@Test public void testIsFileLocatedInDirectorySymbolicLinkNok() throws IOException { //symlinks work only on unix Assume.assumeTrue (isUnix()); Path f2 = Paths.get(FileUtils.getTempDirectoryPath(), "test.txt"); Files.createFile(f2); Path symlink = Paths.get(dir.toString(), "symlink.txt"); //We create a symbolic link inside of the permitted folder pointing to a file outside of the permitted folder. This should be failing. Files.createSymbolicLink(symlink, f2); Assert.assertFalse(fileLoader.isFileLocatedInDirectory(dir, symlink)); Files.delete(symlink); Files.delete(f2); }
@Test public void testIsFileLocatedInDirectorySymbolicLinkOk() throws IOException { //symlinks work only on unix Assume.assumeTrue (isUnix()); Path symlink = Paths.get(dir.toString(), "symlink.txt"); //We create a symbolic link inside of the permitted folder pointing to a file inside of the permitted folder. This should be ok. Files.createSymbolicLink(symlink, f); Assert.assertTrue(fileLoader.isFileLocatedInDirectory(dir, symlink)); Files.delete(symlink); }
@Test public void testIsFileLocatedInDirectorySymbolicLinkFromOutsideOk() throws IOException { //symlinks work only on unix Assume.assumeTrue (isUnix()); Path symlink = Paths.get(FileUtils.getTempDirectoryPath(), "symlink.txt"); //TODO check: is this statement true? I can't think of any harm this could do... //We create a symbolic link outside of the permitted folder pointing to a file inside of the permitted folder. This should be ok as well. Files.createSymbolicLink(symlink, f); Assert.assertTrue(fileLoader.isFileLocatedInDirectory(dir, symlink)); Files.delete(symlink); }