Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Update to version 3 #43

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ grumphp.yml
phpspec.yml
/build/
.php_cs.cache
.envrc
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2020-2022, European Union.
Copyright (c) 2019-2022, European Union.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
"sso"
],
"require": {
"php": ">= 7.4",
"php": ">= 8.1",
"ext-json": "*",
"ext-simplexml": "*",
"ecphp/cas-bundle": "dev-master",
"ecphp/ecas": "^2",
"symfony/framework-bundle": "^5.4 || ^6"
"ecphp/cas-bundle": "dev-refactor/cas-lib-v2",
"ecphp/ecas": "^3",
"symfony/framework-bundle": "^6.1"
},
"require-dev": {
"ext-pcov": "*",
"ecphp/php-conventions": "^1",
"friends-of-phpspec/phpspec-code-coverage": "^6",
"infection/infection": "^0.24.0",
"infection/phpspec-adapter": "^0.1.2",
"infection/infection": "^0.26.0",
"infection/phpspec-adapter": "^0.2",
"nyholm/psr7": "^1.5",
"phpspec/phpspec": "^7",
"symfony/http-client": "^5.4 || ^6",
"symfony/security-core": "^5.4 || ^6"
"symfony/http-client": "^6.1",
"symfony/security-core": "^6.1"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
8 changes: 5 additions & 3 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ imports:
- { resource: vendor/ecphp/php-conventions/config/php73/grumphp.yml }

parameters:
tasks.license.date_from: 2020
extra_tasks:
phpspec:
verbose: true
clover_coverage:
clover_file: build/logs/clover.xml
level: 50
infection:
threads: 10
test_framework: phpspec
configuration: infection.json.dist
min_msi: 10
min_covered_msi: 10
min_msi: 50
min_covered_msi: 90
8 changes: 5 additions & 3 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"timeout": 10,
"timeout": 30,
"source": {
"directories": [
"src"
]
},
"logs": {
"github": true,
"text": "build/infection.log",
"summary": "build/summary.log",
"debug": "build/debug.log",
"perMutator": "build/per-mutator.md",
"badge": {
"branch": "master"
"html": "build/report.html",
"stryker": {
"report": "master"
}
},
"testFramework":"phpspec"
Expand Down
5 changes: 5 additions & 0 deletions phpspec.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ extensions:
- clover
- php
- text
- html
output:
html: build/coverage
clover: build/logs/clover.xml
php: build/coverage.php
whitelist:
- src
blacklist:
- src/Resources
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@

namespace spec\EcPhp\EuLoginBundle\Security\Core\User;

use EcPhp\CasBundle\Cas\SymfonyCasResponseBuilder;
use EcPhp\CasBundle\Security\Core\User\CasUserProvider;
use EcPhp\CasLib\Introspection\Introspector;
use EcPhp\Ecas\Introspection\EcasIntrospector;
use EcPhp\CasLib\Response\CasResponseBuilder;
use EcPhp\CasLib\Response\Factory\AuthenticationFailureFactory;
use EcPhp\CasLib\Response\Factory\ProxyFactory;
use EcPhp\CasLib\Response\Factory\ProxyFailureFactory;
use EcPhp\CasLib\Response\Factory\ServiceValidateFactory as FactoryServiceValidateFactory;
use EcPhp\Ecas\Response\Factory\ServiceValidateFactory;
use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUser;
use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserInterface;
use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserProvider;
use Nyholm\Psr7\Response;
use loophp\psr17\Psr17;
use Nyholm\Psr7\Factory\Psr17Factory;
use PhpSpec\ObjectBehavior;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\User\InMemoryUser;

Expand All @@ -38,7 +46,7 @@ public function it_can_check_if_the_user_class_is_supported()
public function it_can_load_a_user_from_a_response(): void
{
// TestBody1
$response = new Response(200, ['content-type' => 'application/xml'], $this->getTestBody1());
$response = new Response($this->getTestBody1(), 200, ['content-type' => 'application/xml']);

$user = $this->loadUserByResponse($response);

Expand Down Expand Up @@ -143,7 +151,7 @@ public function it_can_load_a_user_from_a_response(): void
]);

// TestBody2
$response = new Response(200, ['content-type' => 'application/xml'], $this->getTestBody2());
$response = new Response($this->getTestBody2(), 200, ['content-type' => 'application/xml']);

$user = $this->loadUserByResponse($response);

Expand Down Expand Up @@ -242,11 +250,11 @@ public function it_can_refresh_a_user(EuLoginUserInterface $user)
->shouldReturn($user);
}

public function it_cannot_load_a_user_by_username()
public function it_cannot_load_a_user_by_identifier()
{
$this
->shouldThrow(UnsupportedUserException::class)
->during('loadUserByUsername', ['foo']);
->during('loadUserByIdentifier', ['foo']);
}

public function it_is_initializable()
Expand All @@ -256,8 +264,29 @@ public function it_is_initializable()

public function let()
{
$psr17Factory = new Psr17Factory();

$psr17 = new Psr17($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);

$casResponseBuilder = new CasResponseBuilder(
new AuthenticationFailureFactory(),
new ProxyFactory(),
new ProxyFailureFactory(),
new ServiceValidateFactory(new FactoryServiceValidateFactory(), $psr17)
);

$psrHttpFactory = new PsrHttpFactory(
$psr17Factory,
$psr17Factory,
$psr17Factory,
$psr17Factory
);

$this
->beConstructedWith(new CasUserProvider(new EcasIntrospector(new Introspector())));
->beConstructedWith(
new CasUserProvider($casResponseBuilder, $psrHttpFactory),
new SymfonyCasResponseBuilder($casResponseBuilder, $psrHttpFactory)
);
}

private function getTestBody1()
Expand Down
104 changes: 66 additions & 38 deletions spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,50 @@

namespace spec\EcPhp\EuLoginBundle\Security\Core\User;

use EcPhp\CasBundle\Cas\SymfonyCasResponseBuilder;
use EcPhp\CasBundle\Security\Core\User\CasUser;
use EcPhp\CasLib\Introspection\Introspector;
use EcPhp\CasLib\Response\CasResponseBuilder;
use EcPhp\CasLib\Response\Factory\AuthenticationFailureFactory;
use EcPhp\CasLib\Response\Factory\ProxyFactory;
use EcPhp\CasLib\Response\Factory\ProxyFailureFactory;
use EcPhp\CasLib\Response\Factory\ServiceValidateFactory;
use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUser;
use Nyholm\Psr7\Response;
use Nyholm\Psr7\Factory\Psr17Factory;
use PhpSpec\ObjectBehavior;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;

class EuLoginUserSpec extends ObjectBehavior
{
public function it_can_get_groups_when_no_groups_are_available()
{
$body = <<<'EOF'
<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas">
<cas:authenticationSuccess>
<cas:user>username</cas:user>
<cas:foo>bar</cas:foo>
<cas:proxies>
<cas:proxy>foo</cas:proxy>
</cas:proxies>
<cas:attributes>
<cas:groups number="0"/>
<cas:extendedAttributes>
<cas:extendedAttribute name="http://stork.eu/motherInLawDogName">
<cas:attributeValue>rex</cas:attributeValue>
<cas:attributeValue>snoopy</cas:attributeValue>
</cas:extendedAttribute>
</cas:extendedAttributes>
</cas:attributes>
</cas:authenticationSuccess>
</cas:serviceResponse>
EOF;

$response = new Response(200, ['Content-Type' => 'application/xml'], $body);
$data = (new Introspector())->parse($response)['serviceResponse']['authenticationSuccess'];
$data = [
'user' => 'username',
'foo' => 'bar',
'proxies' => [
'proxy' => 'foo',
],
'attributes' => [
'groups' => [
'@value' => '',
'@attributes' => [
'number' => '0',
],
],
'extendedAttributes' => [
'extendedAttribute' => [
'attributeValue' => [
0 => 'rex',
1 => 'snoopy',
],
'@attributes' => [
'name' => 'http://stork.eu/motherInLawDogName',
],
],
],
],
];

$casUser = new CasUser($data);

Expand All @@ -53,6 +64,9 @@ public function it_can_get_groups_when_no_groups_are_available()
$this
->getGroups()
->shouldReturn([]);
$this
->getUserIdentifier()
->shouldReturn('username');
}

public function it_can_get_specific_attribute()
Expand Down Expand Up @@ -175,18 +189,10 @@ public function it_is_initializable()
{
$this->shouldHaveType(EuLoginUser::class);

$this
->getPassword()
->shouldBeNull();

$this
->getPgt()
->shouldReturn('proxyGrantingTicket');

$this
->getSalt()
->shouldBeNull();

$this
->getUserIdentifier()
->shouldReturn('username');
Expand All @@ -196,8 +202,8 @@ public function it_is_initializable()
->shouldReturn('bar');

$this
->eraseCredentials()
->shouldBeNull();
->shouldThrow(UnsupportedUserException::class)
->during('eraseCredentials');
}

public function let()
Expand Down Expand Up @@ -295,10 +301,32 @@ public function let()
</cas:serviceResponse>
EOF;

$response = new Response(200, ['Content-Type' => 'application/xml'], $body);
$data = (new Introspector())->parse($response)['serviceResponse']['authenticationSuccess'];
$response = new Response($body, 200, ['Content-Type' => 'application/xml']);

$psr17Factory = new Psr17Factory();

$casResponseBuilder = new CasResponseBuilder(
new AuthenticationFailureFactory(),
new ProxyFactory(),
new ProxyFailureFactory(),
new ServiceValidateFactory()
);

$psrHttpFactory = new PsrHttpFactory(
$psr17Factory,
$psr17Factory,
$psr17Factory,
$psr17Factory
);

$symfonyCasResponseBuilder = new SymfonyCasResponseBuilder(
$casResponseBuilder,
$psrHttpFactory
);

$responseArray = $symfonyCasResponseBuilder->fromResponse($response)->toArray();

$this->beConstructedWith(new CasUser($data));
$this->beConstructedWith(new CasUser($responseArray['serviceResponse']['authenticationSuccess']));
}

private function getAttributesData(): array
Expand Down
Loading