@@ -2300,6 +2300,57 @@ public void testIsValidSign() throws IOException, Error, XPathExpressionExceptio
23002300 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
23012301 assertTrue (samlResponse .isValid ());
23022302 }
2303+
2304+ /**
2305+ * Tests the isValid method of SamlResponse with idpx509certMulti
2306+ * Case: valid sign response / sign assertion / both signed
2307+ *
2308+ * @throws ValidationError
2309+ * @throws SettingsException
2310+ * @throws IOException
2311+ * @throws SAXException
2312+ * @throws ParserConfigurationException
2313+ * @throws XPathExpressionException
2314+ * @throws Error
2315+ *
2316+ * @see com.onelogin.saml2.authn.SamlResponse#isValid
2317+ */
2318+ @ Test
2319+ public void testIsValidSignWithCertMulti () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
2320+ Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.mywithmulticert.properties" ).build ();
2321+ settings .setWantAssertionsSigned (false );
2322+ settings .setWantMessagesSigned (false );
2323+ String samlResponseEncoded = Util .getFileAsString ("data/responses/signed_message_response.xml.base64" );
2324+
2325+ settings .setStrict (false );
2326+ SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2327+ assertTrue (samlResponse .isValid ());
2328+
2329+ settings .setStrict (true );
2330+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2331+ assertTrue (samlResponse .isValid ());
2332+
2333+ samlResponseEncoded = Util .getFileAsString ("data/responses/signed_assertion_response.xml.base64" );
2334+
2335+ settings .setStrict (false );
2336+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2337+ assertTrue (samlResponse .isValid ());
2338+
2339+ settings .setStrict (true );
2340+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2341+ assertTrue (samlResponse .isValid ());
2342+
2343+ samlResponseEncoded = Util .getFileAsString ("data/responses/double_signed_response.xml.base64" );
2344+
2345+ settings .setStrict (false );
2346+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2347+ assertTrue (samlResponse .isValid ());
2348+
2349+ settings .setStrict (true );
2350+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2351+ assertTrue (samlResponse .isValid ());
2352+ }
2353+
23032354
23042355 /**
23052356 * Tests the processSignedElements method of SamlResponse
@@ -2506,6 +2557,75 @@ public void testIsInValidSign() throws IOException, Error, XPathExpressionExcept
25062557 assertFalse (samlResponse .isValid ());
25072558 assertEquals ("Found an invalid Signed Element. SAML Response rejected" , samlResponse .getError ());
25082559 }
2560+
2561+
2562+
2563+ /**
2564+ * Tests the isValid method of SamlResponse with Idpx509certMulti
2565+ * Case: invalid signs
2566+ *
2567+ * @throws ValidationError
2568+ * @throws SettingsException
2569+ * @throws IOException
2570+ * @throws SAXException
2571+ * @throws ParserConfigurationException
2572+ * @throws XPathExpressionException
2573+ * @throws Error
2574+ *
2575+ * @see com.onelogin.saml2.authn.SamlResponse#isValid
2576+ */
2577+ @ Test
2578+ public void testIsInValidSignWithCertMulti () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
2579+ Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.min.properties" ).build ();
2580+ settings .setStrict (true );
2581+ String samlResponseEncoded = Util .getFileAsString ("data/responses/unsigned_response.xml.base64" );
2582+
2583+ SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2584+ assertFalse (samlResponse .isValid ());
2585+ assertEquals ("No Signature found. SAML Response rejected" , samlResponse .getError ());
2586+
2587+ settings = new SettingsBuilder ().fromFile ("config/config.mywithmulticert.properties" ).build ();
2588+
2589+ samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/triple_signed_response.xml.base64" );
2590+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2591+ assertFalse (samlResponse .isValid ());
2592+ assertEquals ("Duplicated ID. SAML Response rejected" , samlResponse .getError ());
2593+
2594+ samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/signed_assertion_response_with_2signatures.xml.base64" );
2595+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2596+ assertFalse (samlResponse .isValid ());
2597+ assertEquals ("Duplicated ID. SAML Response rejected" , samlResponse .getError ());
2598+
2599+ samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/signed_message_response_with_2signatures.xml.base64" );
2600+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2601+ assertFalse (samlResponse .isValid ());
2602+ assertEquals ("Duplicated ID. SAML Response rejected" , samlResponse .getError ());
2603+
2604+ samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/wrong_signed_element.xml.base64" );
2605+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2606+ assertFalse (samlResponse .isValid ());
2607+ assertEquals ("Invalid Signature Element {urn:oasis:names:tc:SAML:2.0:assertion}Subject SAML Response rejected" , samlResponse .getError ());
2608+
2609+ samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/wrong_signed_element2.xml.base64" );
2610+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2611+ assertFalse (samlResponse .isValid ());
2612+ assertEquals ("Invalid Signature Element {urn:oasis:names:tc:SAML:2.0:assertion}Subject SAML Response rejected" , samlResponse .getError ());
2613+
2614+ samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/duplicate_reference_uri.xml.base64" );
2615+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2616+ assertFalse (samlResponse .isValid ());
2617+ assertEquals ("Found an invalid Signed Element. SAML Response rejected" , samlResponse .getError ());
2618+
2619+ samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/no_assertion_id.xml.base64" );
2620+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2621+ assertFalse (samlResponse .isValid ());
2622+ assertEquals ("Signed Element must contain an ID. SAML Response rejected" , samlResponse .getError ());
2623+
2624+ samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/bad_reference.xml.base64" );
2625+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
2626+ assertFalse (samlResponse .isValid ());
2627+ assertEquals ("Found an invalid Signed Element. SAML Response rejected" , samlResponse .getError ());
2628+ }
25092629
25102630 /**
25112631 * Tests the validateSignedElements method of SamlResponse
0 commit comments