1515 */
1616package org .owasp .esapi .reference ;
1717
18- import static org .junit .Assert .assertEquals ;
1918import static org .junit .Assert .assertNotEquals ;
2019
2120import java .io .IOException ;
2221import java .io .UnsupportedEncodingException ;
2322import java .net .URI ;
24- import java .util .List ;
2523import java .util .ArrayList ;
2624import java .util .Arrays ;
27- import java .util .HashMap ;
28- import java .util .Map ;
29- import java .util .Map .Entry ;
30- import java .util .regex .Matcher ;
31- import java .util .regex .Pattern ;
25+ import java .util .List ;
3226
27+ import org .junit .Ignore ;
3328import org .owasp .esapi .ESAPI ;
3429import org .owasp .esapi .Encoder ;
3530import org .owasp .esapi .EncoderConstants ;
36- import org .owasp .esapi .codecs .CSSCodec ;
31+ import org .owasp .esapi .SecurityConfiguration ;
32+ import org .owasp .esapi .SecurityConfigurationWrapper ;
3733import org .owasp .esapi .codecs .Codec ;
3834import org .owasp .esapi .codecs .HTMLEntityCodec ;
3935import org .owasp .esapi .codecs .MySQLCodec ;
4541import org .owasp .esapi .errors .EncodingException ;
4642import org .owasp .esapi .errors .IntrusionException ;
4743import org .owasp .esapi .Randomizer ;
48- import org .owasp .esapi .SecurityConfiguration ;
49- import org .owasp .esapi .SecurityConfigurationWrapper ;
44+
5045
5146import junit .framework .Test ;
5247import junit .framework .TestCase ;
@@ -747,6 +742,7 @@ public void testDecodeFromURL() throws Exception {
747742 fail ();
748743 }
749744 try {
745+ //FIXME: Rewrite this to use expected Exceptions.
750746 instance .decodeFromURL ( "%3xridiculous" );
751747 fail ();
752748 } catch ( Exception e ) {
@@ -985,6 +981,50 @@ public void testGetCanonicalizedUri() throws Exception {
985981 assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
986982
987983 }
984+
985+ public void testGetCanonicalizedUriWithAnHTMLEntityCollision () throws Exception {
986+ System .out .println ("GetCanonicalizedUriWithAnHTMLEntityCollision" );
987+ Encoder e = ESAPI .encoder ();
988+
989+ String expectedUri =
"http://[email protected] /path_to/resource?foo=bar¶1=test" ;
990+ //Please note that section 3.2.1 of RFC-3986 explicitly states not to encode
991+ //password information as in http://palpatine:[email protected] , and this will 992+ //not appear in the userinfo field.
993+ String input =
"http://[email protected] /path_to/resource?foo=bar¶1=test" ;
994+ URI uri = new URI (input );
995+ System .out .println (uri .toString ());
996+ assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
997+
998+ }
999+
1000+ @ org .junit .Ignore ("Pre-check in unit test for issue #826" )
1001+ public void Issue826GetCanonicalizedUriWithMultipleEncoding () throws Exception {
1002+ System .out .println ("GetCanonicalizedUriWithAnHTMLEntityCollision" );
1003+ Encoder e = ESAPI .encoder ();
1004+ String expectedUri =
"http://[email protected] /path_to/resource?foo=bar¶1=&test" ;
1005+ //Please note that section 3.2.1 of RFC-3986 explicitly states not to encode
1006+ //password information as in http://palpatine:[email protected] , and this will 1007+ //not appear in the userinfo field.
1008+ String input =
"http://[email protected] /path_to/resource?foo=bar¶1=&test" ;
1009+ URI uri = new URI (input );
1010+ System .out .println (uri .toString ());
1011+ assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
1012+
1013+ }
1014+ public void testGetCanonicalizedUriWithMultQueryParams () throws Exception {
1015+ System .out .println ("getCanonicalizedUri" );
1016+ Encoder e = ESAPI .encoder ();
1017+
1018+ String expectedUri = "http://palpatine@foo bar.com/path_to/resource?foo=bar&bar=foo#frag" ;
1019+ //Please note that section 3.2.1 of RFC-3986 explicitly states not to encode
1020+ //password information as in http://palpatine:[email protected] , and this will 1021+ //not appear in the userinfo field.
1022+ String input = "http://palpatine@foo%20bar.com/path_to/resource?foo=bar&bar=foo#frag" ;
1023+ URI uri = new URI (input );
1024+ System .out .println (uri .toString ());
1025+ assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
1026+
1027+ }
9881028
9891029 public void testGetCanonicalizedUriPiazza () throws Exception {
9901030 System .out .println ("getCanonicalizedUriPiazza" );
@@ -1000,6 +1040,41 @@ public void testGetCanonicalizedUriPiazza() throws Exception {
10001040 assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
10011041
10021042 }
1043+
1044+ public void testIssue824 () throws Exception {
1045+ System .out .println ("getCanonicalizedUriPiazza" );
1046+ Encoder e = ESAPI .encoder ();
1047+
1048+ String expectedUri = "/webapp/ux/home?d=1705914006565&status=login&ticket=1705914090394_HzJpTROVfhW-JhRW0OqDbHu7tWXXlgrKSUmOzIMsZNCcUIiYGMXX_Q==&newsess=false&roleid=DP010101/0007&origin=ourprogram" ;
1049+ //Please note that section 3.2.1 of RFC-3986 explicitly states not to encode
1050+ //password information as in http://palpatine:[email protected] , and this will 1051+ //not appear in the userinfo field.
1052+ String input = "/webapp/ux/home?d=1705914006565&status=login&ticket=1705914090394_HzJpTROVfhW-JhRW0OqDbHu7tWXXlgrKSUmOzIMsZNCcUIiYGMXX_Q%3D%3D&newsess=false&roleid=DP010101/0007&origin=ourprogram" ;
1053+ URI uri = new URI (input );
1054+ System .out .println (uri .toString ());
1055+ assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
1056+
1057+ }
1058+
1059+ @ org .junit .Ignore ("Pre-check in unit test for issue #826" )
1060+ public void Issue826GetCanonicalizedDoubleAmpersand () throws Exception {
1061+ System .out .println ("getCanonicalizedDoubleAmpersand" );
1062+ Encoder e = ESAPI .encoder ();
1063+ String expectedUri = "http://127.0.0.1:3000/campaigns?goal=all§ion=active&sort-by=-id&status=Draft%2C&html=&contentLaunched" ;
1064+ //http://127.0.0.1:3000/campaigns?goal=all§ion=active&sort-by=-id&status=Draft,&html=null&=null&contentLaunched=null
1065+ /*
1066+ * In this case, the URI class should break up the HTML entity in the query so
1067+ */
1068+ String input = "http://127.0.0.1:3000/campaigns?goal=all§ion=active&sort-by=-id&status=Draft%2C&html=&&contentLaunched" ;
1069+ URI uri = new URI (input );
1070+ System .out .println (uri .toString ());
1071+ try {
1072+ assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
1073+ fail ();
1074+ } catch (Exception ex ) {
1075+ //Expected
1076+ }
1077+ }
10031078
10041079 public void testGetCanonicalizedUriWithMailto () throws Exception {
10051080 System .out .println ("getCanonicalizedUriWithMailto" );
0 commit comments