|
19 | 19 | import org.hamcrest.CoreMatchers; |
20 | 20 | import org.hamcrest.MatcherAssert; |
21 | 21 | import org.junit.jupiter.api.Assertions; |
| 22 | +import org.junit.jupiter.api.Assumptions; |
22 | 23 | import org.junit.jupiter.api.BeforeEach; |
23 | 24 | import org.junit.jupiter.api.DisplayName; |
24 | 25 | import org.junit.jupiter.api.Nested; |
@@ -367,6 +368,50 @@ public void setup() throws IOException { |
367 | 368 | when(openCryptoFile.newFileChannel(any())).thenReturn(fileChannel); |
368 | 369 | } |
369 | 370 |
|
| 371 | + @Nested |
| 372 | + public class LimitedCleartextNameLength { |
| 373 | + |
| 374 | + @BeforeEach |
| 375 | + public void setup() throws IOException { |
| 376 | + Assumptions.assumeTrue(cleartextPath.getFileName().toString().length() == 9); |
| 377 | + } |
| 378 | + |
| 379 | + @Test |
| 380 | + @DisplayName("read-only always works") |
| 381 | + public void testNewFileChannelReadOnlyDespiteMaxName() throws IOException { |
| 382 | + Mockito.doReturn(0).when(fileSystemProperties).maxCleartextNameLength(); |
| 383 | + |
| 384 | + FileChannel ch = inTest.newFileChannel(cleartextPath, EnumSet.of(StandardOpenOption.READ)); |
| 385 | + |
| 386 | + Assertions.assertSame(fileChannel, ch); |
| 387 | + verify(readonlyFlag, Mockito.never()).assertWritable(); |
| 388 | + } |
| 389 | + |
| 390 | + @Test |
| 391 | + @DisplayName("create new fails when exceeding limit") |
| 392 | + public void testNewFileChannelCreate1() { |
| 393 | + Mockito.doReturn(0).when(fileSystemProperties).maxCleartextNameLength(); |
| 394 | + |
| 395 | + Assertions.assertThrows(FileNameTooLongException.class, () -> { |
| 396 | + inTest.newFileChannel(cleartextPath, EnumSet.of(StandardOpenOption.WRITE, StandardOpenOption.CREATE)); |
| 397 | + }); |
| 398 | + |
| 399 | + verifyNoInteractions(openCryptoFiles); |
| 400 | + } |
| 401 | + |
| 402 | + @Test |
| 403 | + @DisplayName("create new succeeds when within limit") |
| 404 | + public void testNewFileChannelCreate2() throws IOException { |
| 405 | + Mockito.doReturn(10).when(fileSystemProperties).maxCleartextNameLength(); |
| 406 | + |
| 407 | + FileChannel ch = inTest.newFileChannel(cleartextPath, EnumSet.of(StandardOpenOption.READ)); |
| 408 | + |
| 409 | + Assertions.assertSame(fileChannel, ch); |
| 410 | + verify(readonlyFlag, Mockito.never()).assertWritable(); |
| 411 | + } |
| 412 | + |
| 413 | + } |
| 414 | + |
370 | 415 | @Test |
371 | 416 | @DisplayName("newFileChannel read-only") |
372 | 417 | public void testNewFileChannelReadOnly() throws IOException { |
|
0 commit comments