/** * @test */ public function shouldCopySamlAttributesToAttributes() { $samlSpInfoHelper = new SamlSpInfoHelper(); $token = new SamlSpToken('key'); $expectedSamlSpInfo = $samlSpInfoHelper->getSamlSpInfo(); $token->setSamlSpInfo($expectedSamlSpInfo); $this->assertTrue($token->hasAttribute('a')); $this->assertEquals(1, $token->getAttribute('a')); $this->assertTrue($token->hasAttribute('b')); $this->assertEquals(array(2, 3), $token->getAttribute('b')); }
/** * @test */ public function shouldAllowGetAuthnStatementSetInConstructor() { $helper = new SamlSpInfoHelper(); $expectedAuthnStatement = $helper->getAuthnStatement(); $samlSpInfo = new SamlSpInfo('idp', null, null, $expectedAuthnStatement); $this->assertEquals($expectedAuthnStatement, $samlSpInfo->getAuthnStatement()); }
/** * @test */ public function shouldWrapAnyThrownExceptionsAsAuthenticatedServiceException() { $samlSpInfoHelper = new SamlSpInfoHelper(); $providerKey = 'main'; $expectedSamlSpInfo = $samlSpInfoHelper->getSamlSpInfo(); $expectedPreviousException = new \Exception($expectedMessage = 'Something goes wrong', $expectedCode = 21); $userProviderMock = $this->createUserManagerMock(); $userProviderMock->expects($this->once())->method('loadUserBySamlInfo')->will($this->throwException($expectedPreviousException)); $authProvider = new SamlSpAuthenticationProvider($providerKey, $userProviderMock, $this->createUserCheckerMock()); $token = new SamlSpToken($providerKey); $token->setUser(''); $token->setSamlSpInfo($expectedSamlSpInfo); try { $authProvider->authenticate($token); } catch (AuthenticationServiceException $e) { $this->assertSame($expectedPreviousException, $e->getPrevious(), $e->getPrevious()); $this->assertEquals($expectedMessage, $e->getMessage()); $this->assertEquals($expectedCode, $e->getCode()); $this->assertNull($e->getToken()); return; } $this->fail('Expected exception: AuthenticationServiceException was not thrown'); }