@@ -599,6 +599,48 @@ public function testGetAttributes()
599599 }
600600 }
601601
602+ /**
603+ * Tests the getAttributes method of the OneLogin_Saml2_Response
604+ *
605+ * @covers OneLogin_Saml2_Response::getAttributes
606+ */
607+ public function testGetAttributesWithFriendlyName ()
608+ {
609+ $ xml = file_get_contents (TEST_ROOT . '/data/responses/response6.xml.base64 ' );
610+ $ response = new OneLogin_Saml2_Response ($ this ->_settings , $ xml );
611+
612+ $ expectedAttributes = array (
613+ 'uid ' => array (
614+ 'demo '
615+ ),
616+ 'givenName ' => array (
617+ 'value '
618+ ),
619+ );
620+ $ this ->assertEquals ($ expectedAttributes , $ response ->getAttributesWithFriendlyName ());
621+
622+ // An assertion that has no attributes should return an empty array when asked for the attributes
623+ $ xml2 = file_get_contents (TEST_ROOT . '/data/responses/response2.xml.base64 ' );
624+ $ response2 = new OneLogin_Saml2_Response ($ this ->_settings , $ xml2 );
625+
626+ $ this ->assertEmpty ($ response2 ->getAttributesWithFriendlyName ());
627+
628+ // Encrypted Attributes are not supported
629+ $ xml3 = file_get_contents (TEST_ROOT . '/data/responses/invalids/encrypted_attrs.xml.base64 ' );
630+ $ response3 = new OneLogin_Saml2_Response ($ this ->_settings , $ xml3 );
631+ $ this ->assertEmpty ($ response3 ->getAttributesWithFriendlyName ());
632+
633+ // Duplicated Attribute names
634+ $ xml4 = file_get_contents (TEST_ROOT . '/data/responses/invalids/duplicated_attributes_with_friendly_names.xml.base64 ' );
635+ $ response4 = new OneLogin_Saml2_Response ($ this ->_settings , $ xml4 );
636+ try {
637+ $ attrs = $ response4 ->getAttributesWithFriendlyName ();
638+ $ this ->fail ('OneLogin_Saml2_ValidationError was not raised ' );
639+ } catch (OneLogin_Saml2_ValidationError $ e ) {
640+ $ this ->assertContains ('Found an Attribute element with duplicated FriendlyName ' , $ e ->getMessage ());
641+ }
642+ }
643+
602644 /**
603645 * Tests the getNameId method of the OneLogin_Saml2_Response
604646 *
0 commit comments