@@ -846,7 +846,7 @@ public void testGetAudiences() throws IOException, Error, XPathExpressionExcepti
846846 }
847847
848848 /**
849- * Tests the getIssuers method of SamlResponse
849+ * Tests the getIssuers methods of SamlResponse
850850 *
851851 * @throws Error
852852 * @throws IOException
@@ -861,46 +861,118 @@ public void testGetAudiences() throws IOException, Error, XPathExpressionExcepti
861861 @ Test
862862 public void testGetIssuers () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
863863 Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
864- String samlResponseEncoded = Util .getFileAsString ("data/responses/response1 .xml.base64" );
864+ String samlResponseEncoded = Util .getFileAsString ("data/responses/valid_encrypted_assertion .xml.base64" );
865865 SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
866+ String expectedIssuer = "http://idp.example.com/" ;
866867 List <String > expectedIssuers = new ArrayList <String >();
867- expectedIssuers .add ("http://idp.example.com/" );
868- samlResponseEncoded = Util . getFileAsString ( "data/responses/valid_encrypted_assertion.xml.base64" );
869- samlResponse = new SamlResponse ( settings , newHttpRequest ( samlResponseEncoded ));
868+ expectedIssuers .add (expectedIssuer );
869+ assertEquals ( expectedIssuer , samlResponse . getResponseIssuer () );
870+ assertEquals ( expectedIssuer , samlResponse . getAssertionIssuer ( ));
870871 assertEquals (expectedIssuers , samlResponse .getIssuers ());
871872
872873 expectedIssuers .remove (0 );
873- expectedIssuers .add ("https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php" );
874+ expectedIssuer = "https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php" ;
875+ expectedIssuers .add (expectedIssuer );
874876
875877 samlResponseEncoded = Util .getFileAsString ("data/responses/signed_message_encrypted_assertion.xml.base64" );
876878 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
879+ assertEquals (expectedIssuer , samlResponse .getResponseIssuer ());
880+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
877881 assertEquals (expectedIssuers , samlResponse .getIssuers ());
878882
879883 samlResponseEncoded = Util .getFileAsString ("data/responses/double_signed_encrypted_assertion.xml.base64" );
880884 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
885+ assertEquals (expectedIssuer , samlResponse .getResponseIssuer ());
886+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
881887 assertEquals (expectedIssuers , samlResponse .getIssuers ());
882888
883889 samlResponseEncoded = Util .getFileAsString ("data/responses/signed_encrypted_assertion.xml.base64" );
884890 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
891+ assertEquals (expectedIssuer , samlResponse .getResponseIssuer ());
892+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
885893 assertEquals (expectedIssuers , samlResponse .getIssuers ());
886894
887895 samlResponseEncoded = Util .getFileAsString ("data/responses/double_signed_response.xml.base64" );
888896 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
897+ assertEquals (expectedIssuer , samlResponse .getResponseIssuer ());
898+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
889899 assertEquals (expectedIssuers , samlResponse .getIssuers ());
890900
891901 samlResponseEncoded = Util .getFileAsString ("data/responses/signed_assertion_response.xml.base64" );
892902 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
903+ assertEquals (expectedIssuer , samlResponse .getResponseIssuer ());
904+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
893905 assertEquals (expectedIssuers , samlResponse .getIssuers ());
894906
907+ expectedIssuer = "https://app.onelogin.com/saml/metadata/13590" ;
895908 expectedIssuers = new ArrayList <String >();
896- expectedIssuers .add ("https://app.onelogin.com/saml/metadata/13590" );
909+ expectedIssuers .add (expectedIssuer );
897910 samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/no_issuer_response.xml.base64" );
898911 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
912+ assertNull (expectedIssuer , samlResponse .getResponseIssuer ());
913+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
899914 assertEquals (expectedIssuers , samlResponse .getIssuers ());
900915 }
901916
902917 /**
903- * Tests the getIssuers method of SamlResponse
918+ * Tests the getIssuers methods of SamlResponse
919+ * <p>
920+ * Case: different issuers for response and assertion
921+ *
922+ * @throws Error
923+ * @throws IOException
924+ * @throws ValidationError
925+ * @throws SettingsException
926+ * @throws SAXException
927+ * @throws ParserConfigurationException
928+ * @throws XPathExpressionException
929+ *
930+ * @see com.onelogin.saml2.authn.SamlResponse#getIssuers
931+ */
932+ @ Test
933+ public void testGetIssuersDifferentIssuers () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
934+ Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
935+ String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/different_issuers.xml.base64" );
936+ SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
937+ List <String > expectedIssuers = new ArrayList <String >();
938+ String expectedResponseIssuer = "https://response-issuer.com" ;
939+ String expectedAssertionIssuer = "https://assertion-issuer.com" ;
940+ expectedIssuers .add (expectedResponseIssuer );
941+ expectedIssuers .add (expectedAssertionIssuer );
942+ assertEquals (expectedResponseIssuer , samlResponse .getResponseIssuer ());
943+ assertEquals (expectedAssertionIssuer , samlResponse .getAssertionIssuer ());
944+ assertEquals (expectedIssuers , samlResponse .getIssuers ());
945+ }
946+
947+ /**
948+ * Tests the getAssertionIssuer method of SamlResponse
949+ * <p>
950+ * Case: Issuer of the assertion not found
951+ *
952+ * @throws Error
953+ * @throws IOException
954+ * @throws ValidationError
955+ * @throws SettingsException
956+ * @throws SAXException
957+ * @throws ParserConfigurationException
958+ * @throws XPathExpressionException
959+ *
960+ * @see com.onelogin.saml2.authn.SamlResponse#getIssuers
961+ */
962+ @ Test
963+ public void testGetAssertionIssuerNoInAssertion () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
964+ Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
965+ String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/no_issuer_assertion.xml.base64" );
966+ SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
967+
968+ expectedEx .expect (ValidationError .class );
969+ expectedEx .expectMessage ("Issuer of the Assertion not found or multiple." );
970+ samlResponse .getAssertionIssuer ();
971+ }
972+
973+ /**
974+ * Tests the getIssuers methods of SamlResponse
975+ * <p>
904976 * Case: Issuer of the assertion not found
905977 *
906978 * @throws Error
@@ -919,11 +991,12 @@ public void testGetIssuersNoInAssertion() throws IOException, Error, XPathExpres
919991 String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/no_issuer_assertion.xml.base64" );
920992 SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
921993
994+ samlResponse .getResponseIssuer (); // this should not fail
922995 expectedEx .expect (ValidationError .class );
923996 expectedEx .expectMessage ("Issuer of the Assertion not found or multiple." );
924997 samlResponse .getIssuers ();
925998 }
926-
999+
9271000 /**
9281001 * Tests the getSessionIndex method of SamlResponse
9291002 *
@@ -1811,8 +1884,7 @@ public void testIsInValidIssuer() throws IOException, Error, XPathExpressionExce
18111884 settings .setStrict (true );
18121885 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
18131886 assertFalse (samlResponse .isValid ());
1814- assertEquals ("No Signature found. SAML Response rejected" , samlResponse .getError ());
1815-
1887+ assertEquals ("Invalid issuer in the Assertion/Response. Was 'http://invalid.isser.example.com/', but expected 'http://idp.example.com/'" , samlResponse .getError ());
18161888 }
18171889
18181890 /**
0 commit comments