|
4 | 4 | */
|
5 | 5 | package org.hibernate.validator.test.internal.constraintvalidators.hv;
|
6 | 6 |
|
| 7 | +import static org.assertj.core.api.Assertions.assertThat; |
7 | 8 | import static org.testng.Assert.assertFalse;
|
8 | 9 | import static org.testng.Assert.assertTrue;
|
9 | 10 | import static org.testng.Assert.fail;
|
@@ -287,5 +288,121 @@ public void validOnlyIfConfiguredVariantMatches() {
|
287 | 288 |
|
288 | 289 | }
|
289 | 290 |
|
| 291 | + @Test |
| 292 | + public void versionNotInTheAllowedList() { |
| 293 | + char[] versions = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; |
| 294 | + |
| 295 | + for ( int i = 0; i < versions.length; i++ ) { |
| 296 | + int version = Character.digit( versions[i], 16 ); |
| 297 | + descriptorBuilder.setAttribute( "version", new int[] { version } ); |
| 298 | + |
| 299 | + uuidAnnotation = descriptorBuilder.build().getAnnotation(); |
| 300 | + uuidValidator.initialize( uuidAnnotation ); |
| 301 | + |
| 302 | + for ( int j = 0; j < versions.length; j++ ) { |
| 303 | + if ( i == j ) { |
| 304 | + continue; |
| 305 | + } |
| 306 | + String uuid = "24e6abaa-b2a8-%sa8e-0622-92adaaae229f".formatted( versions[j] ); |
| 307 | + assertThat( uuidValidator.isValid( uuid, null ) ) |
| 308 | + .as( "Expected uuid %s to be invalid because of the version %s not being allowed", uuid, versions[j] ) |
| 309 | + .isFalse(); |
| 310 | + } |
| 311 | + } |
| 312 | + } |
| 313 | + |
| 314 | + @Test |
| 315 | + public void variantNotInTheAllowedLis11t() { |
| 316 | + descriptorBuilder.setAttribute( "variant", new int[] { 1 } ); |
| 317 | + |
| 318 | + uuidAnnotation = descriptorBuilder.build().getAnnotation(); |
| 319 | + uuidValidator.initialize( uuidAnnotation ); |
| 320 | + |
| 321 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-c622-92adaaae229f", null ) ); |
| 322 | + } |
| 323 | + |
| 324 | + @Test |
| 325 | + public void variantNotInTheAllowedList() { |
| 326 | + // 0xxx 0 - 7 reserved (NCS backward compatible) |
| 327 | + // 10xx 8 - b DCE 1.1, ISO/IEC 11578:1996 |
| 328 | + // 110x c - d reserved (Microsoft GUID) |
| 329 | + // 1110 e reserved (future use) |
| 330 | + // 1111 f unknown / invalid. Must end with "0" |
| 331 | + |
| 332 | + descriptorBuilder.setAttribute( "variant", new int[] { 0 } ); |
| 333 | + |
| 334 | + uuidAnnotation = descriptorBuilder.build().getAnnotation(); |
| 335 | + uuidValidator.initialize( uuidAnnotation ); |
| 336 | + |
| 337 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-0622-92adaaae229f", null ) ); |
| 338 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-1622-92adaaae229f", null ) ); |
| 339 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-2622-92adaaae229f", null ) ); |
| 340 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-3622-92adaaae229f", null ) ); |
| 341 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-4622-92adaaae229f", null ) ); |
| 342 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-5622-92adaaae229f", null ) ); |
| 343 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-6622-92adaaae229f", null ) ); |
| 344 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-7622-92adaaae229f", null ) ); |
| 345 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-8622-92adaaae229f", null ) ); |
| 346 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-9622-92adaaae229f", null ) ); |
| 347 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-a622-92adaaae229f", null ) ); |
| 348 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-b622-92adaaae229f", null ) ); |
| 349 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-c622-92adaaae229f", null ) ); |
| 350 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-d622-92adaaae229f", null ) ); |
| 351 | + // Next two variants are always invalid as they are currently "undefined": |
| 352 | + // 1110 e |
| 353 | + // 1111 f |
| 354 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-e622-92adaaae229f", null ) ); |
| 355 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-f622-92adaaae229f", null ) ); |
| 356 | + |
| 357 | + descriptorBuilder.setAttribute( "variant", new int[] { 1 } ); |
| 358 | + |
| 359 | + uuidAnnotation = descriptorBuilder.build().getAnnotation(); |
| 360 | + uuidValidator.initialize( uuidAnnotation ); |
290 | 361 |
|
| 362 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-0622-92adaaae229f", null ) ); |
| 363 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-1622-92adaaae229f", null ) ); |
| 364 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-2622-92adaaae229f", null ) ); |
| 365 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-3622-92adaaae229f", null ) ); |
| 366 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-4622-92adaaae229f", null ) ); |
| 367 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-5622-92adaaae229f", null ) ); |
| 368 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-6622-92adaaae229f", null ) ); |
| 369 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-7622-92adaaae229f", null ) ); |
| 370 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-8622-92adaaae229f", null ) ); |
| 371 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-9622-92adaaae229f", null ) ); |
| 372 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-a622-92adaaae229f", null ) ); |
| 373 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-b622-92adaaae229f", null ) ); |
| 374 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-c622-92adaaae229f", null ) ); |
| 375 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-d622-92adaaae229f", null ) ); |
| 376 | + // Next two variants are always invalid as they are currently "undefined": |
| 377 | + // 1110 e |
| 378 | + // 1111 f |
| 379 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-e622-92adaaae229f", null ) ); |
| 380 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-f622-92adaaae229f", null ) ); |
| 381 | + |
| 382 | + descriptorBuilder.setAttribute( "variant", new int[] { 2 } ); |
| 383 | + |
| 384 | + uuidAnnotation = descriptorBuilder.build().getAnnotation(); |
| 385 | + uuidValidator.initialize( uuidAnnotation ); |
| 386 | + |
| 387 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-0622-92adaaae229f", null ) ); |
| 388 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-1622-92adaaae229f", null ) ); |
| 389 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-2622-92adaaae229f", null ) ); |
| 390 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-3622-92adaaae229f", null ) ); |
| 391 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-4622-92adaaae229f", null ) ); |
| 392 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-5622-92adaaae229f", null ) ); |
| 393 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-6622-92adaaae229f", null ) ); |
| 394 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-7622-92adaaae229f", null ) ); |
| 395 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-8622-92adaaae229f", null ) ); |
| 396 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-9622-92adaaae229f", null ) ); |
| 397 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-a622-92adaaae229f", null ) ); |
| 398 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-b622-92adaaae229f", null ) ); |
| 399 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-c622-92adaaae229f", null ) ); |
| 400 | + assertTrue( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-d622-92adaaae229f", null ) ); |
| 401 | + // Next two variants are always invalid as they are currently "undefined": |
| 402 | + // 1110 e |
| 403 | + // 1111 f |
| 404 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-e622-92adaaae229f", null ) ); |
| 405 | + assertFalse( uuidValidator.isValid( "24e6abaa-b2a8-4a8e-f622-92adaaae229f", null ) ); |
| 406 | + |
| 407 | + } |
291 | 408 | }
|
0 commit comments