diff --git a/.gitignore b/.gitignore index 5c49ac3..b62210a 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ /composer.lock /*.phar /*.cache + +tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/cache/* \ No newline at end of file diff --git a/composer.json b/composer.json index d81bdbd..e49e8e4 100644 --- a/composer.json +++ b/composer.json @@ -20,14 +20,18 @@ }, "require": { "php": ">=5.5.1", - "symfony/framework-bundle": "~2.3|~3.0|~4.0", - "symfony/dependency-injection": "~2.3|~3.0|~4.0", - "symfony/yaml": "~2.3|~3.0|~4.0", + "symfony/framework-bundle": "~2.7|~3.0|~4.0", + "symfony/dependency-injection": "~2.7|~3.0|~4.0", + "symfony/yaml": "~2.7|~3.0|~4.0", "lightsaml/lightsaml": "~1.1" }, "require-dev": { - "phpunit/phpunit": "~4.5", - "satooshi/php-coveralls": "~0.6" + "symfony/browser-kit": "~2.7|~3.0|~4.0", + "symfony/finder": "~2.7|~3.0|~4.0", + "symfony/filesystem": "~2.7|~3.0|~4.0", + "symfony/routing": "~2.7|~3.0|~4.0", + "phpunit/phpunit": "^5.7", + "php-coveralls/php-coveralls": "~2.0" }, "suggest": { "lightsaml/lightsamp-idp": "If you will be using IDP LightSAML services" diff --git a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/AbstractContainer.php b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/AbstractContainer.php deleted file mode 100644 index f7b113c..0000000 --- a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/AbstractContainer.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace LightSaml\SymfonyBridgeBundle\Bridge\Container; - -use Symfony\Component\DependencyInjection\ContainerInterface; - -abstract class AbstractContainer -{ - /** @var ContainerInterface */ - protected $container; - - /** - * @param ContainerInterface $container - */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - } -} diff --git a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/BuildContainer.php b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/BuildContainer.php index 074210e..fca6e69 100644 --- a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/BuildContainer.php +++ b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/BuildContainer.php @@ -20,17 +20,62 @@ use LightSaml\Build\Container\StoreContainerInterface; use LightSaml\Build\Container\SystemContainerInterface; -class BuildContainer extends AbstractContainer implements BuildContainerInterface +class BuildContainer implements BuildContainerInterface { - /** @var AbstractContainer[] */ - private $containers = []; + /** @var SystemContainerInterface */ + private $systemsystemContainer; + + /** @var PartyContainerInterface */ + private $partypartyContainer; + + /** @var StoreContainerInterface */ + private $storeContainer; + + /** @var OwnContainerInterface */ + private $ownContainer; + + /** @var ProviderContainerInterface */ + private $providerContainer; + + /** @var ServiceContainerInterface */ + private $serviceContainer; + + /** @var CredentialContainerInterface */ + private $credentialContainer; + + /** + * @param SystemContainerInterface $systemContainer + * @param PartyContainerInterface $partyContainer + * @param StoreContainerInterface $storeContainer + * @param ProviderContainerInterface $providerContainer + * @param CredentialContainerInterface $credentialContainer + * @param ServiceContainerInterface $serviceContainer + * @param OwnContainerInterface $ownContainer + */ + public function __construct( + SystemContainerInterface $systemContainer, + PartyContainerInterface $partyContainer, + StoreContainerInterface $storeContainer, + ProviderContainerInterface $providerContainer, + CredentialContainerInterface $credentialContainer, + ServiceContainerInterface $serviceContainer, + OwnContainerInterface $ownContainer + ) { + $this->systemsystemContainer = $systemContainer; + $this->partypartyContainer = $partyContainer; + $this->storeContainer = $storeContainer; + $this->providerContainer = $providerContainer; + $this->credentialContainer = $credentialContainer; + $this->serviceContainer = $serviceContainer; + $this->ownContainer = $ownContainer; + } /** * @return SystemContainerInterface */ public function getSystemContainer() { - return $this->getContainer(SystemContainer::class); + return $this->systemsystemContainer; } /** @@ -38,7 +83,7 @@ public function getSystemContainer() */ public function getPartyContainer() { - return $this->getContainer(PartyContainer::class); + return $this->partypartyContainer; } /** @@ -46,7 +91,7 @@ public function getPartyContainer() */ public function getStoreContainer() { - return $this->getContainer(StoreContainer::class); + return $this->storeContainer; } /** @@ -54,7 +99,7 @@ public function getStoreContainer() */ public function getProviderContainer() { - return $this->getContainer(ProviderContainer::class); + return $this->providerContainer; } /** @@ -62,7 +107,7 @@ public function getProviderContainer() */ public function getCredentialContainer() { - return $this->getContainer(CredentialContainer::class); + return $this->credentialContainer; } /** @@ -70,7 +115,7 @@ public function getCredentialContainer() */ public function getServiceContainer() { - return $this->getContainer(ServiceContainer::class); + return $this->serviceContainer; } /** @@ -78,20 +123,6 @@ public function getServiceContainer() */ public function getOwnContainer() { - return $this->getContainer(OwnContainer::class); - } - - /** - * @param string $class - * - * @return AbstractContainer - */ - private function getContainer($class) - { - if (false === isset($this->containers[$class])) { - $this->containers[$class] = new $class($this->container); - } - - return $this->containers[$class]; + return $this->ownContainer; } } diff --git a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/CredentialContainer.php b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/CredentialContainer.php index 189697f..93a7cbd 100644 --- a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/CredentialContainer.php +++ b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/CredentialContainer.php @@ -14,13 +14,24 @@ use LightSaml\Build\Container\CredentialContainerInterface; use LightSaml\Store\Credential\CredentialStoreInterface; -class CredentialContainer extends AbstractContainer implements CredentialContainerInterface +class CredentialContainer implements CredentialContainerInterface { + /** @var CredentialStoreInterface */ + private $credentialStore; + + /** + * @param CredentialStoreInterface $credentialStore + */ + public function __construct(CredentialStoreInterface $credentialStore) + { + $this->credentialStore = $credentialStore; + } + /** * @return CredentialStoreInterface */ public function getCredentialStore() { - return $this->container->get('lightsaml.credential.credential_store'); + return $this->credentialStore; } } diff --git a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/OwnContainer.php b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/OwnContainer.php index 1285e9c..c77fe6d 100644 --- a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/OwnContainer.php +++ b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/OwnContainer.php @@ -14,15 +14,40 @@ use LightSaml\Build\Container\OwnContainerInterface; use LightSaml\Credential\CredentialInterface; use LightSaml\Provider\EntityDescriptor\EntityDescriptorProviderInterface; +use LightSaml\Store\Credential\CredentialStoreInterface; -class OwnContainer extends AbstractContainer implements OwnContainerInterface +class OwnContainer implements OwnContainerInterface { + /** @var EntityDescriptorProviderInterface */ + private $entityDescriptorProvider; + + /** @var CredentialStoreInterface */ + private $credentialStore; + + /** @var string */ + private $entityId; + + /** + * @param EntityDescriptorProviderInterface $entityDescriptorProvider + * @param CredentialStoreInterface $credentialStore + * @param string $entityId + */ + public function __construct( + EntityDescriptorProviderInterface $entityDescriptorProvider, + CredentialStoreInterface $credentialStore, + $entityId + ) { + $this->entityDescriptorProvider = $entityDescriptorProvider; + $this->credentialStore = $credentialStore; + $this->entityId = $entityId; + } + /** * @return EntityDescriptorProviderInterface */ public function getOwnEntityDescriptorProvider() { - return $this->container->get('lightsaml.own.entity_descriptor_provider'); + return $this->entityDescriptorProvider; } /** @@ -30,8 +55,8 @@ public function getOwnEntityDescriptorProvider() */ public function getOwnCredentials() { - return $this->container->get('lightsaml.own.credential_store')->getByEntityId( - $this->container->getParameter('lightsaml.own.entity_id') + return $this->credentialStore->getByEntityId( + $this->entityId ); } } diff --git a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/PartyContainer.php b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/PartyContainer.php index 1c52de1..e8cd633 100644 --- a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/PartyContainer.php +++ b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/PartyContainer.php @@ -15,14 +15,38 @@ use LightSaml\Store\EntityDescriptor\EntityDescriptorStoreInterface; use LightSaml\Store\TrustOptions\TrustOptionsStoreInterface; -class PartyContainer extends AbstractContainer implements PartyContainerInterface +class PartyContainer implements PartyContainerInterface { + /** @var EntityDescriptorStoreInterface */ + private $idpEntityDescriptorStore; + + /** @var EntityDescriptorStoreInterface */ + private $spEntityDescriptorStore; + + /** @var TrustOptionsStoreInterface */ + private $trustOptionsStore; + + /** + * @param EntityDescriptorStoreInterface $idpEntityDescriptorStore + * @param EntityDescriptorStoreInterface $spEntityDescriptorStore + * @param TrustOptionsStoreInterface $trustOptionsStore + */ + public function __construct( + EntityDescriptorStoreInterface $idpEntityDescriptorStore, + EntityDescriptorStoreInterface $spEntityDescriptorStore, + TrustOptionsStoreInterface $trustOptionsStore + ) { + $this->idpEntityDescriptorStore = $idpEntityDescriptorStore; + $this->spEntityDescriptorStore = $spEntityDescriptorStore; + $this->trustOptionsStore = $trustOptionsStore; + } + /** * @return EntityDescriptorStoreInterface */ public function getIdpEntityDescriptorStore() { - return $this->container->get('lightsaml.party.idp_entity_descriptor_store'); + return $this->idpEntityDescriptorStore; } /** @@ -30,7 +54,7 @@ public function getIdpEntityDescriptorStore() */ public function getSpEntityDescriptorStore() { - return $this->container->get('lightsaml.party.sp_entity_descriptor_store'); + return $this->spEntityDescriptorStore; } /** @@ -38,6 +62,6 @@ public function getSpEntityDescriptorStore() */ public function getTrustOptionsStore() { - return $this->container->get('lightsaml.party.trust_options_store'); + return $this->trustOptionsStore; } } diff --git a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/ProviderContainer.php b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/ProviderContainer.php index f95c7cc..68aead3 100644 --- a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/ProviderContainer.php +++ b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/ProviderContainer.php @@ -16,14 +16,38 @@ use LightSaml\Provider\NameID\NameIdProviderInterface; use LightSaml\Provider\Session\SessionInfoProviderInterface; -class ProviderContainer extends AbstractContainer implements ProviderContainerInterface +class ProviderContainer implements ProviderContainerInterface { + /** @var AttributeValueProviderInterface */ + private $attributeValueProvider; + + /** @var SessionInfoProviderInterface */ + private $sessionInfoProvider; + + /** @var NameIdProviderInterface */ + private $nameIdProvider; + + /** + * @param AttributeValueProviderInterface $attributeValueProvider + * @param SessionInfoProviderInterface $sessionInfoProvider + * @param NameIdProviderInterface $nameIdProvider + */ + public function __construct( + AttributeValueProviderInterface $attributeValueProvider, + SessionInfoProviderInterface $sessionInfoProvider, + NameIdProviderInterface $nameIdProvider + ) { + $this->attributeValueProvider = $attributeValueProvider; + $this->sessionInfoProvider = $sessionInfoProvider; + $this->nameIdProvider = $nameIdProvider; + } + /** * @return AttributeValueProviderInterface */ public function getAttributeValueProvider() { - return $this->container->get('lightsaml.provider.attribute_value'); + return $this->attributeValueProvider; } /** @@ -31,7 +55,7 @@ public function getAttributeValueProvider() */ public function getSessionInfoProvider() { - return $this->container->get('lightsaml.provider.session_info'); + return $this->sessionInfoProvider; } /** @@ -39,11 +63,6 @@ public function getSessionInfoProvider() */ public function getNameIdProvider() { - return $this->container->get('lightsaml.provider.name_id'); - } - - public function getAttributeNameProvider() - { - return $this->container->get('lightsaml.provider.attribute_name'); + return $this->nameIdProvider; } } diff --git a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/ServiceContainer.php b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/ServiceContainer.php index 69ff1e8..5c7fb29 100644 --- a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/ServiceContainer.php +++ b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/ServiceContainer.php @@ -17,27 +17,87 @@ use LightSaml\Resolver\Endpoint\EndpointResolverInterface; use LightSaml\Resolver\Session\SessionProcessorInterface; use LightSaml\Resolver\Signature\SignatureResolverInterface; -use LightSaml\Validator\Model\Assertion\AssertionTimeValidator; +use LightSaml\Validator\Model\Assertion\AssertionTimeValidatorInterface; use LightSaml\Validator\Model\Assertion\AssertionValidatorInterface; use LightSaml\Validator\Model\NameId\NameIdValidatorInterface; use LightSaml\Validator\Model\Signature\SignatureValidatorInterface; -class ServiceContainer extends AbstractContainer implements ServiceContainerInterface +class ServiceContainer implements ServiceContainerInterface { + /** @var AssertionValidatorInterface */ + private $assertionValidator; + + /** @var AssertionTimeValidatorInterface */ + private $assertionTimeValidator; + + /** @var SignatureResolverInterface */ + private $signatureResolver; + + /** @var EndpointResolverInterface */ + private $endpointResolver; + + /** @var NameIdValidatorInterface */ + private $nameIdValidator; + + /** @var BindingFactoryInterface */ + private $bindingFactory; + + /** @var SignatureValidatorInterface */ + private $signatureValidator; + + /** @var CredentialResolverInterface */ + private $credentialResolver; + + /** @var SessionProcessorInterface */ + private $sessionProcessor; + + /** + * @param AssertionValidatorInterface $assertionValidator + * @param AssertionTimeValidatorInterface $assertionTimeValidator + * @param SignatureResolverInterface $signatureResolver + * @param EndpointResolverInterface $endpointResolver + * @param NameIdValidatorInterface $nameIdValidator + * @param BindingFactoryInterface $bindingFactory + * @param SignatureValidatorInterface $signatureValidator + * @param CredentialResolverInterface $credentialResolver + * @param SessionProcessorInterface $sessionProcessor + */ + public function __construct( + AssertionValidatorInterface $assertionValidator, + AssertionTimeValidatorInterface $assertionTimeValidator, + SignatureResolverInterface $signatureResolver, + EndpointResolverInterface $endpointResolver, + NameIdValidatorInterface $nameIdValidator, + BindingFactoryInterface $bindingFactory, + SignatureValidatorInterface $signatureValidator, + CredentialResolverInterface $credentialResolver, + SessionProcessorInterface $sessionProcessor + ) { + $this->assertionValidator = $assertionValidator; + $this->assertionTimeValidator = $assertionTimeValidator; + $this->signatureResolver = $signatureResolver; + $this->endpointResolver = $endpointResolver; + $this->nameIdValidator = $nameIdValidator; + $this->bindingFactory = $bindingFactory; + $this->signatureValidator = $signatureValidator; + $this->credentialResolver = $credentialResolver; + $this->sessionProcessor = $sessionProcessor; + } + /** * @return AssertionValidatorInterface */ public function getAssertionValidator() { - return $this->container->get('lightsaml.service.assertion_validator'); + return $this->assertionValidator; } /** - * @return AssertionTimeValidator + * @return AssertionTimeValidatorInterface */ public function getAssertionTimeValidator() { - return $this->container->get('lightsaml.service.assertion_time_validator'); + return $this->assertionTimeValidator; } /** @@ -45,7 +105,7 @@ public function getAssertionTimeValidator() */ public function getSignatureResolver() { - return $this->container->get('lightsaml.service.signature_resolver'); + return $this->signatureResolver; } /** @@ -53,7 +113,7 @@ public function getSignatureResolver() */ public function getEndpointResolver() { - return $this->container->get('lightsaml.service.endpoint_resolver'); + return $this->endpointResolver; } /** @@ -61,7 +121,7 @@ public function getEndpointResolver() */ public function getNameIdValidator() { - return $this->container->get('lightsaml.service.name_id_validator'); + return $this->nameIdValidator; } /** @@ -69,7 +129,7 @@ public function getNameIdValidator() */ public function getBindingFactory() { - return $this->container->get('lightsaml.service.binding_factory'); + return $this->bindingFactory; } /** @@ -77,7 +137,7 @@ public function getBindingFactory() */ public function getSignatureValidator() { - return $this->container->get('lightsaml.service.signature_validator'); + return $this->signatureValidator; } /** @@ -85,7 +145,7 @@ public function getSignatureValidator() */ public function getCredentialResolver() { - return $this->container->get('lightsaml.service.credential_resolver'); + return $this->credentialResolver; } /** @@ -93,7 +153,7 @@ public function getCredentialResolver() */ public function getLogoutSessionResolver() { - return $this->container->get('lightsaml.service.logout_resolver'); + throw new \LogicException('Not implemented'); } /** @@ -101,6 +161,6 @@ public function getLogoutSessionResolver() */ public function getSessionProcessor() { - return $this->container->get('lightsaml.service.session_processor'); + return $this->sessionProcessor; } } diff --git a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/StoreContainer.php b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/StoreContainer.php index d10a658..f02061c 100644 --- a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/StoreContainer.php +++ b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/StoreContainer.php @@ -16,14 +16,38 @@ use LightSaml\Store\Request\RequestStateStoreInterface; use LightSaml\Store\Sso\SsoStateStoreInterface; -class StoreContainer extends AbstractContainer implements StoreContainerInterface +class StoreContainer implements StoreContainerInterface { + /** @var RequestStateStoreInterface */ + private $requestStateStore; + + /** @var IdStoreInterface */ + private $idStateStore; + + /** @var SsoStateStoreInterface */ + private $ssoStateStore; + + /** + * @param RequestStateStoreInterface $requestStateStore + * @param IdStoreInterface $idStateStore + * @param SsoStateStoreInterface $ssoStateStore + */ + public function __construct( + RequestStateStoreInterface $requestStateStore, + IdStoreInterface $idStateStore, + SsoStateStoreInterface $ssoStateStore + ) { + $this->requestStateStore = $requestStateStore; + $this->idStateStore = $idStateStore; + $this->ssoStateStore = $ssoStateStore; + } + /** * @return RequestStateStoreInterface */ public function getRequestStateStore() { - return $this->container->get('lightsaml.store.request'); + return $this->requestStateStore; } /** @@ -31,7 +55,7 @@ public function getRequestStateStore() */ public function getIdStateStore() { - return $this->container->get('lightsaml.store.id_state'); + return $this->idStateStore; } /** @@ -39,6 +63,6 @@ public function getIdStateStore() */ public function getSsoStateStore() { - return $this->container->get('lightsaml.store.sso_state'); + return $this->ssoStateStore; } } diff --git a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/SystemContainer.php b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/SystemContainer.php index 71f4091..6d12376 100644 --- a/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/SystemContainer.php +++ b/src/LightSaml/SymfonyBridgeBundle/Bridge/Container/SystemContainer.php @@ -16,20 +16,53 @@ use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\SessionInterface; -class SystemContainer extends AbstractContainer implements SystemContainerInterface +class SystemContainer implements SystemContainerInterface { + /** @var RequestStack */ + private $requestStack; + + /** @var SessionInterface */ + private $session; + + /** @var TimeProviderInterface */ + private $timeProvider; + + /** @var EventDispatcherInterface */ + private $eventDispatcher; + + /** @var LoggerInterface */ + private $logger; + + /** + * @param RequestStack $requestStack + * @param SessionInterface $session + * @param TimeProviderInterface $timeProvider + * @param EventDispatcherInterface $eventDispatcher + * @param LoggerInterface $logger + */ + public function __construct( + RequestStack $requestStack, + SessionInterface $session, + TimeProviderInterface $timeProvider, + EventDispatcherInterface $eventDispatcher, + LoggerInterface $logger + ) { + $this->requestStack = $requestStack; + $this->session = $session; + $this->timeProvider = $timeProvider; + $this->eventDispatcher = $eventDispatcher; + $this->logger = $logger; + } + /** * @return Request */ public function getRequest() { - if ($this->container->has('request_stack')) { - return $this->container->get('request_stack')->getCurrentRequest(); - } - - return $this->container->get('request'); + return $this->requestStack->getCurrentRequest(); } /** @@ -37,7 +70,7 @@ public function getRequest() */ public function getSession() { - return $this->container->get('session'); + return $this->session; } /** @@ -45,7 +78,7 @@ public function getSession() */ public function getTimeProvider() { - return $this->container->get('lightsaml.system.time_provider'); + return $this->timeProvider; } /** @@ -53,7 +86,7 @@ public function getTimeProvider() */ public function getEventDispatcher() { - return $this->container->get('lightsaml.system.event_dispatcher'); + return $this->eventDispatcher; } /** @@ -61,6 +94,6 @@ public function getEventDispatcher() */ public function getLogger() { - return $this->container->get('lightsaml.system.logger'); + return $this->logger; } } diff --git a/src/LightSaml/SymfonyBridgeBundle/Resources/config/container.yml b/src/LightSaml/SymfonyBridgeBundle/Resources/config/container.yml index c2b52ee..5cb23a8 100644 --- a/src/LightSaml/SymfonyBridgeBundle/Resources/config/container.yml +++ b/src/LightSaml/SymfonyBridgeBundle/Resources/config/container.yml @@ -1,5 +1,67 @@ services: lightsaml.container.build: class: LightSaml\SymfonyBridgeBundle\Bridge\Container\BuildContainer + public: true arguments: - - "@service_container" + - "@lightsaml.container.system" + - "@lightsaml.container.party" + - "@lightsaml.container.store" + - "@lightsaml.container.provider" + - "@lightsaml.container.credential" + - "@lightsaml.container.service" + - "@lightsaml.container.own" + + lightsaml.container.system: + class: LightSaml\SymfonyBridgeBundle\Bridge\Container\SystemContainer + arguments: + - "@request_stack" + - "@session" + - "@lightsaml.system.time_provider" + - "@lightsaml.system.event_dispatcher" + - "@lightsaml.system.logger" + + lightsaml.container.party: + class: LightSaml\SymfonyBridgeBundle\Bridge\Container\PartyContainer + arguments: + - "@lightsaml.party.idp_entity_descriptor_store" + - "@lightsaml.party.sp_entity_descriptor_store" + - "@lightsaml.party.trust_options_store" + + lightsaml.container.store: + class: LightSaml\SymfonyBridgeBundle\Bridge\Container\StoreContainer + arguments: + - "@lightsaml.store.request" + - "@lightsaml.store.id_state" + - "@lightsaml.store.sso_state" + + lightsaml.container.provider: + class: LightSaml\SymfonyBridgeBundle\Bridge\Container\ProviderContainer + arguments: + - "@lightsaml.provider.attribute_value" + - "@lightsaml.provider.session_info" + - "@lightsaml.provider.name_id" + + lightsaml.container.credential: + class: LightSaml\SymfonyBridgeBundle\Bridge\Container\CredentialContainer + arguments: + - "@lightsaml.credential.credential_store" + + lightsaml.container.service: + class: LightSaml\SymfonyBridgeBundle\Bridge\Container\ServiceContainer + arguments: + - "@lightsaml.service.assertion_validator" + - "@lightsaml.service.assertion_time_validator" + - "@lightsaml.service.signature_resolver" + - "@lightsaml.service.endpoint_resolver" + - "@lightsaml.service.name_id_validator" + - "@lightsaml.service.binding_factory" + - "@lightsaml.service.signature_validator" + - "@lightsaml.service.credential_resolver" + - "@lightsaml.service.session_processor" + + lightsaml.container.own: + class: LightSaml\SymfonyBridgeBundle\Bridge\Container\OwnContainer + arguments: + - "@lightsaml.own.entity_descriptor_provider" + - "@lightsaml.own.credential_store" + - "%lightsaml.own.entity_id%" diff --git a/src/LightSaml/SymfonyBridgeBundle/Resources/config/system.yml b/src/LightSaml/SymfonyBridgeBundle/Resources/config/system.yml index 4cccd66..9f4f9ff 100644 --- a/src/LightSaml/SymfonyBridgeBundle/Resources/config/system.yml +++ b/src/LightSaml/SymfonyBridgeBundle/Resources/config/system.yml @@ -9,4 +9,4 @@ services: class: Symfony\Component\EventDispatcher\EventDispatcher lightsaml.system.logger: - alias: logger + class: Psr\Log\NullLogger diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/AbstractContainerTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/AbstractContainerTest.php deleted file mode 100644 index 45b2b9c..0000000 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/AbstractContainerTest.php +++ /dev/null @@ -1,14 +0,0 @@ -getMockForAbstractClass(AbstractContainer::class, [TestHelper::getContainerMock($this)]); - } -} diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/BuildContainerTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/BuildContainerTest.php index 2bbded8..e80b2a6 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/BuildContainerTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/BuildContainerTest.php @@ -2,62 +2,28 @@ namespace LightSaml\SymfonyBridgeBundle\Tests\Bridge\Container; +use LightSaml\Build\Container\CredentialContainerInterface; +use LightSaml\Build\Container\OwnContainerInterface; +use LightSaml\Build\Container\PartyContainerInterface; +use LightSaml\Build\Container\ProviderContainerInterface; +use LightSaml\Build\Container\ServiceContainerInterface; +use LightSaml\Build\Container\StoreContainerInterface; +use LightSaml\Build\Container\SystemContainerInterface; use LightSaml\SymfonyBridgeBundle\Bridge\Container\BuildContainer; -use LightSaml\SymfonyBridgeBundle\Bridge\Container\CredentialContainer; -use LightSaml\SymfonyBridgeBundle\Bridge\Container\OwnContainer; -use LightSaml\SymfonyBridgeBundle\Bridge\Container\PartyContainer; -use LightSaml\SymfonyBridgeBundle\Bridge\Container\ProviderContainer; -use LightSaml\SymfonyBridgeBundle\Bridge\Container\ServiceContainer; -use LightSaml\SymfonyBridgeBundle\Bridge\Container\StoreContainer; -use LightSaml\SymfonyBridgeBundle\Bridge\Container\SystemContainer; -use LightSaml\SymfonyBridgeBundle\Tests\TestHelper; +use PHPUnit\Framework\TestCase; -class BuildContainerTest extends \PHPUnit_Framework_TestCase +class BuildContainerTest extends TestCase { - public function test_constructs_with_container() - { - new BuildContainer(TestHelper::getContainerMock($this)); - } - - public function test_returns_system_container() - { - $buildContainer = new BuildContainer(TestHelper::getContainerMock($this)); - $this->assertInstanceOf(SystemContainer::class, $buildContainer->getSystemContainer()); - } - - public function test_returns_party_container() - { - $buildContainer = new BuildContainer(TestHelper::getContainerMock($this)); - $this->assertInstanceOf(PartyContainer::class, $buildContainer->getPartyContainer()); - } - - public function test_returns_store_container() - { - $buildContainer = new BuildContainer(TestHelper::getContainerMock($this)); - $this->assertInstanceOf(StoreContainer::class, $buildContainer->getStoreContainer()); - } - - public function test_returns_provider_container() - { - $buildContainer = new BuildContainer(TestHelper::getContainerMock($this)); - $this->assertInstanceOf(ProviderContainer::class, $buildContainer->getProviderContainer()); - } - - public function test_returns_credential_container() - { - $buildContainer = new BuildContainer(TestHelper::getContainerMock($this)); - $this->assertInstanceOf(CredentialContainer::class, $buildContainer->getCredentialContainer()); - } - - public function test_returns_service_container() - { - $buildContainer = new BuildContainer(TestHelper::getContainerMock($this)); - $this->assertInstanceOf(ServiceContainer::class, $buildContainer->getServiceContainer()); - } - - public function test_returns_own_container() - { - $buildContainer = new BuildContainer(TestHelper::getContainerMock($this)); - $this->assertInstanceOf(OwnContainer::class, $buildContainer->getOwnContainer()); + public function test_constructs_with_all_containers() + { + new BuildContainer( + $this->getMockBuilder(SystemContainerInterface::class)->getMock(), + $this->getMockBuilder(PartyContainerInterface::class)->getMock(), + $this->getMockBuilder(StoreContainerInterface::class)->getMock(), + $this->getMockBuilder(ProviderContainerInterface::class)->getMock(), + $this->getMockBuilder(CredentialContainerInterface::class)->getMock(), + $this->getMockBuilder(ServiceContainerInterface::class)->getMock(), + $this->getMockBuilder(OwnContainerInterface::class)->getMock() + ); } } diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/CredentialContainerTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/CredentialContainerTest.php index 40e3645..2a553b1 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/CredentialContainerTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/CredentialContainerTest.php @@ -4,17 +4,14 @@ use LightSaml\Store\Credential\CredentialStoreInterface; use LightSaml\SymfonyBridgeBundle\Bridge\Container\CredentialContainer; -use LightSaml\SymfonyBridgeBundle\Tests\TestHelper; +use PHPUnit\Framework\TestCase; -class CredentialContainerTest extends \PHPUnit_Framework_TestCase +class CredentialContainerTest extends TestCase { - public function test_returns_credential_store() + public function test_constructs_with_all_arguments() { - $container = new CredentialContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.credential.credential_store') - ->willReturn($expected = $this->getMock(CredentialStoreInterface::class)); - - $this->assertSame($expected, $container->getCredentialStore()); + new CredentialContainer( + $this->getMockBuilder(CredentialStoreInterface::class)->getMock() + ); } } diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/OwnContainerTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/OwnContainerTest.php index b37c2cd..fc80558 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/OwnContainerTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/OwnContainerTest.php @@ -2,40 +2,19 @@ namespace LightSaml\SymfonyBridgeBundle\Tests\Bridge\Container; -use LightSaml\Credential\CredentialInterface; use LightSaml\Provider\EntityDescriptor\EntityDescriptorProviderInterface; use LightSaml\Store\Credential\CredentialStoreInterface; use LightSaml\SymfonyBridgeBundle\Bridge\Container\OwnContainer; -use LightSaml\SymfonyBridgeBundle\Tests\TestHelper; +use PHPUnit\Framework\TestCase; -class OwnContainerTest extends \PHPUnit_Framework_TestCase +class OwnContainerTest extends TestCase { - public function test_returns_own_entity_provider() + public function test_constructs_with_all_arguments() { - $container = new OwnContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.own.entity_descriptor_provider') - ->willReturn($expected = $this->getMock(EntityDescriptorProviderInterface::class)); - - $this->assertSame($expected, $container->getOwnEntityDescriptorProvider()); - } - - public function test_returns_own_credentials() - { - $container = new OwnContainer($containerMock = TestHelper::getContainerMock($this)); - - $containerMock->method('get') - ->with('lightsaml.own.credential_store') - ->willReturn($credentialStoreMock = $this->getMock(CredentialStoreInterface::class)); - $containerMock->method('getParameter') - ->with('lightsaml.own.entity_id') - ->willReturn('foo'); - - $credentialStoreMock->method('getByEntityId') - ->willReturn([$expected = $this->getMock(CredentialInterface::class)]); - - $result = $container->getOwnCredentials(); - $this->assertTrue(is_array($result)); - $this->assertSame($expected, $result[0]); + new OwnContainer( + $this->getMockBuilder(EntityDescriptorProviderInterface::class)->getMock(), + $this->getMockBuilder(CredentialStoreInterface::class)->getMock(), + "string" + ); } } diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/PartyContainerTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/PartyContainerTest.php index ae7ae03..d972ea6 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/PartyContainerTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/PartyContainerTest.php @@ -5,37 +5,16 @@ use LightSaml\Store\EntityDescriptor\EntityDescriptorStoreInterface; use LightSaml\Store\TrustOptions\TrustOptionsStoreInterface; use LightSaml\SymfonyBridgeBundle\Bridge\Container\PartyContainer; -use LightSaml\SymfonyBridgeBundle\Tests\TestHelper; +use PHPUnit\Framework\TestCase; -class PartyContainerTest extends \PHPUnit_Framework_TestCase +class PartyContainerTest extends TestCase { - public function test_returns_idp_entity_descriptor_store() + public function test_constructs_with_all_arguments() { - $container = new PartyContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.party.idp_entity_descriptor_store') - ->willReturn($expected = $this->getMock(EntityDescriptorStoreInterface::class)); - - $this->assertSame($expected, $container->getIdpEntityDescriptorStore()); - } - - public function test_returns_sp_entity_descriptor_store() - { - $container = new PartyContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.party.sp_entity_descriptor_store') - ->willReturn($expected = $this->getMock(EntityDescriptorStoreInterface::class)); - - $this->assertSame($expected, $container->getSpEntityDescriptorStore()); - } - - public function test_returns_trust_options_store() - { - $container = new PartyContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.party.trust_options_store') - ->willReturn($expected = $this->getMock(TrustOptionsStoreInterface::class)); - - $this->assertSame($expected, $container->getTrustOptionsStore()); + new PartyContainer( + $this->getMockBuilder(EntityDescriptorStoreInterface::class)->getMock(), + $this->getMockBuilder(EntityDescriptorStoreInterface::class)->getMock(), + $this->getMockBuilder(TrustOptionsStoreInterface::class)->getMock() + ); } } diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/ProviderContainerTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/ProviderContainerTest.php index 1cd04fe..3bb0217 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/ProviderContainerTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/ProviderContainerTest.php @@ -6,37 +6,16 @@ use LightSaml\Provider\NameID\NameIdProviderInterface; use LightSaml\Provider\Session\SessionInfoProviderInterface; use LightSaml\SymfonyBridgeBundle\Bridge\Container\ProviderContainer; -use LightSaml\SymfonyBridgeBundle\Tests\TestHelper; +use PHPUnit\Framework\TestCase; -class ProviderContainerTest extends \PHPUnit_Framework_TestCase +class ProviderContainerTest extends TestCase { - public function test_returns_attribute_value_provider() + public function test_constructs_with_all_arguments() { - $container = new ProviderContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.provider.attribute_value') - ->willReturn($expected = $this->getMock(AttributeValueProviderInterface::class)); - - $this->assertSame($expected, $container->getAttributeValueProvider()); - } - - public function test_returns_session_info_provider() - { - $container = new ProviderContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.provider.session_info') - ->willReturn($expected = $this->getMock(SessionInfoProviderInterface::class)); - - $this->assertSame($expected, $container->getSessionInfoProvider()); - } - - public function test_returns_name_id_provider() - { - $container = new ProviderContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.provider.name_id') - ->willReturn($expected = $this->getMock(NameIdProviderInterface::class)); - - $this->assertSame($expected, $container->getNameIdProvider()); + new ProviderContainer( + $this->getMockBuilder(AttributeValueProviderInterface::class)->getMock(), + $this->getMockBuilder(SessionInfoProviderInterface::class)->getMock(), + $this->getMockBuilder(NameIdProviderInterface::class)->getMock() + ); } } diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/ServiceContainerTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/ServiceContainerTest.php index 423a9c7..04c4ed5 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/ServiceContainerTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/ServiceContainerTest.php @@ -8,111 +8,26 @@ use LightSaml\Resolver\Session\SessionProcessorInterface; use LightSaml\Resolver\Signature\SignatureResolverInterface; use LightSaml\SymfonyBridgeBundle\Bridge\Container\ServiceContainer; -use LightSaml\SymfonyBridgeBundle\Tests\TestHelper; use LightSaml\Validator\Model\Assertion\AssertionTimeValidatorInterface; use LightSaml\Validator\Model\Assertion\AssertionValidatorInterface; use LightSaml\Validator\Model\NameId\NameIdValidatorInterface; use LightSaml\Validator\Model\Signature\SignatureValidatorInterface; +use PHPUnit\Framework\TestCase; -class ServiceContainerTest extends \PHPUnit_Framework_TestCase +class ServiceContainerTest extends TestCase { - public function test_returns_assertion_validator() - { - $container = new ServiceContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.service.assertion_validator') - ->willReturn($expected = $this->getMock(AssertionValidatorInterface::class)); - - $this->assertSame($expected, $container->getAssertionValidator()); - } - - public function test_returns_assertion_time_validator() - { - $container = new ServiceContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.service.assertion_time_validator') - ->willReturn($expected = $this->getMock(AssertionTimeValidatorInterface::class)); - - $this->assertSame($expected, $container->getAssertionTimeValidator()); - } - - public function test_returns_signature_resolver() - { - $container = new ServiceContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.service.signature_resolver') - ->willReturn($expected = $this->getMock(SignatureResolverInterface::class)); - - $this->assertSame($expected, $container->getSignatureResolver()); - } - - public function test_returns_endpoint_resolver() - { - $container = new ServiceContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.service.endpoint_resolver') - ->willReturn($expected = $this->getMock(EndpointResolverInterface::class)); - - $this->assertSame($expected, $container->getEndpointResolver()); - } - - public function test_returns_name_id_validator() - { - $container = new ServiceContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.service.name_id_validator') - ->willReturn($expected = $this->getMock(NameIdValidatorInterface::class)); - - $this->assertSame($expected, $container->getNameIdValidator()); - } - - public function test_returns_binding_factory() - { - $container = new ServiceContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.service.binding_factory') - ->willReturn($expected = $this->getMock(BindingFactoryInterface::class)); - - $this->assertSame($expected, $container->getBindingFactory()); - } - - public function test_returns_signature_validator() - { - $container = new ServiceContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.service.signature_validator') - ->willReturn($expected = $this->getMock(SignatureValidatorInterface::class)); - - $this->assertSame($expected, $container->getSignatureValidator()); - } - - public function test_returns_credential_resolver() - { - $container = new ServiceContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.service.credential_resolver') - ->willReturn($expected = $this->getMock(CredentialResolverInterface::class)); - - $this->assertSame($expected, $container->getCredentialResolver()); - } - - public function test_returns_logout_session_resolver() - { - $container = new ServiceContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.service.logout_resolver') - ->willReturn($expected = new \stdClass()); - - $this->assertSame($expected, $container->getLogoutSessionResolver()); - } - - public function test_returns_session_processor() - { - $container = new ServiceContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.service.session_processor') - ->willReturn($expected = $this->getMock(SessionProcessorInterface::class)); - - $this->assertSame($expected, $container->getSessionProcessor()); + public function test_constructs_with_all_arguments() + { + new ServiceContainer( + $this->getMockBuilder(AssertionValidatorInterface::class)->getMock(), + $this->getMockBuilder(AssertionTimeValidatorInterface::class)->getMock(), + $this->getMockBuilder(SignatureResolverInterface::class)->getMock(), + $this->getMockBuilder(EndpointResolverInterface::class)->getMock(), + $this->getMockBuilder(NameIdValidatorInterface::class)->getMock(), + $this->getMockBuilder(BindingFactoryInterface::class)->getMock(), + $this->getMockBuilder(SignatureValidatorInterface::class)->getMock(), + $this->getMockBuilder(CredentialResolverInterface::class)->getMock(), + $this->getMockBuilder(SessionProcessorInterface::class)->getMock() + ); } } diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/StoreContainerTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/StoreContainerTest.php index 4271e6e..d0f0c31 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/StoreContainerTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/StoreContainerTest.php @@ -6,37 +6,16 @@ use LightSaml\Store\Request\RequestStateStoreInterface; use LightSaml\Store\Sso\SsoStateStoreInterface; use LightSaml\SymfonyBridgeBundle\Bridge\Container\StoreContainer; -use LightSaml\SymfonyBridgeBundle\Tests\TestHelper; +use PHPUnit\Framework\TestCase; -class StoreContainerTest extends \PHPUnit_Framework_TestCase +class StoreContainerTest extends TestCase { - public function test_returns_request_state_store() + public function test_constructs_with_all_arguments() { - $container = new StoreContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.store.request') - ->willReturn($expected = $this->getMock(RequestStateStoreInterface::class)); - - $this->assertSame($expected, $container->getRequestStateStore()); - } - - public function test_returns_id_state_store() - { - $container = new StoreContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.store.id_state') - ->willReturn($expected = $this->getMock(IdStoreInterface::class)); - - $this->assertSame($expected, $container->getIdStateStore()); - } - - public function test_returns_sso_state_store() - { - $container = new StoreContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.store.sso_state') - ->willReturn($expected = $this->getMock(SsoStateStoreInterface::class)); - - $this->assertSame($expected, $container->getSsoStateStore()); + new StoreContainer( + $this->getMockBuilder(RequestStateStoreInterface::class)->getMock(), + $this->getMockBuilder(IdStoreInterface::class)->getMock(), + $this->getMockBuilder(SsoStateStoreInterface::class)->getMock() + ); } } diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/SystemContainerTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/SystemContainerTest.php index cc30bfc..be80870 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/SystemContainerTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Bridge/Container/SystemContainerTest.php @@ -4,89 +4,22 @@ use LightSaml\Provider\TimeProvider\TimeProviderInterface; use LightSaml\SymfonyBridgeBundle\Bridge\Container\SystemContainer; -use LightSaml\SymfonyBridgeBundle\Tests\TestHelper; +use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\SessionInterface; -class SystemContainerTest extends \PHPUnit_Framework_TestCase +class SystemContainerTest extends TestCase { - public function test_returns_request_from_stack() + public function test_constructs_with_all_arguments() { - if (false == class_exists('Symfony\Component\HttpFoundation\RequestStack')) { - return; - } - - $container = new SystemContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('has') - ->with('request_stack') - ->willReturn(true); - $containerMock->method('get') - ->with('request_stack') - ->willReturn($requestStackMock = $this->getMock(RequestStack::class)); - - $requestStackMock->method('getCurrentRequest') - ->willReturn($expected = new Request()); - - $this->assertSame($expected, $container->getRequest()); - } - - public function test_returns_request_from_scope() - { - if (class_exists('Symfony\Component\HttpFoundation\RequestStack')) { - return; - } - - $container = new SystemContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('has') - ->with('request_stack') - ->willReturn(false); - $containerMock->method('get') - ->with('request') - ->willReturn($expected = new Request()); - - $this->assertSame($expected, $container->getRequest()); - } - - public function test_returns_session() - { - $container = new SystemContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('session') - ->willReturn($expected = $this->getMock(SessionInterface::class)); - - $this->assertSame($expected, $container->getSession()); - } - - public function test_returns_time_provider() - { - $container = new SystemContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.system.time_provider') - ->willReturn($expected = $this->getMock(TimeProviderInterface::class)); - - $this->assertSame($expected, $container->getTimeProvider()); - } - - public function test_returns_event_dispatcher() - { - $container = new SystemContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.system.event_dispatcher') - ->willReturn($expected = $this->getMock(EventDispatcherInterface::class)); - - $this->assertSame($expected, $container->getEventDispatcher()); - } - - public function test_returns_logger() - { - $container = new SystemContainer($containerMock = TestHelper::getContainerMock($this)); - $containerMock->method('get') - ->with('lightsaml.system.logger') - ->willReturn($expected = $this->getMock(LoggerInterface::class)); - - $this->assertSame($expected, $container->getLogger()); + new SystemContainer( + $this->getMockBuilder(RequestStack::class)->getMock(), + $this->getMockBuilder(SessionInterface::class)->getMock(), + $this->getMockBuilder(TimeProviderInterface::class)->getMock(), + $this->getMockBuilder(EventDispatcherInterface::class)->getMock(), + $this->getMockBuilder(LoggerInterface::class)->getMock() + ); } } diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/Compiler/AddMethodCallCompilerPassTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/Compiler/AddMethodCallCompilerPassTest.php index c941d1b..5905ee8 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/Compiler/AddMethodCallCompilerPassTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/Compiler/AddMethodCallCompilerPassTest.php @@ -3,11 +3,12 @@ namespace LightSaml\SymfonyBridgeBundle\Tests\DependencyInjection\Compiler; use LightSaml\SymfonyBridgeBundle\DependencyInjection\Compiler\AddMethodCallCompilerPass; +use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -class AddMethodCallCompilerPassTest extends \PHPUnit_Framework_TestCase +class AddMethodCallCompilerPassTest extends TestCase { public function test_constructs_with_three_strings() { diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/ConfigurationTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/ConfigurationTest.php index cbb97ef..4c8931f 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/ConfigurationTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/ConfigurationTest.php @@ -3,9 +3,10 @@ namespace LightSaml\SymfonyBridgeBundle\Tests\DependencyInjection; use LightSaml\SymfonyBridgeBundle\DependencyInjection\Configuration; +use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\Processor; -class ConfigurationTest extends \PHPUnit_Framework_TestCase +class ConfigurationTest extends TestCase { public function test_passes_with_own_entity_id_only() { diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/LightSamlSymfonyBridgeExtensionTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/LightSamlSymfonyBridgeExtensionTest.php index 9b18367..0ebf416 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/LightSamlSymfonyBridgeExtensionTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/DependencyInjection/LightSamlSymfonyBridgeExtensionTest.php @@ -3,10 +3,11 @@ namespace LightSaml\SymfonyBridgeBundle\Tests\DependencyInjection; use LightSaml\SymfonyBridgeBundle\DependencyInjection\LightSamlSymfonyBridgeExtension; +use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -class LightSamlSymfonyBridgeExtensionTest extends \PHPUnit_Framework_TestCase +class LightSamlSymfonyBridgeExtensionTest extends TestCase { public function test_loads_with_configuration() { @@ -256,11 +257,12 @@ public function test_loads_system_custom_event_dispatcher() $this->assertEquals($expectedAlias, (string) $containerBuilder->getAlias('lightsaml.system.event_dispatcher')); } - public function test_loads_system_logger() + public function test_loads_system_logger_when_given_in_config() { $containerBuilder = new ContainerBuilder(new ParameterBag()); $extension = new LightSamlSymfonyBridgeExtension(); $config = $this->getDefaultConfig(); + $config['light_saml_symfony_bridge']['system']['logger'] = 'some.logger'; $extension->load($config, $containerBuilder); diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Factory/CredentialStoreFactoryTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Factory/CredentialStoreFactoryTest.php index b46a249..9ea1ee7 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Factory/CredentialStoreFactoryTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Factory/CredentialStoreFactoryTest.php @@ -6,20 +6,21 @@ use LightSaml\Store\Credential\CredentialStoreInterface; use LightSaml\Store\EntityDescriptor\EntityDescriptorStoreInterface; use LightSaml\SymfonyBridgeBundle\Factory\CredentialStoreFactory; +use PHPUnit\Framework\TestCase; -class CredentialStoreFactoryTest extends \PHPUnit_Framework_TestCase +class CredentialStoreFactoryTest extends TestCase { public function test_returns_credential_store() { $factory = new CredentialStoreFactory(); - $credentialStoreMock = $this->getMock(CredentialStoreInterface::class); + $credentialStoreMock = $this->getMockBuilder(CredentialStoreInterface::class)->getMock(); $credentialStoreMock->method('getByEntityId') - ->willReturn([$this->getMock(CredentialInterface::class)]); + ->willReturn([$this->getMockBuilder(CredentialInterface::class)->getMock()]); $value = $factory->build( - $this->getMock(EntityDescriptorStoreInterface::class), - $this->getMock(EntityDescriptorStoreInterface::class), + $this->getMockBuilder(EntityDescriptorStoreInterface::class)->getMock(), + $this->getMockBuilder(EntityDescriptorStoreInterface::class)->getMock(), 'own-id', $credentialStoreMock ); diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Factory/OwnEntityDescriptorProviderFactoryTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Factory/OwnEntityDescriptorProviderFactoryTest.php index 1c50903..d54d3fc 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/Factory/OwnEntityDescriptorProviderFactoryTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Factory/OwnEntityDescriptorProviderFactoryTest.php @@ -7,27 +7,28 @@ use LightSaml\Provider\EntityDescriptor\EntityDescriptorProviderInterface; use LightSaml\Store\Credential\CredentialStoreInterface; use LightSaml\SymfonyBridgeBundle\Factory\OwnEntityDescriptorProviderFactory; +use PHPUnit\Framework\TestCase; use Symfony\Component\Routing\RouterInterface; -class OwnEntityDescriptorProviderFactoryTest extends \PHPUnit_Framework_TestCase +class OwnEntityDescriptorProviderFactoryTest extends TestCase { public function test_returns_entity_descriptor_builder() { $factory = new OwnEntityDescriptorProviderFactory(); - $routerMock = $this->getMock(RouterInterface::class); + $routerMock = $this->getMockBuilder(RouterInterface::class)->getMock(); $routerMock->expects($this->exactly(2)) ->method('generate') ->with($this->isType('string'), [], RouterInterface::ABSOLUTE_URL) ->willReturn('http://localhost'); - $credentialStoreMock = $this->getMock(CredentialStoreInterface::class); + $credentialStoreMock = $this->getMockBuilder(CredentialStoreInterface::class)->getMock(); $credentialStoreMock->method('getByEntityId') ->with($ownEntityId = 'own-id') - ->willReturn([$credentialMock = $this->getMock(X509CredentialInterface::class)]); + ->willReturn([$credentialMock = $this->getMockBuilder(X509CredentialInterface::class)->getMock()]); $credentialMock->method('getCertificate') - ->willReturn($this->getMock(X509Certificate::class)); + ->willReturn($this->getMockBuilder(X509Certificate::class)->getMock()); $value = $factory->build( $ownEntityId, diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/FunctionalTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/FunctionalTest.php new file mode 100644 index 0000000..849b882 --- /dev/null +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/FunctionalTest.php @@ -0,0 +1,146 @@ +remove(__DIR__.'/cache'); + } + + protected static function getKernelClass() + { + return TestKernel::class; + } + + public function test_build_container() + { + static::createClient(); + /** @var BuildContainerInterface $buildContainer */ + $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); + $this->assertInstanceOf(BuildContainerInterface::class, $buildContainer); + $this->assertInstanceOf(SystemContainerInterface::class, $buildContainer->getSystemContainer()); + $this->assertInstanceOf(OwnContainerInterface::class, $buildContainer->getOwnContainer()); + $this->assertInstanceOf(PartyContainerInterface::class, $buildContainer->getPartyContainer()); + $this->assertInstanceOf(StoreContainerInterface::class, $buildContainer->getStoreContainer()); + } + + public function test_system_container() { + static::createClient(); + /** @var BuildContainerInterface $buildContainer */ + $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); + $systemContainer = $buildContainer->getSystemContainer(); + $this->assertInstanceOf(EventDispatcherInterface::class, $systemContainer->getEventDispatcher()); + $this->assertInstanceOf(LoggerInterface::class, $systemContainer->getLogger()); + $this->assertInstanceOf(TimeProviderInterface::class, $systemContainer->getTimeProvider()); + } + + public function test_party_container() + { + static::createClient(); + /** @var BuildContainerInterface $buildContainer */ + $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); + $partyContainer = $buildContainer->getPartyContainer(); + $this->assertInstanceOf(EntityDescriptorStoreInterface::class, $partyContainer->getIdpEntityDescriptorStore()); + $this->assertInstanceOf(EntityDescriptorStoreInterface::class, $partyContainer->getSpEntityDescriptorStore()); + $this->assertInstanceOf(TrustOptionsStoreInterface::class, $partyContainer->getTrustOptionsStore()); + } + + public function test_store_container() + { + static::createClient(); + /** @var BuildContainerInterface $buildContainer */ + $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); + $storeContainer = $buildContainer->getStoreContainer(); + $this->assertInstanceOf(RequestStateStoreInterface::class, $storeContainer->getRequestStateStore()); + $this->assertInstanceOf(IdStoreInterface::class, $storeContainer->getIdStateStore()); + $this->assertInstanceOf(SsoStateStoreInterface::class, $storeContainer->getSsoStateStore()); + } + + public function test_provider_container() + { + static::createClient(); + /** @var BuildContainerInterface $buildContainer */ + $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); + $providerContainer = $buildContainer->getProviderContainer(); + $this->assertInstanceOf(AttributeValueProviderInterface::class, $providerContainer->getAttributeValueProvider()); + $this->assertInstanceOf(SessionInfoProviderInterface::class, $providerContainer->getSessionInfoProvider()); + $this->assertInstanceOf(NameIdProviderInterface::class, $providerContainer->getNameIdProvider()); + } + + public function test_credential_container() + { + static::createClient(); + /** @var BuildContainerInterface $buildContainer */ + $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); + $credentialContainer = $buildContainer->getCredentialContainer(); + $this->assertInstanceOf(CredentialStoreInterface::class, $credentialContainer->getCredentialStore()); + } + + public function test_service_container() + { + static::createClient(); + /** @var BuildContainerInterface $buildContainer */ + $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); + $serviceContainer = $buildContainer->getServiceContainer(); + $this->assertInstanceOf(AssertionValidatorInterface::class, $serviceContainer->getAssertionValidator()); + $this->assertInstanceOf(AssertionTimeValidatorInterface::class, $serviceContainer->getAssertionTimeValidator()); + $this->assertInstanceOf(SignatureResolverInterface::class, $serviceContainer->getSignatureResolver()); + $this->assertInstanceOf(EndpointResolverInterface::class, $serviceContainer->getEndpointResolver()); + $this->assertInstanceOf(NameIdValidatorInterface::class, $serviceContainer->getNameIdValidator()); + $this->assertInstanceOf(BindingFactoryInterface::class, $serviceContainer->getBindingFactory()); + $this->assertInstanceOf(SignatureValidatorInterface::class, $serviceContainer->getSignatureValidator()); + $this->assertInstanceOf(CredentialResolverInterface::class, $serviceContainer->getCredentialResolver()); + $this->assertInstanceOf(SessionProcessorInterface::class, $serviceContainer->getSessionProcessor()); + } + + + public function test_own_container() + { + static::createClient(); + /** @var BuildContainerInterface $buildContainer */ + $buildContainer = static::$kernel->getContainer()->get('lightsaml.container.build'); + $ownContainer = $buildContainer->getOwnContainer(); + $this->assertInstanceOf(EntityDescriptorProviderInterface::class, $ownContainer->getOwnEntityDescriptorProvider()); + $this->assertInternalType('array', $ownContainer->getOwnCredentials()); + array_map(function ($credential) { + $this->assertInstanceOf(CredentialInterface::class, $credential); + }, $ownContainer->getOwnCredentials()); + } +} \ No newline at end of file diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/TestKernel.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/TestKernel.php new file mode 100644 index 0000000..3a8888b --- /dev/null +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/TestKernel.php @@ -0,0 +1,36 @@ +load(__DIR__.'/config.yml'); + } + + +} \ No newline at end of file diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/config.yml b/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/config.yml new file mode 100644 index 0000000..f81eaca --- /dev/null +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/config.yml @@ -0,0 +1,27 @@ +framework: + secret: secret + test: ~ + router: { resource: "%kernel.root_dir%/routing.yml" } + csrf_protection: false + templating: false + session: + storage_id: session.mock_storage + +services: + session.mock_storage: + class: Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage + +light_saml_symfony_bridge: + own: + entity_id: https://localhost/lightSAML/SymfonyBridgeBundle + credentials: + - + certificate: "%kernel.root_dir%/../../../../../vendor/lightsaml/lightsaml/web/sp/saml.crt" + key: "%kernel.root_dir%/../../../../../vendor/lightsaml/lightsaml/web/sp/saml.key" + password: ~ + party: + idp: + files: + - "%kernel.root_dir%/../../../../../vendor/lightsaml/lightsaml/web/sp/openidp.feide.no.xml" + - "%kernel.root_dir%/../../../../../vendor/lightsaml/lightsaml/web/sp/localhost-lightsaml-lightsaml-idp.xml" + - "%kernel.root_dir%/../../../../../vendor/lightsaml/lightsaml/web/sp/testshib-providers.xml" diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/routing.yml b/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/routing.yml new file mode 100644 index 0000000..c409c17 --- /dev/null +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/Functional/routing.yml @@ -0,0 +1,2 @@ +lightsaml.login_check: + path: /login_check diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/LightSamlSymfonyBridgeBundleTest.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/LightSamlSymfonyBridgeBundleTest.php index 6789ca8..15629b2 100644 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/LightSamlSymfonyBridgeBundleTest.php +++ b/tests/LightSaml/SymfonyBridgeBundle/Tests/LightSamlSymfonyBridgeBundleTest.php @@ -4,10 +4,11 @@ use LightSaml\SymfonyBridgeBundle\DependencyInjection\Compiler\AddMethodCallCompilerPass; use LightSaml\SymfonyBridgeBundle\LightSamlSymfonyBridgeBundle; +use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -class LightSamlSymfonyBridgeBundleTest extends \PHPUnit_Framework_TestCase +class LightSamlSymfonyBridgeBundleTest extends TestCase { public function build_adds_own_credential_store_compiler_pass_provider() { diff --git a/tests/LightSaml/SymfonyBridgeBundle/Tests/TestHelper.php b/tests/LightSaml/SymfonyBridgeBundle/Tests/TestHelper.php deleted file mode 100644 index a328bd1..0000000 --- a/tests/LightSaml/SymfonyBridgeBundle/Tests/TestHelper.php +++ /dev/null @@ -1,16 +0,0 @@ -getMock(\Symfony\Component\DependencyInjection\ContainerInterface::class); - } -}