public function test_response() { $response = new Response(); $response->addAssertion($assertion = new Assertion())->setStatus(new Status(new StatusCode(SamlConstants::STATUS_SUCCESS))); $assertion->setId(Helper::generateID())->setIssuer(new Issuer('https://issuer.com')); $this->verify($response); }
public function test_success_response_with_xsd() { $response = new Response(); $response->setStatus(new Status(new StatusCode(SamlConstants::STATUS_SUCCESS)))->setInResponseTo(Helper::generateID())->setID(Helper::generateID())->setIssueInstant(new \DateTime())->setIssuer(new Issuer('https://idp.com')); $response->addAssertion($assertion = new Assertion()); $assertion->setId(Helper::generateID())->setIssueInstant(new \DateTime())->setIssuer(new Issuer('https://idp.com'))->setSubject((new Subject())->setNameID(new NameID('*****@*****.**', SamlConstants::NAME_ID_FORMAT_EMAIL))->addSubjectConfirmation((new SubjectConfirmation())->setMethod(SamlConstants::CONFIRMATION_METHOD_BEARER)->setSubjectConfirmationData((new SubjectConfirmationData())->setInResponseTo(Helper::generateID())->setNotOnOrAfter(new \DateTime('+1 hour'))->setRecipient('https://sp.com/acs'))))->setConditions((new Conditions())->setNotBefore(new \DateTime())->setNotOnOrAfter(new \DateTime('+1 hour'))->addItem(new AudienceRestriction(['https://sp.com/acs'])))->addItem((new AttributeStatement())->addAttribute(new Attribute(ClaimTypes::EMAIL_ADDRESS, '*****@*****.**')))->addItem((new AuthnStatement())->setAuthnInstant(new \DateTime('-1 hour'))->setSessionIndex(Helper::generateID())->setAuthnContext((new AuthnContext())->setAuthnContextClassRef(SamlConstants::AUTHN_CONTEXT_PASSWORD_PROTECTED_TRANSPORT))); $this->sign($assertion); $this->sign($response); $this->validateProtocol($response); }
public function test_sets_unknown_assertion_id_to_store() { $action = new RepeatedIdValidatorAction($loggerMock = TestHelper::getLoggerMock($this), $idStoreMock = TestHelper::getIdStoreMock($this)); $assertionContext = TestHelper::getAssertionContext($assertion = new Assertion()); $assertion->setId($assertionId = '123'); $assertion->setIssuer(new Issuer($issuer = 'http://issuer.com')); $assertion->addItem(new AuthnStatement()); $assertion->setSubject(new Subject()); $assertion->getSubject()->addSubjectConfirmation($subjectConfirmation = new SubjectConfirmation()); $subjectConfirmation->setMethod(SamlConstants::CONFIRMATION_METHOD_BEARER); $subjectConfirmation->setSubjectConfirmationData(new SubjectConfirmationData()); $subjectConfirmation->getSubjectConfirmationData()->setNotOnOrAfter(new \DateTime()); $idStoreMock->expects($this->once())->method('has')->with($issuer, $assertionId)->willReturn(false); $idStoreMock->expects($this->once())->method('set')->with($issuer, $assertionId, $this->isInstanceOf(\DateTime::class)); $action->execute($assertionContext); }
public function test_statement_validator_is_called_for_authn_statement() { $nameIdValidatorMock = $this->getNameIdValidatorMock(); $subjectValidatorMock = $this->getSubjectValidatorMock(); $statementValidatorMock = $this->getStatementValidatorMock(); $validator = new AssertionValidator($nameIdValidatorMock, $subjectValidatorMock, $statementValidatorMock); $authnStatement = new AuthnStatement(); $statementValidatorMock->expects($this->once())->method('validateStatement')->with($authnStatement); $assertion = new Assertion(); $assertion->setId('1234567890123456')->setIssueInstant(1000)->setIssuer(new Issuer('issuer'))->setSubject(new Subject())->addItem($authnStatement); $validator->validateAssertion($assertion); }