public function test_receives_message()
 {
     $action = new ReceiveMessageAction($logger = TestHelper::getLoggerMock($this), $bindingFactory = $this->getBindingFactoryMock());
     $context = new ProfileContext(Profiles::SSO_SP_SEND_AUTHN_REQUEST, ProfileContext::ROLE_SP);
     $context->getHttpRequestContext()->setRequest($request = new Request());
     $binding = $this->getBindingMock();
     $bindingFactory->expects($this->once())->method('detectBindingType')->with($request)->willReturn($bindingType = SamlConstants::BINDING_SAML2_HTTP_POST);
     $logger->expects($this->once())->method('debug')->with('Detected binding type: urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST', $this->isType('array'));
     $bindingFactory->expects($this->once())->method('create')->with($bindingType)->willReturn($binding);
     $binding->expects($this->once())->method('receive')->with($request, $context->getInboundContext());
     $action->execute($context);
     $this->assertEquals($bindingType, $context->getInboundContext()->getBindingType());
 }
    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())));
    }
 public function test__get_http_request_returns_from_context()
 {
     $profileContext = new ProfileContext(Profiles::METADATA, ProfileContext::ROLE_IDP);
     $profileContext->getHttpRequestContext()->setRequest($expectedValue = new Request());
     $this->assertSame($expectedValue, $profileContext->getHttpRequest());
 }
 /**
  * @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;
 }