From 59057887641daadee2a7ec714d7252d4ab01ad59 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 1 Aug 2022 12:20:55 +0200 Subject: [PATCH] Do not update the tests right now. --- .../Core/User/EuLoginUserProviderSpec.php | 37 +++-------------- .../Security/Core/User/EuLoginUserSpec.php | 41 +++---------------- src/DependencyInjection/EuLoginExtension.php | 3 -- src/Resources/config/services.php | 28 ++++++------- 4 files changed, 23 insertions(+), 86 deletions(-) diff --git a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php index 8e38427..8ac2071 100644 --- a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php +++ b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserProviderSpec.php @@ -12,17 +12,11 @@ namespace spec\EcPhp\EuLoginBundle\Security\Core\User; use EcPhp\CasBundle\Security\Core\User\CasUserProvider; -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\CasLib\Introspection\Introspector; +use EcPhp\Ecas\Introspection\EcasIntrospector; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUser; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserInterface; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserProvider; -use loophp\psr17\Psr17; -use Nyholm\Psr7\Factory\Psr17Factory; use Nyholm\Psr7\Response; use PhpSpec\ObjectBehavior; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; @@ -46,19 +40,7 @@ public function it_can_load_a_user_from_a_response(): void // TestBody1 $response = new Response(200, ['content-type' => 'application/xml'], $this->getTestBody1()); - $psr17f = new Psr17Factory(); - $psr17 = new Psr17($psr17f, $psr17f, $psr17f, $psr17f, $psr17f, $psr17f); - $responseBuilder = new CasResponseBuilder( - new AuthenticationFailureFactory(), - new ProxyFactory(), - new ProxyFailureFactory(), - new ServiceValidateFactory(new FactoryServiceValidateFactory(), $psr17) - ); - - $user = $this - ->loadUserByResponse( - $responseBuilder->fromResponse($response) - ); + $user = $this->loadUserByResponse($response); $user ->getAttributes() @@ -161,16 +143,9 @@ 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(200, ['content-type' => 'application/xml'], $this->getTestBody2()); - $user = $this - ->loadUserByResponse( - $responseBuilder->fromResponse($response) - ); + $user = $this->loadUserByResponse($response); $user ->getAttributes() @@ -282,7 +257,7 @@ public function it_is_initializable() public function let() { $this - ->beConstructedWith(new CasUserProvider()); + ->beConstructedWith(new CasUserProvider(new EcasIntrospector(new Introspector()))); } private function getTestBody1() diff --git a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php index e0716bf..78810dc 100644 --- a/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php +++ b/spec/EcPhp/EuLoginBundle/Security/Core/User/EuLoginUserSpec.php @@ -12,16 +12,8 @@ namespace spec\EcPhp\EuLoginBundle\Security\Core\User; use EcPhp\CasBundle\Security\Core\User\CasUser; -use EcPhp\CasBundle\Security\Core\User\CasUserInterface; -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\CasLib\Introspection\Introspector; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUser; -use loophp\psr17\Psr17; -use Nyholm\Psr7\Factory\Psr17Factory; use Nyholm\Psr7\Response; use PhpSpec\ObjectBehavior; @@ -50,18 +42,8 @@ public function it_can_get_groups_when_no_groups_are_available() EOF; - $psr17f = new Psr17Factory(); - $psr17 = new Psr17($psr17f, $psr17f, $psr17f, $psr17f, $psr17f, $psr17f); $response = new Response(200, ['Content-Type' => 'application/xml'], $body); - $responseBuilder = new CasResponseBuilder( - new AuthenticationFailureFactory(), - new ProxyFactory(), - new ProxyFailureFactory(), - new ServiceValidateFactory(new FactoryServiceValidateFactory(), $psr17) - ); - $data = $responseBuilder - ->fromResponse($response) - ->toArray()['serviceResponse']['authenticationSuccess']; + $data = (new Introspector())->parse($response)['serviceResponse']['authenticationSuccess']; $casUser = new CasUser($data); @@ -182,7 +164,7 @@ public function it_can_get_specific_attribute() ->shouldReturn('proxyGrantingProtocol'); } - public function it_can_get_the_attributes_only(CasUserInterface $user) + public function it_can_get_the_attributes_only() { $this ->getAttributes() @@ -313,22 +295,10 @@ public function let() EOF; - $psr17f = new Psr17Factory(); - $psr17 = new Psr17($psr17f, $psr17f, $psr17f, $psr17f, $psr17f, $psr17f); $response = new Response(200, ['Content-Type' => 'application/xml'], $body); - $responseBuilder = new CasResponseBuilder( - new AuthenticationFailureFactory(), - new ProxyFactory(), - new ProxyFailureFactory(), - new ServiceValidateFactory(new FactoryServiceValidateFactory(), $psr17) - ); + $data = (new Introspector())->parse($response)['serviceResponse']['authenticationSuccess']; - $data = $responseBuilder - ->fromResponse($response) - ->getCredentials(); - - $this - ->beConstructedWith(new CasUser($data)); + $this->beConstructedWith(new CasUser($data)); } private function getAttributesData(): array @@ -407,7 +377,6 @@ private function getAttributesData(): array 'proxyGrantingProtocol' => 'proxyGrantingProtocol', 'timeZone' => 'timeZone', 'userManager' => 'userManager', - 'foo' => 'bar', ]; } } diff --git a/src/DependencyInjection/EuLoginExtension.php b/src/DependencyInjection/EuLoginExtension.php index 4766cc6..11aa6e6 100644 --- a/src/DependencyInjection/EuLoginExtension.php +++ b/src/DependencyInjection/EuLoginExtension.php @@ -18,9 +18,6 @@ final class EuLoginExtension extends Extension { - /** - * @param array $configs - */ public function load(array $configs, ContainerBuilder $container): void { // Load EU Login services. diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index b8235c6..d78d3fb 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -11,13 +11,9 @@ namespace Symfony\Component\DependencyInjection\Loader\Configurator; -use EcPhp\CasBundle\Security\Core\User\CasUserProvider; -use EcPhp\CasLib\Contract\CasInterface; -use EcPhp\CasLib\Contract\Configuration\PropertiesInterface; -use EcPhp\CasLib\Contract\Response\Factory\ServiceValidateFactory as FactoryServiceValidateFactory; use EcPhp\Ecas\Ecas; use EcPhp\Ecas\EcasProperties; -use EcPhp\Ecas\Response\Factory\ServiceValidateFactory; +use EcPhp\Ecas\Introspection\EcasIntrospector; use EcPhp\EuLoginBundle\Security\Core\User\EuLoginUserProvider; return static function (ContainerConfigurator $container) { @@ -29,21 +25,21 @@ ->autowire(true); $services - ->set(EuLoginUserProvider::class) - ->arg('$casUserProvider', service(CasUserProvider::class)); + ->set('ecas.introspector', EcasIntrospector::class) + ->decorate('cas.introspector') + ->arg('$introspector', service('ecas.introspector.inner')); $services - ->set(EcasProperties::class) - ->decorate(PropertiesInterface::class) - ->arg('$casProperties', service('.inner')); + ->set('eulogin.userprovider', EuLoginUserProvider::class) + ->arg('$casUserProvider', service('cas.userprovider')); $services - ->set(ServiceValidateFactory::class) - ->decorate(FactoryServiceValidateFactory::class) - ->arg('$serviceValidateFactory', service('.inner')); + ->set('ecas.configuration', EcasProperties::class) + ->decorate('cas.configuration') + ->arg('$casProperties', service('ecas.configuration.inner')); $services - ->set(Ecas::class) - ->decorate(CasInterface::class) - ->arg('$cas', service('.inner')); + ->set('ecas', Ecas::class) + ->decorate('cas') + ->arg('$cas', service('ecas.inner')); };