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 ;
4339import org .owasp .esapi .codecs .WindowsCodec ;
4440import org .owasp .esapi .errors .EncodingException ;
4541import org .owasp .esapi .errors .IntrusionException ;
46- import org .owasp .esapi .SecurityConfiguration ;
47- import org .owasp .esapi .SecurityConfigurationWrapper ;
4842
4943import junit .framework .Test ;
5044import junit .framework .TestCase ;
@@ -678,6 +672,7 @@ public void testDecodeFromURL() throws Exception {
678672 fail ();
679673 }
680674 try {
675+ //FIXME: Rewrite this to use expected Exceptions.
681676 instance .decodeFromURL ( "%3xridiculous" );
682677 fail ();
683678 } catch ( Exception e ) {
@@ -916,6 +911,50 @@ public void testGetCanonicalizedUri() throws Exception {
916911 assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
917912
918913 }
914+
915+ public void testGetCanonicalizedUriWithAnHTMLEntityCollision () throws Exception {
916+ System .out .println ("GetCanonicalizedUriWithAnHTMLEntityCollision" );
917+ Encoder e = ESAPI .encoder ();
918+
919+ String expectedUri =
"http://[email protected] /path_to/resource?foo=bar¶1=test" ;
920+ //Please note that section 3.2.1 of RFC-3986 explicitly states not to encode
921+ //password information as in http://palpatine:[email protected] , and this will 922+ //not appear in the userinfo field.
923+ String input =
"http://[email protected] /path_to/resource?foo=bar¶1=test" ;
924+ URI uri = new URI (input );
925+ System .out .println (uri .toString ());
926+ assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
927+
928+ }
929+
930+ @ org .junit .Ignore ("Pre-check in unit test for issue #826" )
931+ public void Issue826GetCanonicalizedUriWithMultipleEncoding () throws Exception {
932+ System .out .println ("GetCanonicalizedUriWithAnHTMLEntityCollision" );
933+ Encoder e = ESAPI .encoder ();
934+ String expectedUri =
"http://[email protected] /path_to/resource?foo=bar¶1=&test" ;
935+ //Please note that section 3.2.1 of RFC-3986 explicitly states not to encode
936+ //password information as in http://palpatine:[email protected] , and this will 937+ //not appear in the userinfo field.
938+ String input =
"http://[email protected] /path_to/resource?foo=bar¶1=&test" ;
939+ URI uri = new URI (input );
940+ System .out .println (uri .toString ());
941+ assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
942+
943+ }
944+ public void testGetCanonicalizedUriWithMultQueryParams () throws Exception {
945+ System .out .println ("getCanonicalizedUri" );
946+ Encoder e = ESAPI .encoder ();
947+
948+ String expectedUri = "http://palpatine@foo bar.com/path_to/resource?foo=bar&bar=foo#frag" ;
949+ //Please note that section 3.2.1 of RFC-3986 explicitly states not to encode
950+ //password information as in http://palpatine:[email protected] , and this will 951+ //not appear in the userinfo field.
952+ String input = "http://palpatine@foo%20bar.com/path_to/resource?foo=bar&bar=foo#frag" ;
953+ URI uri = new URI (input );
954+ System .out .println (uri .toString ());
955+ assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
956+
957+ }
919958
920959 public void testGetCanonicalizedUriPiazza () throws Exception {
921960 System .out .println ("getCanonicalizedUriPiazza" );
@@ -931,6 +970,41 @@ public void testGetCanonicalizedUriPiazza() throws Exception {
931970 assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
932971
933972 }
973+
974+ public void testIssue824 () throws Exception {
975+ System .out .println ("getCanonicalizedUriPiazza" );
976+ Encoder e = ESAPI .encoder ();
977+
978+ String expectedUri = "/webapp/ux/home?d=1705914006565&status=login&ticket=1705914090394_HzJpTROVfhW-JhRW0OqDbHu7tWXXlgrKSUmOzIMsZNCcUIiYGMXX_Q==&newsess=false&roleid=DP010101/0007&origin=ourprogram" ;
979+ //Please note that section 3.2.1 of RFC-3986 explicitly states not to encode
980+ //password information as in http://palpatine:[email protected] , and this will 981+ //not appear in the userinfo field.
982+ String input = "/webapp/ux/home?d=1705914006565&status=login&ticket=1705914090394_HzJpTROVfhW-JhRW0OqDbHu7tWXXlgrKSUmOzIMsZNCcUIiYGMXX_Q%3D%3D&newsess=false&roleid=DP010101/0007&origin=ourprogram" ;
983+ URI uri = new URI (input );
984+ System .out .println (uri .toString ());
985+ assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
986+
987+ }
988+
989+ @ org .junit .Ignore ("Pre-check in unit test for issue #826" )
990+ public void Issue826GetCanonicalizedDoubleAmpersand () throws Exception {
991+ System .out .println ("getCanonicalizedDoubleAmpersand" );
992+ Encoder e = ESAPI .encoder ();
993+ String expectedUri = "http://127.0.0.1:3000/campaigns?goal=all§ion=active&sort-by=-id&status=Draft%2C&html=&contentLaunched" ;
994+ //http://127.0.0.1:3000/campaigns?goal=all§ion=active&sort-by=-id&status=Draft,&html=null&=null&contentLaunched=null
995+ /*
996+ * In this case, the URI class should break up the HTML entity in the query so
997+ */
998+ String input = "http://127.0.0.1:3000/campaigns?goal=all§ion=active&sort-by=-id&status=Draft%2C&html=&&contentLaunched" ;
999+ URI uri = new URI (input );
1000+ System .out .println (uri .toString ());
1001+ try {
1002+ assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
1003+ fail ();
1004+ } catch (Exception ex ) {
1005+ //Expected
1006+ }
1007+ }
9341008
9351009 public void testGetCanonicalizedUriWithMailto () throws Exception {
9361010 System .out .println ("getCanonicalizedUriWithMailto" );
0 commit comments