From 9799746d24d1baf1143206c20b830ea9a1da567d Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 22 Oct 2023 17:59:47 -0700 Subject: [PATCH] Add directory permission tests for HDFS --- .../hdfs/TestHdfsFileSystemHdfs.java | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/trino-hdfs/src/test/java/io/trino/filesystem/hdfs/TestHdfsFileSystemHdfs.java b/lib/trino-hdfs/src/test/java/io/trino/filesystem/hdfs/TestHdfsFileSystemHdfs.java index 59dc57c2c2eb1..8a98509c611db 100644 --- a/lib/trino-hdfs/src/test/java/io/trino/filesystem/hdfs/TestHdfsFileSystemHdfs.java +++ b/lib/trino-hdfs/src/test/java/io/trino/filesystem/hdfs/TestHdfsFileSystemHdfs.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.UncheckedIOException; @@ -42,6 +43,7 @@ public class TestHdfsFileSystemHdfs extends AbstractTestTrinoFileSystem { private Hadoop hadoop; + private HdfsConfiguration hdfsConfiguration; private HdfsEnvironment hdfsEnvironment; private HdfsContext hdfsContext; private TrinoFileSystem fileSystem; @@ -53,7 +55,7 @@ void beforeAll() hadoop.start(); HdfsConfig hdfsConfig = new HdfsConfig(); - HdfsConfiguration hdfsConfiguration = new DynamicHdfsConfiguration(new HdfsConfigurationInitializer(hdfsConfig), emptySet()); + hdfsConfiguration = new DynamicHdfsConfiguration(new HdfsConfigurationInitializer(hdfsConfig), emptySet()); hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, hdfsConfig, new NoHdfsAuthentication()); hdfsContext = new HdfsContext(ConnectorIdentity.ofUser("test")); @@ -107,4 +109,33 @@ protected void verifyFileSystemIsEmpty() throw new UncheckedIOException(e); } } + + @Test + void testCreateDirectoryPermission() + throws IOException + { + assertCreateDirectoryPermission(fileSystem, hdfsEnvironment, (short) 777); + } + + @Test + void testCreateDirectoryPermissionWithSkip() + throws IOException + { + HdfsConfig configWithSkip = new HdfsConfig() + .setNewDirectoryPermissions(HdfsConfig.SKIP_DIR_PERMISSIONS); + HdfsEnvironment hdfsEnvironment = new HdfsEnvironment(hdfsConfiguration, configWithSkip, new NoHdfsAuthentication()); + TrinoFileSystem fileSystem = new HdfsFileSystem(hdfsEnvironment, hdfsContext, new TrinoHdfsFileSystemStats()); + + assertCreateDirectoryPermission(fileSystem, hdfsEnvironment, (short) 755); + } + + private void assertCreateDirectoryPermission(TrinoFileSystem fileSystem, HdfsEnvironment hdfsEnvironment, short permission) + throws IOException + { + Location location = getRootLocation().appendPath("test"); + fileSystem.createDirectory(location); + Path path = new Path(location.toString()); + FileStatus status = hdfsEnvironment.getFileSystem(hdfsContext, path).getFileStatus(path); + assertThat(status.getPermission().toOctal()).isEqualTo(permission); + } }