@@ -822,7 +822,7 @@ public void testGetAudiences() throws IOException, Error, XPathExpressionExcepti
822822 }
823823
824824 /**
825- * Tests the getIssuers method of SamlResponse
825+ * Tests the getIssuers methods of SamlResponse
826826 *
827827 * @throws Error
828828 * @throws IOException
@@ -837,46 +837,61 @@ public void testGetAudiences() throws IOException, Error, XPathExpressionExcepti
837837 @ Test
838838 public void testGetIssuers () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
839839 Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
840- String samlResponseEncoded = Util .getFileAsString ("data/responses/response1 .xml.base64" );
840+ String samlResponseEncoded = Util .getFileAsString ("data/responses/valid_encrypted_assertion .xml.base64" );
841841 SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
842+ String expectedIssuer = "http://idp.example.com/" ;
842843 List <String > expectedIssuers = new ArrayList <String >();
843- expectedIssuers .add ("http://idp.example.com/" );
844- samlResponseEncoded = Util . getFileAsString ( "data/responses/valid_encrypted_assertion.xml.base64" );
845- samlResponse = new SamlResponse ( settings , newHttpRequest ( samlResponseEncoded ));
844+ expectedIssuers .add (expectedIssuer );
845+ assertEquals ( expectedIssuer , samlResponse . getResponseIssuer () );
846+ assertEquals ( expectedIssuer , samlResponse . getAssertionIssuer ( ));
846847 assertEquals (expectedIssuers , samlResponse .getIssuers ());
847848
848849 expectedIssuers .remove (0 );
849- expectedIssuers .add ("https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php" );
850+ expectedIssuer = "https://pitbulk.no-ip.org/simplesaml/saml2/idp/metadata.php" ;
851+ expectedIssuers .add (expectedIssuer );
850852
851853 samlResponseEncoded = Util .getFileAsString ("data/responses/signed_message_encrypted_assertion.xml.base64" );
852854 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
855+ assertEquals (expectedIssuer , samlResponse .getResponseIssuer ());
856+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
853857 assertEquals (expectedIssuers , samlResponse .getIssuers ());
854858
855859 samlResponseEncoded = Util .getFileAsString ("data/responses/double_signed_encrypted_assertion.xml.base64" );
856860 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
861+ assertEquals (expectedIssuer , samlResponse .getResponseIssuer ());
862+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
857863 assertEquals (expectedIssuers , samlResponse .getIssuers ());
858864
859865 samlResponseEncoded = Util .getFileAsString ("data/responses/signed_encrypted_assertion.xml.base64" );
860866 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
867+ assertEquals (expectedIssuer , samlResponse .getResponseIssuer ());
868+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
861869 assertEquals (expectedIssuers , samlResponse .getIssuers ());
862870
863871 samlResponseEncoded = Util .getFileAsString ("data/responses/double_signed_response.xml.base64" );
864872 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
873+ assertEquals (expectedIssuer , samlResponse .getResponseIssuer ());
874+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
865875 assertEquals (expectedIssuers , samlResponse .getIssuers ());
866876
867877 samlResponseEncoded = Util .getFileAsString ("data/responses/signed_assertion_response.xml.base64" );
868878 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
879+ assertEquals (expectedIssuer , samlResponse .getResponseIssuer ());
880+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
869881 assertEquals (expectedIssuers , samlResponse .getIssuers ());
870882
883+ expectedIssuer = "https://app.onelogin.com/saml/metadata/13590" ;
871884 expectedIssuers = new ArrayList <String >();
872- expectedIssuers .add ("https://app.onelogin.com/saml/metadata/13590" );
885+ expectedIssuers .add (expectedIssuer );
873886 samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/no_issuer_response.xml.base64" );
874887 samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
888+ assertNull (expectedIssuer , samlResponse .getResponseIssuer ());
889+ assertEquals (expectedIssuer , samlResponse .getAssertionIssuer ());
875890 assertEquals (expectedIssuers , samlResponse .getIssuers ());
876891 }
877892
878893 /**
879- * Tests the getIssuers method of SamlResponse
894+ * Tests the getIssuers methods of SamlResponse
880895 * <p>
881896 * Case: different issuers for response and assertion
882897 *
@@ -896,13 +911,44 @@ public void testGetIssuersDifferentIssuers() throws IOException, Error, XPathExp
896911 String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/different_issuers.xml.base64" );
897912 SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
898913 List <String > expectedIssuers = new ArrayList <String >();
899- expectedIssuers .add ("https://response-issuer.com" );
900- expectedIssuers .add ("https://assertion-issuer.com" );
914+ String expectedResponseIssuer = "https://response-issuer.com" ;
915+ String expectedAssertionIssuer = "https://assertion-issuer.com" ;
916+ expectedIssuers .add (expectedResponseIssuer );
917+ expectedIssuers .add (expectedAssertionIssuer );
918+ assertEquals (expectedResponseIssuer , samlResponse .getResponseIssuer ());
919+ assertEquals (expectedAssertionIssuer , samlResponse .getAssertionIssuer ());
901920 assertEquals (expectedIssuers , samlResponse .getIssuers ());
902921 }
903922
904923 /**
905- * Tests the getIssuers method of SamlResponse
924+ * Tests the getAssertionIssuer method of SamlResponse
925+ * <p>
926+ * Case: Issuer of the assertion not found
927+ *
928+ * @throws Error
929+ * @throws IOException
930+ * @throws ValidationError
931+ * @throws SettingsException
932+ * @throws SAXException
933+ * @throws ParserConfigurationException
934+ * @throws XPathExpressionException
935+ *
936+ * @see com.onelogin.saml2.authn.SamlResponse#getIssuers
937+ */
938+ @ Test
939+ public void testGetAssertionIssuerNoInAssertion () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
940+ Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
941+ String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/no_issuer_assertion.xml.base64" );
942+ SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
943+
944+ expectedEx .expect (ValidationError .class );
945+ expectedEx .expectMessage ("Issuer of the Assertion not found or multiple." );
946+ samlResponse .getAssertionIssuer ();
947+ }
948+
949+ /**
950+ * Tests the getIssuers methods of SamlResponse
951+ * <p>
906952 * Case: Issuer of the assertion not found
907953 *
908954 * @throws Error
@@ -921,11 +967,12 @@ public void testGetIssuersNoInAssertion() throws IOException, Error, XPathExpres
921967 String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/no_issuer_assertion.xml.base64" );
922968 SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
923969
970+ samlResponse .getResponseIssuer (); // this should not fail
924971 expectedEx .expect (ValidationError .class );
925972 expectedEx .expectMessage ("Issuer of the Assertion not found or multiple." );
926973 samlResponse .getIssuers ();
927974 }
928-
975+
929976 /**
930977 * Tests the getSessionIndex method of SamlResponse
931978 *
0 commit comments