|
@@ -17,13 +17,17 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.fs;
|
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.fail;
|
|
|
+
|
|
|
+import java.net.URI;
|
|
|
+
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
+import org.apache.hadoop.fs.permission.FsPermission;
|
|
|
import org.junit.Test;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-import static org.junit.Assert.fail;
|
|
|
-
|
|
|
public class TestFileContext {
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(TestFileContext
|
|
|
.class);
|
|
@@ -39,4 +43,40 @@ public class TestFileContext {
|
|
|
LOG.info("Expected exception: ", ufse);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testConfBasedAndAPIBasedSetUMask() throws Exception {
|
|
|
+
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+
|
|
|
+ String defaultlUMask =
|
|
|
+ conf.get(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY);
|
|
|
+ assertEquals("Default UMask changed!", "022", defaultlUMask);
|
|
|
+
|
|
|
+ URI uri1 = new URI("file://mydfs:50070/");
|
|
|
+ URI uri2 = new URI("file://tmp");
|
|
|
+
|
|
|
+ FileContext fc1 = FileContext.getFileContext(uri1, conf);
|
|
|
+ FileContext fc2 = FileContext.getFileContext(uri2, conf);
|
|
|
+ assertEquals("Umask for fc1 is incorrect", 022, fc1.getUMask().toShort());
|
|
|
+ assertEquals("Umask for fc2 is incorrect", 022, fc2.getUMask().toShort());
|
|
|
+
|
|
|
+ // Till a user explicitly calls FileContext.setUMask(), the updates through
|
|
|
+ // configuration should be reflected..
|
|
|
+ conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "011");
|
|
|
+ assertEquals("Umask for fc1 is incorrect", 011, fc1.getUMask().toShort());
|
|
|
+ assertEquals("Umask for fc2 is incorrect", 011, fc2.getUMask().toShort());
|
|
|
+
|
|
|
+ // Stop reflecting the conf update for specific FileContexts, once an
|
|
|
+ // explicit setUMask is done.
|
|
|
+ conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "066");
|
|
|
+ fc1.setUMask(FsPermission.createImmutable((short) 00033));
|
|
|
+ assertEquals("Umask for fc1 is incorrect", 033, fc1.getUMask().toShort());
|
|
|
+ assertEquals("Umask for fc2 is incorrect", 066, fc2.getUMask().toShort());
|
|
|
+
|
|
|
+ conf.set(CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY, "077");
|
|
|
+ fc2.setUMask(FsPermission.createImmutable((short) 00044));
|
|
|
+ assertEquals("Umask for fc1 is incorrect", 033, fc1.getUMask().toShort());
|
|
|
+ assertEquals("Umask for fc2 is incorrect", 044, fc2.getUMask().toShort());
|
|
|
+ }
|
|
|
}
|