我正在使用gitlab ci和image从源代码构建apache flink java:8u111-jdk
,并发现对文件权限的测试失败,因为不尊重文件权限。
其中一个单元测试如下:
@Test
public void testDeleteDirectory() throws Exception {
// deleting a non-existent file should not cause an error
File doesNotExist = new File(tmp.newFolder(), "abc");
FileUtils.deleteDirectory(doesNotExist);
// deleting a write protected file should throw an error
File cannotDeleteParent = tmp.newFolder();
File cannotDeleteChild = new File(cannotDeleteParent, "child");
try {
assumeTrue(cannotDeleteChild.createNewFile());
assumeTrue(cannotDeleteParent.setWritable(false));
assumeTrue(cannotDeleteChild.setWritable(false));
FileUtils.deleteDirectory(cannotDeleteParent);
fail("this should fail with an exception");
}
catch (AccessDeniedException ignored) {
// this is expected
}
finally {
//noinspection ResultOfMethodCallIgnored
cannotDeleteParent.setWritable(true);
//noinspection ResultOfMethodCallIgnored
cannotDeleteChild.setWritable(true);
}
}
试验结果为:
testDeleteDirectory(org.apache.flink.util.FileUtilsTest) Time elapsed: 0.022 sec <<< FAILURE!
java.lang.AssertionError: this should fail with an exception
at org.junit.Assert.fail(Assert.java:88)
at org.apache.flink.util.FileUtilsTest.testDeleteDirectory(FileUtilsTest.java:129)
当我深入研究代码时,我发现下面的语句 java.io.File
:
在某些平台上,可以使用允许修改不允许写操作的文件的特权来启动java虚拟机。
所以我怀疑是ci环境出了问题。如何进一步调试问题?谢谢!
环境:
docker图像:java:8u111-jdk
操作系统内核:linux 4.9.0-8-amd64 x86\U 64
发行:debian 8
jdk版本:openjdk 1.8.0\u 111
1条答案
按热度按时间wmvff8tz1#
问题是,我们以root用户身份运行此代码,因此可以删除受写保护的文件。