@@ -232,6 +232,32 @@ public function testGetNameIdFormat()
232232 }
233233 }
234234
235+ /**
236+ * Tests the getNameIdNameQualifier method of the OneLogin_Saml2_Response
237+ *
238+ * @covers OneLogin_Saml2_Response::getNameIdNameQualifier
239+ */
240+ public function testGetNameIdNameQualifier ()
241+ {
242+ $ xml = file_get_contents (TEST_ROOT . '/data/responses/response1.xml.base64 ' );
243+ $ response = new OneLogin_Saml2_Response ($ this ->_settings , $ xml );
244+ $ this ->assertEquals ('https://test.example.com/saml/metadata ' , $ response ->getNameIdNameQualifier ());
245+ $ xml2 = file_get_contents (TEST_ROOT . '/data/responses/response_encrypted_nameid.xml.base64 ' );
246+ $ response2 = new OneLogin_Saml2_Response ($ this ->_settings , $ xml2 );
247+ $ this ->assertEquals (null , $ response2 ->getNameIdNameQualifier ());
248+ $ xml3 = file_get_contents (TEST_ROOT . '/data/responses/valid_encrypted_assertion.xml.base64 ' );
249+ $ response3 = new OneLogin_Saml2_Response ($ this ->_settings , $ xml3 );
250+ $ this ->assertEquals (null , $ response3 ->getNameIdNameQualifier ());
251+ $ xml4 = file_get_contents (TEST_ROOT . '/data/responses/invalids/no_nameid.xml.base64 ' );
252+ $ response4 = new OneLogin_Saml2_Response ($ this ->_settings , $ xml4 );
253+ try {
254+ $ nameId4 = $ response4 ->getNameIdNameQualifier ();
255+ $ this ->fail ('OneLogin_Saml2_ValidationError was not raised ' );
256+ } catch (OneLogin_Saml2_ValidationError $ e ) {
257+ $ this ->assertContains ('NameID not found in the assertion of the Response ' , $ e ->getMessage ());
258+ }
259+ }
260+
235261 /**
236262 * Tests the getNameIdData method of the OneLogin_Saml2_Response
237263 *
@@ -243,7 +269,8 @@ public function testGetNameIdData()
243269 $ response = new OneLogin_Saml2_Response ($ this ->_settings , $ xml );
244270 $ expectedNameIdData = array (
245271 'Value ' => 'support@onelogin.com ' ,
246- 'Format ' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress '
272+ 'Format ' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress ' ,
273+ 'NameQualifier ' => 'https://test.example.com/saml/metadata '
247274 );
248275 $ nameIdData = $ response ->getNameIdData ();
249276 $ this ->assertEquals ($ expectedNameIdData , $ nameIdData );
0 commit comments