15
15
*/
16
16
package org .owasp .esapi .reference ;
17
17
18
- import static org .junit .Assert .assertEquals ;
19
18
import static org .junit .Assert .assertNotEquals ;
20
19
21
20
import java .io .IOException ;
22
21
import java .io .UnsupportedEncodingException ;
23
22
import java .net .URI ;
24
- import java .util .List ;
25
23
import java .util .ArrayList ;
26
24
import 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 ;
32
26
27
+ import org .junit .Ignore ;
33
28
import org .owasp .esapi .ESAPI ;
34
29
import org .owasp .esapi .Encoder ;
35
30
import org .owasp .esapi .EncoderConstants ;
36
- import org .owasp .esapi .codecs .CSSCodec ;
31
+ import org .owasp .esapi .SecurityConfiguration ;
32
+ import org .owasp .esapi .SecurityConfigurationWrapper ;
37
33
import org .owasp .esapi .codecs .Codec ;
38
34
import org .owasp .esapi .codecs .HTMLEntityCodec ;
39
35
import org .owasp .esapi .codecs .MySQLCodec ;
43
39
import org .owasp .esapi .codecs .WindowsCodec ;
44
40
import org .owasp .esapi .errors .EncodingException ;
45
41
import org .owasp .esapi .errors .IntrusionException ;
46
- import org .owasp .esapi .SecurityConfiguration ;
47
- import org .owasp .esapi .SecurityConfigurationWrapper ;
48
42
49
43
import junit .framework .Test ;
50
44
import junit .framework .TestCase ;
@@ -678,6 +672,7 @@ public void testDecodeFromURL() throws Exception {
678
672
fail ();
679
673
}
680
674
try {
675
+ //FIXME: Rewrite this to use expected Exceptions.
681
676
instance .decodeFromURL ( "%3xridiculous" );
682
677
fail ();
683
678
} catch ( Exception e ) {
@@ -916,6 +911,50 @@ public void testGetCanonicalizedUri() throws Exception {
916
911
assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
917
912
918
913
}
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
+ }
919
958
920
959
public void testGetCanonicalizedUriPiazza () throws Exception {
921
960
System .out .println ("getCanonicalizedUriPiazza" );
@@ -931,6 +970,41 @@ public void testGetCanonicalizedUriPiazza() throws Exception {
931
970
assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
932
971
933
972
}
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
+ }
934
1008
935
1009
public void testGetCanonicalizedUriWithMailto () throws Exception {
936
1010
System .out .println ("getCanonicalizedUriWithMailto" );
0 commit comments