10
10
/**
11
11
* Extension of the AbstractPatternTest which focuses on asserting that the default whitelist regex values applied in
12
12
* the validation process are performing the intended function in the environment.
13
- *
14
13
* <br/>
15
- *
16
14
* If the regex values in this test are found to not match the running environment configurations, then the tests will
17
15
* be skipped.
18
16
*
19
17
* @author Jeremiah
20
18
* @since Jan 20, 2018
21
19
*/
22
20
public class EsapiWhitelistValidationPatternTester extends AbstractPatternTest {
23
- //See ESAPI.properties
24
- private static final String HTTP_QUERY_STRING_PROP_NAME ="HTTPQueryString" ;
25
- private static final String HTTP_QUERY_STRING_REGEX ="^([a-zA-Z0-9_\\ -]{1,32}=[\\ p{L}\\ p{N}.\\ -/+=_ !$*?@%]*&?)*$" ;
21
+ // See ESAPI.properties
22
+ private static final String HTTP_QUERY_STRING_PROP_NAME = "HTTPQueryString" ;
23
+ private static final String HTTP_QUERY_STRING_REGEX = "^([a-zA-Z0-9_\\ -]{1,32}=[\\ p{L}\\ p{N}.\\ -/+=_ !$*?@%]*&?)*$" ;
24
+
25
+ private static final String CONFIGURATION_PATTERN_MISMATCH_MESSAGE = "The regular expression specified does not match the configuration settings.\n "
26
+ + "If the value was changed from the ESAPI default, it is recommended to copy "
27
+ + "this class into your project, update the regex being tested, and update all "
28
+ + "associated input expectations for your unique environment." ;
26
29
27
30
@ Parameters (name = "{0}-{1}" )
28
31
public static Collection <Object []> createDefaultPatternTests () {
29
32
Collection <Object []> parameters = new ArrayList <>();
30
-
31
- for (PatternTestTuple tuple : buildHttpQueryStringTests ()) {
33
+
34
+ for (PatternTestTuple tuple : buildHttpQueryStringTests ()) {
32
35
parameters .add (new Object [] { HTTP_QUERY_STRING_PROP_NAME , tuple });
33
36
}
34
37
35
-
36
38
return parameters ;
37
39
}
38
-
40
+
39
41
private static Collection <PatternTestTuple > buildHttpQueryStringTests () {
40
- Collection <PatternTestTuple > httpQueryStringTests = new ArrayList <>();
41
-
42
- //MATCHING CASES
42
+ Collection <PatternTestTuple > httpQueryStringTests = new ArrayList <>();
43
+
44
+ // MATCHING CASES
43
45
PatternTestTuple tuple = newHttpQueryStringTuple ("Default Case" , "b" , true );
44
46
httpQueryStringTests .add (tuple );
45
47
tuple = newHttpQueryStringTuple ("Percent Encoded Value" , "%62" , true );
@@ -48,27 +50,27 @@ private static Collection<PatternTestTuple> buildHttpQueryStringTests() {
48
50
httpQueryStringTests .add (tuple );
49
51
tuple = newHttpQueryStringTuple ("Double Equals" , "=" , true );
50
52
httpQueryStringTests .add (tuple );
51
-
52
- //NON-MATCHING CASES
53
+
54
+ // NON-MATCHING CASES
53
55
tuple = newHttpQueryStringTuple ("Ampersand In Value" , "&b" , false );
54
56
httpQueryStringTests .add (tuple );
55
- tuple = newHttpQueryStringTuple ("Null Character" , "" + Character .MIN_VALUE , false );
57
+ tuple = newHttpQueryStringTuple ("Null Character" , "" + Character .MIN_VALUE , false );
56
58
httpQueryStringTests .add (tuple );
57
59
tuple = newHttpQueryStringTuple ("Encoded Null Character" , "\u0000 " , false );
58
60
httpQueryStringTests .add (tuple );
59
-
61
+
60
62
return httpQueryStringTests ;
61
63
}
62
64
63
65
private static PatternTestTuple newHttpQueryStringTuple (String description , String value , boolean shouldPass ) {
64
66
PatternTestTuple tuple = new PatternTestTuple ();
65
- tuple .input = "a=" + value ;
67
+ tuple .input = "a=" + value ;
66
68
tuple .shouldMatch = shouldPass ;
67
69
tuple .regex = HTTP_QUERY_STRING_REGEX ;
68
70
tuple .description = description ;
69
71
return tuple ;
70
72
}
71
-
73
+
72
74
public EsapiWhitelistValidationPatternTester (String property , PatternTestTuple tuple ) {
73
75
super (tuple );
74
76
/*
@@ -80,12 +82,8 @@ public EsapiWhitelistValidationPatternTester(String property, PatternTestTuple t
80
82
* behavior.
81
83
*/
82
84
DefaultSecurityConfiguration configuration = new DefaultSecurityConfiguration ();
83
- Assume .assumeTrue (
84
- "The regular expression specified does not match the configuration settings.\n "
85
- + "If the value was changed from the ESAPI default, it is recommended to copy "
86
- + "this class into your project, update the regex being tested, and update all "
87
- + "associated input expectations for your unique environment." ,
88
- configuration .getValidationPattern (property ).toString ().equals (tuple .regex ));
85
+ Assume .assumeTrue (CONFIGURATION_PATTERN_MISMATCH_MESSAGE , configuration .getValidationPattern (property )
86
+ .toString ().equals (tuple .regex ));
89
87
}
90
88
91
89
}
0 commit comments