public function test_adds_sso_session_state() { $state = new SsoState(); $session1 = new SsoSessionState(); $session1->setIdpEntityId($session1Idp = 'http://idp-1.com'); $session1->setSpEntityId($session1sp = 'http://sp-1.com'); $state->addSsoSession($session1); $this->assertTrue(is_array($state->getSsoSessions())); $this->assertCount(1, $state->getSsoSessions()); $session2 = new SsoSessionState(); $session2->setIdpEntityId($session1Idp = 'http://idp-2.com'); $session2->setSpEntityId($session1sp = 'http://sp-2.com'); $state->addSsoSession($session1); $this->assertCount(2, $state->getSsoSessions()); }
public function test_serialization_and_deserialization() { $state = new SsoSessionState(); $state->setIdpEntityId($idp = 'IDP')->setSpEntityId($sp = 'SP')->setNameId($nameId = 'name.id')->setNameIdFormat($nameIdFormat = 'name.id.format')->setSessionIndex($sessionIndex = 'session.index')->setFirstAuthOn($firstAuthOn = new \DateTime('2015-10-27 08:00:00'))->setLastAuthOn($lastAuthOn = new \DateTime('2015-10-27 10:00:00'))->setSessionInstant($sessionInstant = new \DateTime('2015-10-27 06:00:00')); $data = $state->serialize(); $otherState = new SsoSessionState(); $otherState->unserialize($data); $this->assertEquals($state->getIdpEntityId(), $otherState->getIdpEntityId()); $this->assertEquals($state->getSpEntityId(), $otherState->getSpEntityId()); $this->assertEquals($state->getNameId(), $otherState->getNameId()); $this->assertEquals($state->getNameIdFormat(), $otherState->getNameIdFormat()); $this->assertEquals($state->getSessionIndex(), $otherState->getSessionIndex()); $this->assertEquals($state->getFirstAuthOn(), $otherState->getFirstAuthOn()); $this->assertEquals($state->getLastAuthOn(), $otherState->getLastAuthOn()); $this->assertEquals($state->getSessionInstant(), $otherState->getSessionInstant()); }
public function test_serialization() { $state = new SsoSessionState(); $state->setIdpEntityId('idp'); $state->setSpEntityId('sp'); $state->setNameId('name-id'); $state->setNameIdFormat('name-id-format'); $state->setSessionIndex('session-index'); $state->getParameters()->replace(['a' => 'abc', 'b' => 22, 'c' => [1, 2]]); /** @var SsoSessionState $other */ $other = unserialize(serialize($state)); $this->assertInstanceOf(SsoSessionState::class, $other); $this->assertInstanceOf(ParameterBag::class, $other->getParameters()); $this->assertEquals($state->getIdpEntityId(), $other->getIdpEntityId()); $this->assertEquals($state->getSpEntityId(), $other->getSpEntityId()); $this->assertEquals($state->getNameId(), $other->getNameId()); $this->assertEquals($state->getNameIdFormat(), $other->getNameIdFormat()); $this->assertEquals($state->getSessionIndex(), $other->getSessionIndex()); $this->assertEquals($state->getParameters()->all(), $other->getParameters()->all()); }
/** * @param SsoState $ssoState * @param Assertion $assertion * @param \DateTime $now * @param string $ownEntityId * @param string $partyEntityId * * @return SsoSessionState */ protected function createSession(SsoState $ssoState, Assertion $assertion, \DateTime $now, $ownEntityId, $partyEntityId) { $ssoSession = new SsoSessionState(); $ssoSession->setIdpEntityId($partyEntityId)->setSpEntityId($ownEntityId)->setNameId($assertion->getSubject()->getNameID()->getValue())->setNameIdFormat($assertion->getSubject()->getNameID()->getFormat())->setSessionIndex($assertion->getFirstAuthnStatement()->getSessionIndex())->setSessionInstant($assertion->getFirstAuthnStatement()->getAuthnInstantDateTime())->setFirstAuthOn($now)->setLastAuthOn($now); $ssoState->addSsoSession($ssoSession); return $ssoSession; }
public function test_modify() { $state = new SsoState(); $state->addSsoSession($session1 = new SsoSessionState()); $session1->setIdpEntityId('idp-1'); $state->addSsoSession($session2 = new SsoSessionState()); $session2->setIdpEntityId('idp-2'); $state->modify(function (SsoSessionState $session) use($session1) { return $session->getIdpEntityId() != $session1->getIdpEntityId(); }); $sessions = $state->getSsoSessions(); $this->assertCount(1, $sessions); $this->assertEquals($session2->getIdpEntityId(), $sessions[0]->getIdpEntityId()); }