Commit bba046e
Date validation rule 299 (#468)
* DateValidationRule Logic Updates
Updating the parsing logic of the DateValidationRule to not only verify a
date can be constructed from the input string in a known format, but also
that the generated Date can be reformatted back to the same String
content. This adds additional security for cases where the DateFormatter
accepts characters postfixed to an otherwise valid date.
As a result two tests in ValidationTest.java had to be updated to use the
correct explicit format. The data sets were using full-name month, day,
year content, but supplying the MEDIUM format. Updating the provided
format to LONG allowed the new check to function as desired.
* DateValidationRule Test Content
Adding test cases presented in the github issue
* Dependency Cleanup: JodaTime
Removing JodaTime dependency from Pom. It had been introduced to
potentially address date/time parsing issues, but had not yet been applied
to the baseline.
* DateValidationRule Test Content
Updating test to actually use assertions in execution so that the intended
state is verified.
* DateValidationRule Test Content
Adding additional test case content.
* Validation Test Cleanup
Converting ValidationErrorList Test to use Junit4 syntax.
* Validation Test Cleanup
Updating assertions used in ValidationErrorList for more information in
Junit test failure cases.
* Validation Test Cleanup
Breaking the exception cases of the ValidationErrorListTest into separate
test blocks. Updated to use the ExpectedException Rule.
Corrected wording in implementation error message on null context.
Corrected message in implementation on null ValidationException reference.
* Validation Test Cleanup
Test updates to use class-scope references rather than on a per-test
basis.
Removed method to create ValidationException. Catch block indicated that
a specific exception had been thrown at one point. I checked the call
heirarchy and verified that exception is not being explicitly thrown at
this time.
* Validation Test Cleanup
ValidationErrorListTest:
Removed sysouts
Cleaned unused imports
Formatted file (removed tab chars & adjusted indent)
* Validation Test Cleanup BaseValidationRuleTest
Converting test to Junit4 Syntax.
* Validation Test Cleanup: BaseValidationRuleTest
Commenting out the current test. Upon inspection, the test is not fulfilling the commented intent. Instead of validating that the BaseValidationRule throws exceptions, it is only verifying that the test-scope stub implementation throws. Going to keep it around so I can verify I'm fulfilling the intent in the new implementation content before deleting that code
* Validation Test Cleanup: BaseValidationRuleTest
Re-implementing the tests for BaseValidationRule.
** This commit contains a failing test (testWhitelistSetExtendedCharacterSets)**
I do not know how to test utf-16 character sets, but I think it is something that needs to be done.
I have listed a concern with potential side-effects of using ValidationErrorList in the BaseValidationRule. Refer to testGetValidMultipleExceptionSameContextThrowsRuntimeException for more information.
* Validation Test Cleanup: DateValidationRuleTest
Initial basic tests for general class functionality.
* Validation Test Cleanup: DateValidationRuleTest
Adding validations to ensure that DateFormat leniency is being set in accordance with the SecurityConfiguration ACCEPT_LENIENT_DATES value.
Still light in the context that I'm not verifying the value is derived from the SecurityConfiguration, but I am at least checking that the date format is being updated and that the value being applied matches the test-scope settings.
* DateValidationRule Logic & Test Updates
Updating the implementation so the process of generating a String from the parsed date and comparing it with the canonicalized input only happens during the sanitize workflow. This will allow for the DateFormat contract for leniency and ESAPI's contract for security to remain intact (I think).
In essence, getValid is asking if the configured DateFormat can parse any date out of String being provided. That's completely on the DateFormat instance. If it works then return it, if it doesn't the throw the ValidationException.
On the other hand, sanitize is asking for a safe representation of the String. For that we can add the additional cross check and be more stringent in the criteria. Meaning if the same String that was used to generate the Date cannot be recreated from that date then we don't trust the input.
Tests were updated to reflect this workflow, and the data set used to check 299 in the ValidatorTest has been integrated into DateValidationRuleTest.
* Validation Test Updates: BaseValidationRuleTest
Ignoring the explictly fail case in the test.
* DateValidation Corrections for DefaultValidator
Adding another sanitize method to the DateValidationRule which accepts the ValidationErrorList in addition to the other parameters.
Updating DefaultValidator to use the new sanitize method and check the error list to verify the returned date before passing it along to the client. If there are no errors, we're gtg; otherwise, the ValidationError at the first index is rethrown.
* DateValidationTest API Extension
Adding tests for new sanitize API method.
* DefaultValidator Date Validation Logic Update
Altering method chaining to defer to the getValidDate which uses the ValidationErrorList which now contains the delegation to the DateValidationRule.
* DefaultValidator Date API Testing
Creating a new test class that focuses on testing the DATE API of
DefaultValidator.
This is a wireframe commit.
* DefaultValidator Date API Testing
Successful interception of the DateValidatorRule construction. When
DefaultValidator instantiates a new instance internally, it receives the
test-scope spy.
This will allow us to check that the intended workflow of how the
DefaultValidator delegates to the DateValidatorRule is operating as
expected without needing to re-test the conditions already verified in the
DateValidatorRuleTest.
* DefaultValidator Logic Update & Date API Tests
Working tests to verify happy-path workflow through DefaultValidator Date
API.
Logic update to isValidDate with ValidationErrorList to use the
ValidationErrorList that is passed in with the delegated
DateValidationRule.sanitize call.
* DefaultValidator Date API Negative Tests
Verifying workflow and response from the DateAPI when the
DateValidationRule would result in a ValidationException being thrown.
* DefaultValidator Date API Test Cleanup
No functional changes. Mostly updating static imports and references.
* DefaultValidator cleanup
Fixing inconsistent indentation in updated method block.
* ValidatorTest Cleanup :: New ESAPI API Test
Created a new test for the static ESAPI class which verifies the workflow by which the runtime Validator is derived.
Removed the date validity tests from the ValidatorTest. All pertinent content has been divided into the BaseValidationRuleTest, DateValidationRuleTest, ValidationErrorListTest, DefaultValidatorDateAPITest, and ESAPIContractAPITests.
The specific conditions have been shifted to be exclusively against the implementation (BaseValidationRuleTest). It is shown that the DefaultValidator uses BaseValidationRule in all date-related checks (DefaultValidatorDateAPITest). And we know that if the user configures the ESAPI validator property to the DefaultValidator it will resolve at runtime (ESAPIContractAPITests).
* DateValdationRuleTest Additions
Adding Powermock tests that show the lenient setting is derived from the
SecurityConfiguration and is applied to the DateFormat reference both when
a DateValidationRule is constructed, and when the setDateFormat method is
invoked.
I chose to implement this as a unique test since PowermockRunner impacts my ability to see code coverage.
* BaseValidationRuleTest UTF-16 Whitelist Addition
Replacing ignore/fail of test impl with content showing that extended
character sets can be whitelisted through the implementation.1 parent 48cb2ad commit bba046e
File tree
11 files changed
+1044
-295
lines changed- src
- main/java/org/owasp/esapi
- reference
- validation
- test/java/org/owasp/esapi
- reference
- validation
11 files changed
+1044
-295
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | 132 | | |
139 | 133 | | |
140 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | | - | |
| 94 | + | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
Lines changed: 20 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
| 280 | + | |
| 281 | + | |
287 | 282 | | |
288 | 283 | | |
289 | 284 | | |
290 | 285 | | |
291 | 286 | | |
292 | 287 | | |
293 | | - | |
294 | | - | |
295 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
296 | 297 | | |
297 | 298 | | |
298 | 299 | | |
299 | 300 | | |
300 | 301 | | |
301 | 302 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
309 | 312 | | |
310 | 313 | | |
311 | 314 | | |
| |||
Lines changed: 29 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | | - | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 74 | + | |
80 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
81 | 91 | | |
82 | | - | |
| 92 | + | |
83 | 93 | | |
84 | 94 | | |
85 | 95 | | |
| |||
91 | 101 | | |
92 | 102 | | |
93 | 103 | | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
98 | 114 | | |
99 | 115 | | |
100 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
Lines changed: 57 additions & 107 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
23 | 27 | | |
24 | 28 | | |
| 29 | + | |
25 | 30 | | |
26 | 31 | | |
27 | 32 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
48 | 38 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
57 | 47 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
92 | 60 | | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
100 | 66 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
109 | 73 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
118 | 80 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
127 | 87 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | 88 | | |
139 | 89 | | |
140 | 90 | | |
0 commit comments