|
40 | 40 | import org.example.domain.NestedDataUnwrappedAction; |
41 | 41 | import org.example.domain.User; |
42 | 42 | import org.example.domain.UserField; |
| 43 | +import org.primeframework.mvc.MockConfiguration; |
43 | 44 | import org.primeframework.mvc.PrimeBaseTest; |
44 | 45 | import org.primeframework.mvc.parameter.convert.ConverterStateException; |
45 | 46 | import org.slf4j.Logger; |
@@ -307,59 +308,35 @@ public void fuzzing() { |
307 | 308 | public void maximumParameterCollectionIndex() { |
308 | 309 | ActionField action = new ActionField(); |
309 | 310 | action.user = new UserField(); |
310 | | - configuration.collectionSizeLimit = 100; |
311 | 311 |
|
312 | 312 | try { |
313 | | - // Exceeds the limit on an existing list — triggers IndexedCollectionAccessor.pad() |
314 | | - try { |
315 | | - evaluator.setValue("names[101]", action, ArrayUtils.toArray("test"), null); |
316 | | - fail("Expected an [InvalidCollectionSizeException] exception."); |
317 | | - } catch (InvalidCollectionSizeException e) { |
318 | | - assertEquals(e.resultCode, "input"); |
319 | | - } |
320 | | - |
321 | | - // Exceeds the limit on a null array — triggers Accessor.createValue() |
322 | | - action.user.securityQuestions = null; |
323 | | - try { |
324 | | - evaluator.setValue("user.securityQuestions[999]", action, ArrayUtils.toArray("test"), null); |
325 | | - fail("Expected an [InvalidCollectionSizeException] exception."); |
326 | | - } catch (InvalidCollectionSizeException e) { |
327 | | - assertEquals(e.resultCode, "input"); |
328 | | - } |
| 313 | + evaluator.setValue("names[101]", action, ArrayUtils.toArray("test"), null); |
| 314 | + fail("Expected an [InvalidCollectionSizeException] exception."); |
| 315 | + } catch (InvalidCollectionSizeException e) { |
| 316 | + assertEquals(e.resultCode, "input"); |
| 317 | + } |
329 | 318 |
|
330 | | - // Within the limit works normally |
331 | | - evaluator.setValue("user.siblings[0].name", action, ArrayUtils.toArray("Brett"), null); |
332 | | - assertEquals(action.user.siblings.size(), 1); |
333 | | - assertEquals(action.user.siblings.getFirst().name, "Brett"); |
334 | | - |
335 | | - // Exactly at the limit works |
336 | | - action.user.securityQuestions = null; |
337 | | - evaluator.setValue("user.securityQuestions[99]", action, ArrayUtils.toArray("question"), null); |
338 | | - assertEquals(action.user.securityQuestions.length, 100); |
339 | | - assertEquals(action.user.securityQuestions[99], "question"); |
340 | | - assertNull(action.user.securityQuestions[0]); |
341 | | - assertNull(action.user.securityQuestions[50]); |
342 | | - |
343 | | - // No limit (-1) allows any index |
344 | | - configuration.collectionSizeLimit = -1; |
345 | | - action.user.securityQuestions = null; |
346 | | - evaluator.setValue("user.securityQuestions[500]", action, ArrayUtils.toArray("question"), null); |
347 | | - assertEquals(action.user.securityQuestions.length, 501); |
348 | | - assertEquals(action.user.securityQuestions[500], "question"); |
349 | | - assertNull(action.user.securityQuestions[0]); |
350 | | - assertNull(action.user.securityQuestions[499]); |
351 | | - |
352 | | - // Negative index is rejected regardless of the configured limit |
353 | | - configuration.collectionSizeLimit = 100; |
354 | | - try { |
355 | | - evaluator.setValue("names[-1]", action, ArrayUtils.toArray("test"), null); |
356 | | - fail("Expected an [InvalidCollectionSizeException] exception."); |
357 | | - } catch (InvalidCollectionSizeException e) { |
358 | | - assertEquals(e.resultCode, "input"); |
359 | | - } |
360 | | - } finally { |
361 | | - configuration.collectionSizeLimit = -1; |
| 319 | + // Exceeds the limit on a null array — triggers Accessor.createValue() |
| 320 | + action.user.securityQuestions = null; |
| 321 | + try { |
| 322 | + evaluator.setValue("user.securityQuestions[999]", action, ArrayUtils.toArray("test"), null); |
| 323 | + fail("Expected an [InvalidCollectionSizeException] exception."); |
| 324 | + } catch (InvalidCollectionSizeException e) { |
| 325 | + assertEquals(e.resultCode, "input"); |
362 | 326 | } |
| 327 | + |
| 328 | + // Within the limit works normally |
| 329 | + evaluator.setValue("user.siblings[0].name", action, ArrayUtils.toArray("Brett"), null); |
| 330 | + assertEquals(action.user.siblings.size(), 1); |
| 331 | + assertEquals(action.user.siblings.getFirst().name, "Brett"); |
| 332 | + |
| 333 | + // Exactly at the limit works |
| 334 | + action.user.securityQuestions = null; |
| 335 | + evaluator.setValue("user.securityQuestions[9]", action, ArrayUtils.toArray("question"), null); |
| 336 | + assertEquals(action.user.securityQuestions.length, 10); |
| 337 | + assertEquals(action.user.securityQuestions[9], "question"); |
| 338 | + assertNull(action.user.securityQuestions[0]); |
| 339 | + assertNull(action.user.securityQuestions[8]); |
363 | 340 | } |
364 | 341 |
|
365 | 342 | @Test |
|
0 commit comments