Skip to content

Commit bbfdf57

Browse files
committed
Added test: Replace an existing, shortened symlink
1 parent 26a9138 commit bbfdf57

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/test/java/org/cryptomator/cryptofs/CryptoFileSystemProviderIntegrationTest.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,50 @@ public void testReplaceExistingShortenedDirEmpty() throws IOException {
647647
}
648648
}*/
649649

650+
/* //TODO https://github.com/cryptomator/cryptofs/issues/177
651+
@Test
652+
@DisplayName("Replace an existing, shortened symlink")
653+
public void testReplaceExistingShortenedSymlink() throws IOException {
654+
try (var fs = setupCryptoFs(50, 100, false)) {
655+
var source = fs.getPath("/sourceDir");
656+
var linkedFromSource = fs.getPath("/linkedFromSource.txt");
657+
var linkedFromSourceContent = "linkedFromSourceContent!";
658+
659+
var targetName50Chars = "/target_89_123456789_123456789_123456789_123456789_"; //since filename encryption increases filename length, 50 cleartext chars are sufficient
660+
var target = fs.getPath(targetName50Chars);
661+
var linkedFromTarget = fs.getPath("/linkedFromTarget.txt");
662+
var linkedFromTargetContent = "linkedFromTargeContent!";
663+
664+
Files.createFile(linkedFromSource);
665+
Files.writeString(linkedFromSource, linkedFromSourceContent, UTF_8);
666+
Files.createFile(linkedFromTarget);
667+
Files.writeString(linkedFromTarget, linkedFromTargetContent, UTF_8);
668+
669+
Files.createSymbolicLink(source, linkedFromSource);
670+
Files.createSymbolicLink(target, linkedFromTarget);
671+
672+
Assertions.assertDoesNotThrow(() -> Files.move(source, target, REPLACE_EXISTING));
673+
Assertions.assertTrue(Files.notExists(source));
674+
Assertions.assertTrue(Files.exists(target));
675+
676+
//Assert linked files haven't been changed
677+
Assertions.assertTrue(Files.exists(linkedFromSource));
678+
Assertions.assertEquals(Files.readString(linkedFromSource, UTF_8), linkedFromSourceContent);
679+
Assertions.assertFalse(Files.isSymbolicLink(linkedFromSource));
680+
Assertions.assertTrue(Files.isRegularFile(linkedFromSource, LinkOption.NOFOLLOW_LINKS));
681+
682+
Assertions.assertTrue(Files.exists(linkedFromTarget));
683+
Assertions.assertEquals(Files.readString(linkedFromTarget, UTF_8), linkedFromTargetContent);
684+
Assertions.assertFalse(Files.isSymbolicLink(linkedFromTarget));
685+
Assertions.assertTrue(Files.isRegularFile(linkedFromTarget, LinkOption.NOFOLLOW_LINKS));
686+
687+
//Assert link is correct
688+
Assertions.assertTrue(Files.isSymbolicLink(target));
689+
Assertions.assertTrue(Files.isRegularFile(target /* FOLLOW_LINKS *<remove this when enabling test>/));
690+
Assertions.assertEquals(Files.readSymbolicLink(target), linkedFromSource);
691+
}
692+
}*/
693+
650694
private FileSystem setupCryptoFs(int ciphertextShorteningThreshold, int maxCleartextFilename, boolean readonly) throws IOException {
651695
byte[] key = new byte[64];
652696
Arrays.fill(key, (byte) 0x55);

0 commit comments

Comments
 (0)