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