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 ;
45
41
import org .owasp .esapi .errors .EncodingException ;
46
42
import org .owasp .esapi .errors .IntrusionException ;
47
43
import org .owasp .esapi .Randomizer ;
48
- import org .owasp .esapi .SecurityConfiguration ;
49
- import org .owasp .esapi .SecurityConfigurationWrapper ;
44
+
50
45
51
46
import junit .framework .Test ;
52
47
import junit .framework .TestCase ;
@@ -747,6 +742,7 @@ public void testDecodeFromURL() throws Exception {
747
742
fail ();
748
743
}
749
744
try {
745
+ //FIXME: Rewrite this to use expected Exceptions.
750
746
instance .decodeFromURL ( "%3xridiculous" );
751
747
fail ();
752
748
} catch ( Exception e ) {
@@ -985,6 +981,50 @@ public void testGetCanonicalizedUri() throws Exception {
985
981
assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
986
982
987
983
}
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
+ }
988
1028
989
1029
public void testGetCanonicalizedUriPiazza () throws Exception {
990
1030
System .out .println ("getCanonicalizedUriPiazza" );
@@ -1000,6 +1040,41 @@ public void testGetCanonicalizedUriPiazza() throws Exception {
1000
1040
assertEquals (expectedUri , e .getCanonicalizedURI (uri ));
1001
1041
1002
1042
}
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
+ }
1003
1078
1004
1079
public void testGetCanonicalizedUriWithMailto () throws Exception {
1005
1080
System .out .println ("getCanonicalizedUriWithMailto" );
0 commit comments