public function test_sets_outbounding_message_version_to_value_from_constructor()
 {
     $action = new MessageVersionAction(TestHelper::getLoggerMock($this), $value = SamlConstants::VERSION_20);
     $context = TestHelper::getProfileContext();
     $context->getOutboundContext()->setMessage($message = new AuthnRequest());
     $action->execute($context);
     $this->assertEquals($value, $message->getVersion());
 }
예제 #2
0
 public function test_sets_id_of_outbounding_message()
 {
     $action = new MessageIdAction(TestHelper::getLoggerMock($this));
     $context = TestHelper::getProfileContext();
     $context->getOutboundContext()->setMessage($message = new AuthnRequest());
     $action->execute($context);
     $this->assertNotNull($message->getID());
 }
 /**
  * @expectedException \LogicException
  * @expectedExceptionMessage Expected X509CredentialInterface but got
  */
 public function test_throws_logic_exception_when_returned_value_if_not_credential()
 {
     $signatureResolver = new OwnSignatureResolver($credentialResolverMock = TestHelper::getCredentialResolverMock($this));
     $context = TestHelper::getProfileContext();
     $context->getOwnEntityContext()->setEntityDescriptor($ownEntityDescriptor = new EntityDescriptor($ownEntityId = 'http://own.id'));
     $credentialResolverMock->method('query')->willReturn($query = new CredentialResolverQuery($credentialResolverMock));
     $credentialResolverMock->method('resolve')->willReturn([$this->getMock(CredentialInterface::class)]);
     $signatureResolver->getSignature($context);
 }
 public function test_sets_outbounding_message_issue_instant_to_value_from_time_provider()
 {
     $action = new MessageIssueInstantAction(TestHelper::getLoggerMock($this), $timeProviderMock = TestHelper::getTimeProviderMock($this));
     $timeProviderMock->expects($this->any())->method('getTimestamp')->willReturn(1412399250);
     $context = TestHelper::getProfileContext();
     $context->getOutboundContext()->setMessage($message = new AuthnRequest());
     $action->execute($context);
     $this->assertEquals('2014-10-04T05:07:30Z', $message->getIssueInstantString());
 }
 public function test_does_nothing_if_endpoint_already_set()
 {
     $context = TestHelper::getProfileContext();
     $context->getEndpointContext()->setEndpoint($endpoint = new SingleSignOnService());
     $endpoint->setLocation('http://location.com');
     $endpoint->setBinding(SamlConstants::BINDING_SAML2_HTTP_POST);
     $this->logger->expects($this->once())->method('debug')->with('Endpoint already set with location "http://location.com" and binding "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"', $this->isType('array'));
     $this->setEndpointResolver(false, null);
     $this->action->execute($context);
 }
 public function test_creates_request_state_with_outbound_message_id()
 {
     $action = new SaveRequestStateAction(TestHelper::getLoggerMock($this), $requestStateStoreMock = TestHelper::getRequestStateStoreMock($this));
     $context = TestHelper::getProfileContext();
     $context->getOutboundContext()->setMessage($message = new AuthnRequest());
     $message->setID($id = '123123123');
     $requestStateStoreMock->expects($this->once())->method('set')->with($this->isInstanceOf(RequestState::class))->willReturnCallback(function (RequestState $requestState) use($id) {
         $this->assertEquals($id, $requestState->getId());
     });
     $action->execute($context);
 }
예제 #7
0
 public function test_calls_binding_factory_with_endpoint_type_and_calls_binding_and_sets_response_to_context()
 {
     $action = new SendMessageAction($loggerMock = TestHelper::getLoggerMock($this), $bindingFactoryMock = TestHelper::getBindingFactoryMock($this));
     $context = TestHelper::getProfileContext();
     $context->getEndpointContext()->setEndpoint(new SingleSignOnService($location = 'http://example/com', $bindingType = SamlConstants::BINDING_SAML2_HTTP_POST));
     $bindingFactoryMock->expects($this->once())->method('create')->with($bindingType)->willReturn($bindingMock = TestHelper::getBindingMock($this));
     $bindingMock->expects($this->once())->method('send')->with($this->isInstanceOf(MessageContext::class))->willReturn($response = new Response());
     $loggerMock->expects($this->once())->method('info')->with('Sending message', $this->isType('array'));
     $action->execute($context);
     $this->assertSame($response, $context->getHttpResponseContext()->getResponse());
 }
예제 #8
0
 public function test_signs_message_when_signing_enabled()
 {
     $action = new SignMessageAction($loggerMock = TestHelper::getLoggerMock($this), $signatureResolverMock = TestHelper::getSignatureResolverMock($this));
     $context = TestHelper::getProfileContext();
     $context->getPartyEntityContext()->setTrustOptions(new TrustOptions());
     $context->getTrustOptions()->setSignAuthnRequest(true);
     $context->getOutboundContext()->setMessage($message = new AuthnRequest());
     $signature = new SignatureWriter($certificateMock = TestHelper::getX509CertificateMock($this));
     $certificateMock->expects($this->any())->method('getInfo')->willReturn($expectedInfo = ['a' => 1]);
     $certificateMock->expects($this->any())->method('getFingerprint')->willReturn($expectedFingerprint = '123123123');
     $signatureResolverMock->expects($this->once())->method('getSignature')->with($context)->willReturn($signature);
     $loggerMock->expects($this->once())->method('debug')->with('Message signed with fingerprint "123123123"', $this->isType('array'));
     $action->execute($context);
     $this->assertSame($signature, $message->getSignature());
 }
 /**
  * @param string           $ownRole
  * @param SamlMessage      $inboundMessage
  * @param Endpoint         $endpoint
  * @param EntityDescriptor $partyEntityDescriptor
  * @param string           $profileId
  *
  * @return \LightSaml\Context\Profile\ProfileContext
  */
 protected function createContext($ownRole = ProfileContext::ROLE_IDP, SamlMessage $inboundMessage = null, Endpoint $endpoint = null, EntityDescriptor $partyEntityDescriptor = null, $profileId = Profiles::SSO_IDP_RECEIVE_AUTHN_REQUEST)
 {
     $context = TestHelper::getProfileContext($profileId, $ownRole);
     if ($endpoint) {
         $context->getEndpointContext()->setEndpoint($endpoint);
     }
     if (null == $partyEntityDescriptor) {
         $partyEntityDescriptor = EntityDescriptor::load(__DIR__ . '/../../../../../../../resources/sample/EntityDescriptor/idp2-ed-formatted.xml');
     }
     $context->getPartyEntityContext()->setEntityDescriptor($partyEntityDescriptor);
     if ($inboundMessage) {
         $context->getInboundContext()->setMessage($inboundMessage);
     }
     return $context;
 }
 public function test_returns_context_its_constructed_with()
 {
     $context = TestHelper::getProfileContext();
     $exception = new LightSamlContextException($context, 'message');
     $this->assertSame($context, $exception->getContext());
 }
 public function test_does_nothing_if_recipient_matches_own_acs_service_location()
 {
     $action = new RecipientValidatorAction($loggerMock = TestHelper::getLoggerMock($this), $endpointResolver = TestHelper::getEndpointResolverMock($this));
     $assertionContext = TestHelper::getAssertionContext($assertion = new Assertion());
     $assertion->addItem(new AuthnStatement());
     $assertion->setSubject(new Subject());
     $assertion->getSubject()->addSubjectConfirmation($subjectConfirmation = (new SubjectConfirmation())->setMethod(SamlConstants::CONFIRMATION_METHOD_BEARER));
     $subjectConfirmation->setSubjectConfirmationData((new SubjectConfirmationData())->setRecipient($recipient = 'http://recipient.com'));
     $profileContext = TestHelper::getProfileContext();
     $profileContext->getOwnEntityContext()->setEntityDescriptor($ownEntityDescriptor = new EntityDescriptor());
     $assertionContext->setParent($profileContext);
     $endpointResolver->expects($this->once())->method('resolve')->willReturnCallback(function () use($recipient) {
         return [TestHelper::getEndpointReferenceMock($this, new AssertionConsumerService())];
     });
     $action->execute($assertionContext);
 }
예제 #12
0
    public function test_to_string_gives_debug_tree_string()
    {
        $profileContext = TestHelper::getProfileContext();
        $profileContext->getOwnEntityContext();
        $profileContext->getPartyEntityContext();
        $profileContext->addSubContext('assertion_01', $assertionSubContext01 = new AssertionContext());
        $assertionSubContext01->addSubContext('rs', new RequestStateContext());
        $actual = (string) $profileContext;
        $expected = <<<EOT
{
    "root": "LightSaml\\\\Context\\\\Profile\\\\ProfileContext",
    "root__children": {
        "own_entity": "LightSaml\\\\Context\\\\Profile\\\\EntityContext",
        "party_entity": "LightSaml\\\\Context\\\\Profile\\\\EntityContext",
        "assertion_01": "LightSaml\\\\Context\\\\Profile\\\\AssertionContext",
        "assertion_01__children": {
            "rs": "LightSaml\\\\Context\\\\Profile\\\\RequestStateContext"
        }
    }
}
EOT;
        $this->assertEquals($expected, $actual);
    }
예제 #13
0
 public function test_returns_given_name_id()
 {
     $provider = new FixedNameIdProvider($expected = new NameID());
     $this->assertSame($expected, $provider->getNameID(TestHelper::getProfileContext()));
 }