/** * @test */ public function shouldCreateTokenFromIDPResponseAndPassItToAuthenticationManager() { $requestMock = $this->createRequestStub($hasSessionReturn = true, $hasPreviousSessionReturn = true, $duplicateReturn = $this->createRequestMock(), $getSessionReturn = $this->createSessionMock()); $duplicateReturn->attributes = new ParameterBag(); $nameID = new NameID(); $nameID->setValue('name.id'); $attribute1 = new Attribute(); $attribute1->setName('common.name'); $attribute1->setValues(array('my common name')); $authnStatement = new AuthnStatement(); $authnStatement->setSessionIndex('1234567890'); $relyingPartyMock = $this->createRelyingPartyStub($supportsReturn = true, $manageReturnSamlSpInfo = new SamlSpInfo('idp1', $nameID, array($attribute1), $authnStatement)); $httpUtilsStub = $this->createHttpUtilsStub($checkRequestPathReturn = true, $createRedirectResponseReturn = new RedirectResponse('uri')); $testCase = $this; $authenticationManagerMock = $this->createAuthenticationManagerMock(); $authenticationManagerMock->expects($this->once())->method('authenticate')->with($this->isInstanceOf('AerialShip\\SamlSPBundle\\Security\\Core\\Authentication\\Token\\SamlSpToken'))->will($this->returnCallback(function (SamlSpToken $actualToken) use($testCase, $manageReturnSamlSpInfo) { $samlInfo = $actualToken->getSamlSpInfo(); $testCase->assertNotNull($samlInfo); $testCase->assertNotNull($samlInfo->getNameID()); $testCase->assertEquals('name.id', $samlInfo->getNameID()->getValue()); $testCase->assertNotNull($samlInfo->getAttributes()); $testCase->assertCount(1, $samlInfo->getAttributes()); $testCase->assertEquals($manageReturnSamlSpInfo, $actualToken->getSamlSpInfo()); return $actualToken; })); $eventMock = $this->createGetResponseEventStub($requestMock); $listener = new SamlSpAuthenticationListener($this->createSecurityContextMock(), $authenticationManagerMock, $this->createSessionAuthenticationStrategyMock(), $httpUtilsStub, 'providerKey', $this->createAuthenticationSuccessHandlerStub(), $this->createAuthenticationFailureHandlerMock(), $options = array()); $listener->setRelyingParty($relyingPartyMock); $listener->handle($eventMock); }
/** * @param Attribute[] $attributes * @return array */ public function getAttributes(array $attributes = array('a' => 1, 'b' => array(2, 3))) { $arrAttributes = array(); foreach ($attributes as $name => $value) { $a = new Attribute(); $a->setName($name); if (!is_array($value)) { $value = array($value); } $a->setValues($value); $arrAttributes[] = $a; } return $arrAttributes; }