예제 #1
0
 /**
  * @expectedException \LightSaml\Error\LightSamlContextException
  * @expectedExceptionMessage Missing ACS Service with HTTP POST binding in own SP SSO Descriptor
  */
 public function test_throws_context_exception_if_no_own_acs_service()
 {
     $action = new ACSUrlAction($loggerMock = TestHelper::getLoggerMock($this), $endpointResolverMock = $this->getEndpointResolverMock());
     $context = new ProfileContext(Profiles::SSO_SP_SEND_AUTHN_REQUEST, ProfileContext::ROLE_SP);
     $context->getOwnEntityContext()->setEntityDescriptor($entityDescriptorMock = $this->getEntityDescriptorMock());
     $entityDescriptorMock->expects($this->once())->method('getAllEndpoints')->willReturn([]);
     $endpointResolverMock->expects($this->once())->method('resolve')->willReturn([]);
     $loggerMock->expects($this->once())->method('error');
     $action->execute($context);
 }
 /**
  * @param string $ownRole
  * @param string $destination
  *
  * @return ProfileContext
  */
 private function buildContext($ownRole, $destination)
 {
     $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, $ownRole);
     $context->getInboundContext()->setMessage(new AuthnRequest());
     if ($destination) {
         $context->getInboundMessage()->setDestination($destination);
     }
     $context->getOwnEntityContext()->setEntityDescriptor(new EntityDescriptor());
     return $context;
 }
 public function test_sets_own_entity_id_to_outbounding_message_issuer_with_name_id_format_entity()
 {
     $action = new CreateMessageIssuerAction(TestHelper::getLoggerMock($this));
     $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP);
     $context->getOutboundContext()->setMessage($message = new AuthnRequest());
     $context->getOwnEntityContext()->setEntityDescriptor(new EntityDescriptor($ownEntityId = 'http://own.entity.id'));
     $action->execute($context);
     $this->assertNotNull($message->getIssuer());
     $this->assertEquals($ownEntityId, $message->getIssuer()->getValue());
     $this->assertEquals(SamlConstants::NAME_ID_FORMAT_ENTITY, $message->getIssuer()->getFormat());
 }
 /**
  * @expectedException \LightSaml\Error\LightSamlContextException
  * @expectedExceptionMessage No credentials resolved for assertion decryption
  */
 public function test_throws_context_exception_when_no_credentials_resolved()
 {
     $action = new DecryptAssertionsAction($loggerMock = TestHelper::getLoggerMock($this), $credentialResolverMock = $this->getCredentialResolverMock());
     $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP);
     $context->getOwnEntityContext()->setEntityDescriptor(new EntityDescriptor($entityId = 'http://entity.id'));
     $context->getInboundContext()->setMessage($response = new Response());
     $response->addEncryptedAssertion($encryptedAssertionMock1 = $this->getEncryptedAssertionReaderMock());
     $credentialResolverMock->expects($this->once())->method('query')->willReturn($query = new CredentialResolverQuery($credentialResolverMock));
     $credentialResolverMock->expects($this->once())->method('resolve')->with($query)->willReturn([]);
     $action->execute($context);
 }
예제 #5
0
 public function test_calls_session_processor()
 {
     $action = new SpSsoStateAction(TestHelper::getLoggerMock($this), $sessionProcessorMock = $this->getSessionProcessorMock());
     $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP);
     $context->getInboundContext()->setMessage($response = new Response());
     $response->addAssertion($assertion1 = new Assertion());
     $response->addAssertion($assertion2 = new Assertion());
     $context->getOwnEntityContext()->setEntityDescriptor(new EntityDescriptor($ownEntityId = 'http://own.entity.id'));
     $context->getPartyEntityContext()->setEntityDescriptor(new EntityDescriptor($partyEntityId = 'http://party.id'));
     $sessionProcessorMock->expects($this->once())->method('processAssertions')->with($this->isType('array'), $ownEntityId, $partyEntityId)->willReturnCallback(function (array $assertions, $ownId, $partyId) use($assertion1, $assertion2) {
         $this->assertSame($assertion1, $assertions[0]);
         $this->assertSame($assertion2, $assertions[1]);
     });
     $action->execute($context);
 }
    public function test_creates_http_response_with_serialized_own_entity()
    {
        $loggerMock = TestHelper::getLoggerMock($this);
        $action = new SerializeOwnEntityAction($loggerMock);
        $context = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP);
        $context->getOwnEntityContext()->setEntityDescriptor($ownEntityDescriptor = new EntityDescriptor($myEntityId = 'http://localhost/myself'));
        $context->getHttpRequestContext()->setRequest($httpRequest = new Request());
        $httpRequest->headers->add(['Accept' => $contextType = 'application/samlmetadata+xml']);
        $action->execute($context);
        /** @var Response $response */
        $response = $context->getHttpResponseContext()->getResponse();
        $this->assertNotNull($response);
        $this->assertEquals($contextType, $response->headers->get('Content-Type'));
        $expectedContent = <<<EOT
<?xml version="1.0"?>
<EntityDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" entityID="http://localhost/myself"/>
EOT;
        $expectedContent = trim(str_replace("\r", '', $expectedContent));
        $this->assertEquals($expectedContent, trim(str_replace("\r", '', $response->getContent())));
    }
예제 #7
0
 public function test__get_own_entity_descriptor_returns_from_context()
 {
     $profileContext = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP);
     $profileContext->getOwnEntityContext()->setEntityDescriptor($expectedValue = new EntityDescriptor());
     $this->assertSame($expectedValue, $profileContext->getOwnEntityDescriptor());
 }
예제 #8
0
 /**
  * @return ProfileContext
  */
 public function build()
 {
     if (null === $this->request) {
         throw new LightSamlBuildException('HTTP Request not set');
     }
     if (null === $this->ownEntityDescriptorProvider) {
         throw new LightSamlBuildException('Own EntityDescriptor not set');
     }
     if (null === $this->profileId) {
         throw new LightSamlBuildException('ProfileID not set');
     }
     if (null === $this->profileRole) {
         throw new LightSamlBuildException('Profile role not set');
     }
     $result = new ProfileContext($this->profileId, $this->profileRole);
     $result->getHttpRequestContext()->setRequest($this->request);
     $result->getOwnEntityContext()->setEntityDescriptor($this->ownEntityDescriptorProvider->get());
     return $result;
 }
 /**
  * @param string $ownEntityId
  *
  * @return ProfileContext
  */
 private function buildContext($ownEntityId = 'own.entity.id')
 {
     $context = new ProfileContext(Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST, ProfileContext::ROLE_IDP);
     $context->getOwnEntityContext()->setEntityDescriptor(new EntityDescriptor($ownEntityId));
     return $context;
 }