Gets the NameID Data provided by the SAML response from the IdP.
public getNameIdData ( ) : array | ||
return | array | Name ID Data (Value, Format, NameQualifier, SPNameQualifier) |
/** * Tests the getNameIdData method of the OneLogin_Saml2_Response * * @covers OneLogin_Saml2_Response::getNameIdData */ public function testGetNameIdData() { $xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64'); $response = new OneLogin_Saml2_Response($this->_settings, $xml); $expectedNameIdData = array('Value' => '*****@*****.**', 'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'); $nameIdData = $response->getNameIdData(); $this->assertEquals($expectedNameIdData, $nameIdData); $xml2 = file_get_contents(TEST_ROOT . '/data/responses/response_encrypted_nameid.xml.base64'); $response2 = new OneLogin_Saml2_Response($this->_settings, $xml2); $expectedNameIdData2 = array('Value' => '2de11defd199f8d5bb63f9b7deb265ba5c675c10', 'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified', 'SPNameQualifier' => 'https://pitbulk.no-ip.org/newonelogin/demo1/metadata.php'); $nameIdData2 = $response2->getNameIdData(); $this->assertEquals($expectedNameIdData2, $nameIdData2); $xml3 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64'); $response3 = new OneLogin_Saml2_Response($this->_settings, $xml3); $expectedNameIdData3 = array('Value' => '_68392312d490db6d355555cfbbd8ec95d746516f60', 'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient', 'SPNameQualifier' => 'http://stuff.com/endpoints/metadata.php'); $nameIdData3 = $response3->getNameIdData(); $this->assertEquals($expectedNameIdData3, $nameIdData3); $xml4 = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_nameid.xml.base64'); $response4 = new OneLogin_Saml2_Response($this->_settings, $xml4); try { $nameIdData4 = $response4->getNameIdData(); } catch (Exception $e) { $this->assertContains('Not NameID found in the assertion of the Response', $e->getMessage()); } }
/** * Tests the getNameIdData method of the OneLogin_Saml2_Response * * @covers OneLogin_Saml2_Response::getNameIdData */ public function testGetNameIdData() { $xml = file_get_contents(TEST_ROOT . '/data/responses/response1.xml.base64'); $response = new OneLogin_Saml2_Response($this->_settings, $xml); $expectedNameIdData = array('Value' => '*****@*****.**', 'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'); $nameIdData = $response->getNameIdData(); $this->assertEquals($expectedNameIdData, $nameIdData); $xml2 = file_get_contents(TEST_ROOT . '/data/responses/response_encrypted_nameid.xml.base64'); $response2 = new OneLogin_Saml2_Response($this->_settings, $xml2); $expectedNameIdData2 = array('Value' => '2de11defd199f8d5bb63f9b7deb265ba5c675c10', 'Format' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', 'SPNameQualifier' => 'http://stuff.com/endpoints/metadata.php'); $nameIdData2 = $response2->getNameIdData(); $this->assertEquals($expectedNameIdData2, $nameIdData2); $xml3 = file_get_contents(TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64'); $response3 = new OneLogin_Saml2_Response($this->_settings, $xml3); $expectedNameIdData3 = array('Value' => '_68392312d490db6d355555cfbbd8ec95d746516f60', 'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient', 'SPNameQualifier' => 'http://stuff.com/endpoints/metadata.php'); $nameIdData3 = $response3->getNameIdData(); $this->assertEquals($expectedNameIdData3, $nameIdData3); $xml4 = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_nameid.xml.base64'); $response4 = new OneLogin_Saml2_Response($this->_settings, $xml4); try { $nameIdData4 = $response4->getNameIdData(); } catch (Exception $e) { $this->assertContains('Not NameID found in the assertion of the Response', $e->getMessage()); } $settingsDir = TEST_ROOT . '/settings/'; include $settingsDir . 'settings1.php'; $settingsInfo['security']['wantNameId'] = true; $settings = new OneLogin_Saml2_Settings($settingsInfo); $response5 = new OneLogin_Saml2_Response($settings, $xml4); try { $nameIdData5 = $response5->getNameIdData(); } catch (Exception $e) { $this->assertContains('Not NameID found in the assertion of the Response', $e->getMessage()); } $settingsInfo['security']['wantNameId'] = false; $settings = new OneLogin_Saml2_Settings($settingsInfo); $response6 = new OneLogin_Saml2_Response($settings, $xml4); $nameIdData6 = $response6->getNameIdData(); $this->assertEmpty($nameIdData6); unset($settingsInfo['security']['wantNameId']); $settings = new OneLogin_Saml2_Settings($settingsInfo); $response7 = new OneLogin_Saml2_Response($settings, $xml4); try { $nameIdData7 = $response7->getNameIdData(); } catch (Exception $e) { $this->assertContains('Not NameID found in the assertion of the Response', $e->getMessage()); } $xml5 = file_get_contents(TEST_ROOT . '/data/responses/wrong_spnamequalifier.xml.base64'); $response8 = new OneLogin_Saml2_Response($settings, $xml5); try { $nameIdData8 = $response8->getNameIdData(); } catch (Exception $e) { $this->assertContains('The SPNameQualifier value mistmatch the SP entityID value.', $e->getMessage()); } $xml6 = file_get_contents(TEST_ROOT . '/data/responses/invalids/empty_nameid.xml.base64'); $response9 = new OneLogin_Saml2_Response($settings, $xml6); try { $nameIdData9 = $response9->getNameIdData(); } catch (Exception $e) { $this->assertContains('An empty NameID value found', $e->getMessage()); } }