@@ -78,6 +78,23 @@ public void testConstructor() throws IOException, Error, XPathExpressionExceptio
7878 assertTrue (samlResponse instanceof SamlResponse );
7979 }
8080
81+ /**
82+ * Tests that a invalid SAMLResponse with not expected elements fails
83+ *
84+ * @throws Exception
85+ *
86+ * @see com.onelogin.saml2.authn.SamlResponse
87+ */
88+ @ Test
89+ public void testOInvalidResponseWithNonExpectedElementsFail () throws Exception {
90+ expectedEx .expect (ValidationError .class );
91+ expectedEx .expectMessage ("SAML Response could not be processed" );
92+
93+ Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
94+ String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/wrapped_response_2.xml.base64" );
95+
96+ SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
97+ }
8198 /**
8299 * Tests the constructor of SamlResponse
83100 * Case: Encrypted assertion but no key
@@ -906,28 +923,28 @@ public void testGetAttributesDuplicatedNames() throws IOException, Error, XPathE
906923
907924 HashMap <String , List <String >> attributes = samlResponse .getAttributes ();
908925 }
909-
926+
910927 /**
911- * Tests the isValid method of SamlResponse
928+ * Tests that queryAssertion method of SamlResponse
929+ * Case: Elements retrieved are covered by a Signature
912930 *
913931 * @throws Exception
914932 *
915- * @see com.onelogin.saml2.authn.SamlResponse#isValid
933+ * @see com.onelogin.saml2.authn.SamlResponse#queryAssertion
916934 */
917935 @ Test
918- public void testOnlyRetrieveAssertionWithIDThatMatchesSignatureReference () throws Exception {
919- expectedEx .expect (ValidationError .class );
920- expectedEx .expectMessage ("SAML Response could not be processed" );
921-
936+ public void testOnlyRetrieveAssertionWithIDThatMatchesSignatureReference () throws Exception {
922937 Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
923- String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/wrapped_response_2 .xml.base64" );
938+ String samlResponseEncoded = Util .getFileAsString ("data/responses/signed_assertion_response_with_2_assertions .xml.base64" );
924939 SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
925-
926- String nameID = samlResponse .getNameId ();
927- assertFalse (samlResponse .isValid ());
928- assertFalse ("root@example.com" .equals (nameID ));
940+ assertEquals ("492882615acf31c8096b627245d76ae53036c090" , samlResponse .getNameId ());
941+
942+ samlResponseEncoded = Util .getFileAsString ("data/responses/signed_assertion_response_with_2_assertions_differrent_order.xml.base64" );
943+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
944+ assertEquals ("492882615acf31c8096b627245d76ae53036c090" , samlResponse .getNameId ());
929945 }
930-
946+
947+
931948 /**
932949 * Tests the isValid method of SamlResponse
933950 *
0 commit comments