1717import java .util .regex .Pattern ;
1818
1919import org .hamcrest .core .Is ;
20+ import org .junit .After ;
2021import org .junit .Before ;
2122import org .junit .Rule ;
2223import org .junit .Test ;
@@ -66,10 +67,6 @@ public class DefaultValidatorInputStringAPITest {
6667
6768 @ Before
6869 public void setup () throws Exception {
69- //Is intrusion detection disabled? A: Yes, it is off.
70- //This logic is confusing: True, the value is False...
71- when (mockSecConfig .getDisableIntrusionDetection ()).thenReturn (true );
72-
7370 contextStr = testName .getMethodName ();
7471 testValidatorType = testName .getMethodName () + "_validator_type" ;
7572 validatorResultString = testName .getMethodName () + "_validator_result" ;
@@ -101,6 +98,13 @@ public void setup() throws Exception {
10198
10299 }
103100
101+ @ After
102+ public void verifyDelegateCalls () {
103+ verify (mockSecConfig , times (1 )).getValidationPattern (testValidatorType );
104+
105+ PowerMockito .verifyNoMoreInteractions (spyStringRule , mockSecConfig , mockEncoder );
106+ }
107+
104108 @ Test
105109 public void getValidInputNullAllowedPassthrough () throws Exception {
106110 String safeValue = uit .getValidInput (contextStr , testName .getMethodName (), testValidatorType , testMaximumLength , true );
@@ -109,6 +113,7 @@ public void getValidInputNullAllowedPassthrough() throws Exception {
109113 verify (spyStringRule , times (1 )).setAllowNull (true );
110114 verify (spyStringRule , times (0 )).setAllowNull (false );
111115 verify (spyStringRule , times (1 )).setMaximumLength (testMaximumLength );
116+ verify (spyStringRule , times (1 )).setCanonicalize (true );
112117 verify (spyStringRule , times (1 )).getValid (contextStr , testName .getMethodName ());
113118 }
114119
@@ -120,6 +125,7 @@ public void getValidInputNullNotAllowedPassthrough() throws Exception {
120125 verify (spyStringRule , times (0 )).setAllowNull (true );
121126 verify (spyStringRule , times (1 )).setAllowNull (false );
122127 verify (spyStringRule , times (1 )).setMaximumLength (testMaximumLength );
128+ verify (spyStringRule , times (1 )).setCanonicalize (true );
123129 verify (spyStringRule , times (1 )).getValid (contextStr , testName .getMethodName ());
124130 }
125131
@@ -137,7 +143,16 @@ public void getValidInputValidationExceptionPropagates() throws Exception {
137143 exEx .expect (Is .is (validationEx ));
138144
139145 doThrow (validationEx ).when (spyStringRule ).getValid (ArgumentMatchers .anyString (), ArgumentMatchers .anyString ());
140- uit .getValidInput (contextStr , testName .getMethodName (), testValidatorType , testMaximumLength , true );
146+ try {
147+ uit .getValidInput (contextStr , testName .getMethodName (), testValidatorType , testMaximumLength , true );
148+ } finally {
149+ verify (spyStringRule , times (1 )).addWhitelistPattern (TEST_PATTERN );
150+ verify (spyStringRule , times (1 )).setAllowNull (true );
151+ verify (spyStringRule , times (0 )).setAllowNull (false );
152+ verify (spyStringRule , times (1 )).setMaximumLength (testMaximumLength );
153+ verify (spyStringRule , times (1 )).setCanonicalize (true );
154+ verify (spyStringRule , times (1 )).getValid (contextStr , testName .getMethodName ());
155+ }
141156 }
142157
143158 @ Test
@@ -149,6 +164,12 @@ public void getValidInputValidationExceptionErrorList() throws Exception {
149164 assertTrue (result .isEmpty ());
150165 assertEquals (1 , errorList .size ());
151166 assertEquals (validationEx , errorList .getError (contextStr ));
167+ verify (spyStringRule , times (1 )).addWhitelistPattern (TEST_PATTERN );
168+ verify (spyStringRule , times (1 )).setAllowNull (true );
169+ verify (spyStringRule , times (0 )).setAllowNull (false );
170+ verify (spyStringRule , times (1 )).setMaximumLength (testMaximumLength );
171+ verify (spyStringRule , times (1 )).setCanonicalize (true );
172+ verify (spyStringRule , times (1 )).getValid (contextStr , testName .getMethodName ());
152173 }
153174
154175
@@ -161,6 +182,7 @@ public void isValidInputNullAllowedPassthrough() throws Exception {
161182 verify (spyStringRule , times (1 )).setAllowNull (true );
162183 verify (spyStringRule , times (0 )).setAllowNull (false );
163184 verify (spyStringRule , times (1 )).setMaximumLength (testMaximumLength );
185+ verify (spyStringRule , times (1 )).setCanonicalize (true );
164186 verify (spyStringRule , times (1 )).getValid (contextStr , testName .getMethodName ());
165187 }
166188
@@ -169,6 +191,12 @@ public void isValidInputValidationExceptionReturnsFalse() throws Exception {
169191 doThrow (validationEx ).when (spyStringRule ).getValid (ArgumentMatchers .anyString (), ArgumentMatchers .anyString ());
170192 boolean result = uit .isValidInput (contextStr , testName .getMethodName (), testValidatorType , testMaximumLength , true );
171193 assertFalse (result );
194+ verify (spyStringRule , times (1 )).addWhitelistPattern (TEST_PATTERN );
195+ verify (spyStringRule , times (1 )).setAllowNull (true );
196+ verify (spyStringRule , times (0 )).setAllowNull (false );
197+ verify (spyStringRule , times (1 )).setMaximumLength (testMaximumLength );
198+ verify (spyStringRule , times (1 )).setCanonicalize (true );
199+ verify (spyStringRule , times (1 )).getValid (contextStr , testName .getMethodName ());
172200 }
173201
174202 @ Test
@@ -180,5 +208,24 @@ public void isValidInputValidationExceptionErrorListReturnsFalse() throws Except
180208 assertFalse (result );
181209 assertEquals (1 , errorList .size ());
182210 assertEquals (validationEx , errorList .getError (contextStr ));
211+ verify (errors , times (1 )).addError (contextStr , validationEx );
212+ verify (spyStringRule , times (1 )).addWhitelistPattern (TEST_PATTERN );
213+ verify (spyStringRule , times (1 )).setAllowNull (true );
214+ verify (spyStringRule , times (0 )).setAllowNull (false );
215+ verify (spyStringRule , times (1 )).setMaximumLength (testMaximumLength );
216+ verify (spyStringRule , times (1 )).setCanonicalize (true );
217+ verify (spyStringRule , times (1 )).getValid (contextStr , testName .getMethodName ());
218+ }
219+
220+ @ Test
221+ public void canonicalizeSettingPassedThrough () throws Exception {
222+ String safeValue = uit .getValidInput (contextStr , testName .getMethodName (), testValidatorType , testMaximumLength , false ,false );
223+ assertEquals (validatorResultString , safeValue );
224+ verify (spyStringRule , times (1 )).addWhitelistPattern (TEST_PATTERN );
225+ verify (spyStringRule , times (0 )).setAllowNull (true );
226+ verify (spyStringRule , times (1 )).setAllowNull (false );
227+ verify (spyStringRule , times (1 )).setMaximumLength (testMaximumLength );
228+ verify (spyStringRule , times (1 )).setCanonicalize (false );
229+ verify (spyStringRule , times (1 )).getValid (contextStr , testName .getMethodName ());
183230 }
184231}
0 commit comments