2929
3030import java .io .IOException ;
3131import java .util .ArrayList ;
32+ import java .util .Arrays ;
3233import java .util .HashMap ;
3334import java .util .List ;
3435import java .util .Map ;
@@ -890,6 +891,86 @@ public void testGetAudiences() throws IOException, Error, XPathExpressionExcepti
890891 assertEquals (expectedAudiences , samlResponse .getAudiences ());
891892 }
892893
894+ /**
895+ * Tests the getResponseIssuer method of SamlResponse
896+ * <p>
897+ * Case: with or without trimming
898+ *
899+ * @throws Error
900+ * @throws IOException
901+ * @throws ValidationError
902+ * @throws SettingsException
903+ * @throws SAXException
904+ * @throws ParserConfigurationException
905+ * @throws XPathExpressionException
906+ *
907+ * @see com.onelogin.saml2.authn.SamlResponse#getIssuers
908+ */
909+ @ Test
910+ public void testGetResponseIssuerTrimming () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
911+ // disabled by now
912+ Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
913+ String samlResponseEncoded = Util .getFileAsString ("data/responses/response3_with_whitespace.xml.base64" );
914+ SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
915+ assertEquals ("\n \t http://example.com/services/trust\n " , samlResponse .getResponseIssuer ());
916+ settings .setTrimNameIds (true );
917+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
918+ assertEquals ("http://example.com/services/trust" , samlResponse .getResponseIssuer ());
919+ }
920+
921+ /**
922+ * Tests the getAssertionIssuer method of SamlResponse
923+ * <p>
924+ * Case: Issuer of the assertion not found
925+ *
926+ * @throws Error
927+ * @throws IOException
928+ * @throws ValidationError
929+ * @throws SettingsException
930+ * @throws SAXException
931+ * @throws ParserConfigurationException
932+ * @throws XPathExpressionException
933+ *
934+ * @see com.onelogin.saml2.authn.SamlResponse#getIssuers
935+ */
936+ @ Test
937+ public void testGetAssertionIssuerNoInAssertion () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
938+ Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
939+ String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/no_issuer_assertion.xml.base64" );
940+ SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
941+
942+ expectedEx .expect (ValidationError .class );
943+ expectedEx .expectMessage ("Issuer of the Assertion not found or multiple." );
944+ samlResponse .getAssertionIssuer ();
945+ }
946+
947+ /**
948+ * Tests the getAssertionIssuer method of SamlResponse
949+ * <p>
950+ * Case: with or without trimming
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 testGetAssertionIssuerTrimming () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
964+ // disabled by now
965+ Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
966+ String samlResponseEncoded = Util .getFileAsString ("data/responses/response3_with_whitespace.xml.base64" );
967+ SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
968+ assertEquals ("\n \t http://example.com/services/trust\n " , samlResponse .getAssertionIssuer ());
969+ settings .setTrimNameIds (true );
970+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
971+ assertEquals ("http://example.com/services/trust" , samlResponse .getAssertionIssuer ());
972+ }
973+
893974 /**
894975 * Tests the getIssuers methods of SamlResponse
895976 *
@@ -990,8 +1071,7 @@ public void testGetIssuersDifferentIssuers() throws IOException, Error, XPathExp
9901071 }
9911072
9921073 /**
993- * Tests the getAssertionIssuer method of SamlResponse
994- * <p>
1074+ * Tests the getIssuers method of SamlResponse
9951075 * Case: Issuer of the assertion not found
9961076 *
9971077 * @throws Error
@@ -1005,14 +1085,15 @@ public void testGetIssuersDifferentIssuers() throws IOException, Error, XPathExp
10051085 * @see com.onelogin.saml2.authn.SamlResponse#getIssuers
10061086 */
10071087 @ Test
1008- public void testGetAssertionIssuerNoInAssertion () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
1088+ public void testGetIssuersNoInAssertion () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
10091089 Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
10101090 String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/no_issuer_assertion.xml.base64" );
10111091 SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
10121092
1093+ samlResponse .getResponseIssuer (); // this should not fail
10131094 expectedEx .expect (ValidationError .class );
10141095 expectedEx .expectMessage ("Issuer of the Assertion not found or multiple." );
1015- samlResponse .getAssertionIssuer ();
1096+ samlResponse .getIssuers ();
10161097 }
10171098
10181099 /**
@@ -1033,39 +1114,13 @@ public void testGetAssertionIssuerNoInAssertion() throws IOException, Error, XPa
10331114 @ Test
10341115 public void testGetIssuersTrimming () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
10351116 // disabled by now
1036- // Saml2Settings settings = new SettingsBuilder().fromFile("config/config.my.properties").build();
1037- // String samlResponseEncoded = Util.getFileAsString("data/responses/response3_with_whitespace.xml.base64");
1038- // SamlResponse samlResponse = new SamlResponse(settings, newHttpRequest(samlResponseEncoded));
1039- // assertEquals(Arrays.asList("\n \thttp://example.com/services/trust\n ", "\n \thttp://example.com/services/trust\n "), samlResponse.getIssuers());
1040- // settings.setTrimNameIds(true);
1041- // samlResponse = new SamlResponse(settings, newHttpRequest(samlResponseEncoded));
1042- // assertEquals(Arrays.asList("http://example.com/services/trust"), samlResponse.getIssuers());
1043- }
1044-
1045- /**
1046- * Tests the getIssuers method of SamlResponse
1047- * Case: Issuer of the assertion not found
1048- *
1049- * @throws Error
1050- * @throws IOException
1051- * @throws ValidationError
1052- * @throws SettingsException
1053- * @throws SAXException
1054- * @throws ParserConfigurationException
1055- * @throws XPathExpressionException
1056- *
1057- * @see com.onelogin.saml2.authn.SamlResponse#getIssuers
1058- */
1059- @ Test
1060- public void testGetIssuersNoInAssertion () throws IOException , Error , XPathExpressionException , ParserConfigurationException , SAXException , SettingsException , ValidationError {
10611117 Saml2Settings settings = new SettingsBuilder ().fromFile ("config/config.my.properties" ).build ();
1062- String samlResponseEncoded = Util .getFileAsString ("data/responses/invalids/no_issuer_assertion .xml.base64" );
1118+ String samlResponseEncoded = Util .getFileAsString ("data/responses/response3_with_whitespace .xml.base64" );
10631119 SamlResponse samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
1064-
1065- samlResponse .getResponseIssuer (); // this should not fail
1066- expectedEx .expect (ValidationError .class );
1067- expectedEx .expectMessage ("Issuer of the Assertion not found or multiple." );
1068- samlResponse .getIssuers ();
1120+ assertEquals (Arrays .asList ("\n \t http://example.com/services/trust\n " , "\n \t http://example.com/services/trust\n " ), samlResponse .getIssuers ());
1121+ settings .setTrimNameIds (true );
1122+ samlResponse = new SamlResponse (settings , newHttpRequest (samlResponseEncoded ));
1123+ assertEquals (Arrays .asList ("http://example.com/services/trust" ), samlResponse .getIssuers ());
10691124 }
10701125
10711126 /**
0 commit comments