/** * Constructs a default {@link MkdirsOptions}. */ private MkdirsOptions(String authUmask) { // By default create parent is true. mCreateParent = true; // default owner and group are null (unset) mOwner = null; mGroup = null; mMode = ModeUtils.applyDirectoryUMask(Mode.defaults(), authUmask); }
/** * Tests the {@link Mode#getUMask()} method to thrown an exception when it is not an integer. */ @Test public void umaskNotInteger() { String umask = "NotInteger"; mThrown.expect(IllegalArgumentException.class); mThrown.expectMessage(ExceptionMessage.INVALID_CONFIGURATION_VALUE.getMessage(umask, PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); ModeUtils.applyDirectoryUMask(Mode.defaults(), umask); }
/** * @return Master side defaults for {@link CreateDirectoryPOptions} */ public static CreateDirectoryPOptions createDirectoryDefaults() { return CreateDirectoryPOptions.newBuilder() .setCommonOptions(commonDefaults()) .setMode(ModeUtils.applyDirectoryUMask(Mode.defaults(), ServerConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)).toProto()) .setRecursive(false) .setWriteType(ServerConfiguration .getEnum(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class).toProto()) .setAllowExists(false).build(); }
/** * Tests the {@link Mode#getUMask()} method to thrown an exception when it exceeds the length. */ @Test public void umaskExceedLength() { String umask = "00022"; mConfiguration.set(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK, umask); mThrown.expect(IllegalArgumentException.class); mThrown.expectMessage(ExceptionMessage.INVALID_CONFIGURATION_VALUE.getMessage(umask, PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); ModeUtils.applyDirectoryUMask(Mode.defaults(), mConfiguration .get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)); }
SecurityUtils.getOwnerFromLoginModule(ServerConfiguration.global()), SecurityUtils.getGroupFromLoginModule(ServerConfiguration.global()), ModeUtils.applyDirectoryUMask(Mode.createFullAccess(), ServerConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)), context);
/** * Tests the {@link MutableInodeDirectory#getMode()} method. */ @Test public void permissionStatus() { MutableInodeDirectory inode2 = createInodeDirectory(); Assert.assertEquals(TEST_OWNER, inode2.getOwner()); Assert.assertEquals(TEST_GROUP, inode2.getGroup()); Assert.assertEquals(ModeUtils.applyDirectoryUMask(Mode.defaults(), ServerConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)).toShort(), inode2.getMode()); }
/** * Tests the {@link Mode#getUMask()} and * {@link Mode#applyUMask(Mode)} methods. */ @Test public void umask() { String umask = "0022"; Mode mode = ModeUtils.applyDirectoryUMask(Mode.defaults(), umask); assertEquals(Mode.Bits.ALL, mode.getOwnerBits()); assertEquals(Mode.Bits.READ_EXECUTE, mode.getGroupBits()); assertEquals(Mode.Bits.READ_EXECUTE, mode.getOtherBits()); assertEquals(0755, mode.toShort()); }
/** * Tests for default {@link MkdirsOptions}. */ @Test public void defaults() throws IOException { MkdirsOptions options = MkdirsOptions.defaults(mConfiguration); // Verify the default createParent is true. assertTrue(options.getCreateParent()); // Verify that the owner and group are not set. assertNull(options.getOwner()); assertNull(options.getGroup()); String umask = mConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK); assertEquals(ModeUtils.applyDirectoryUMask(Mode.defaults(), umask), options.getMode()); }
/** * Tests for building an {@link MkdirsOptions} with a security enabled * configuration. */ @Test public void securityEnabled() throws IOException { InstancedConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults()); conf.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName()); conf.set(PropertyKey.SECURITY_LOGIN_USERNAME, "foo"); // Use IdentityUserGroupMapping to map user "foo" to group "foo". conf.set(PropertyKey.SECURITY_GROUP_MAPPING_CLASS, IdentityUserGroupsMapping.class.getName()); MkdirsOptions options = MkdirsOptions.defaults(mConfiguration); // Verify the default createParent is true. assertTrue(options.getCreateParent()); // Verify that the owner and group are not set. assertNull(options.getOwner()); assertNull(options.getGroup()); String umask = mConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK); assertEquals(ModeUtils.applyDirectoryUMask(Mode.defaults(), umask), options.getMode()); }