Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,12 @@ public static String getHomeDirectory(Configuration conf,
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY,
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_DEFAULT);
}
return userHomePrefix + Path.SEPARATOR + ugi.getShortUserName();
String homeDirectory =
userHomePrefix + Path.SEPARATOR + ugi.getShortUserName();
Preconditions.checkArgument(new Path(homeDirectory).isAbsolute(),
"Invalid value of %s: %s; must be an absolute path",
HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY, userHomePrefix);
return homeDirectory;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.apache.hadoop.fs.BlockLocation;
import org.apache.hadoop.fs.CommonConfigurationKeys;
import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
Expand Down Expand Up @@ -1117,6 +1118,34 @@ public void testFileIdPath() throws Throwable {
}
}

@Test
public void testUserHomeDirectoryPrefix() throws Exception {
UserGroupInformation ugi =
UserGroupInformation.createRemoteUser("test-user");
Configuration conf = new Configuration(false);

assertEquals("/user/test-user",
DFSUtilClient.getHomeDirectory(conf, ugi));

conf.set(HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY, "/home");
assertEquals("/home/test-user",
DFSUtilClient.getHomeDirectory(conf, ugi));

conf.set(HdfsClientConfigKeys.DFS_USER_HOME_DIR_PREFIX_KEY, "@name@");
IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> DFSUtilClient.getHomeDirectory(conf, ugi));
assertEquals("Invalid value of dfs.user.home.dir.prefix: @name@; "
+ "must be an absolute path", exception.getMessage());

conf.setClass("fs.hdfs.impl", DistributedFileSystem.class,
FileSystem.class);
exception = assertThrows(IllegalArgumentException.class,
() -> FileSystem.newInstance(new URI("hdfs://127.0.0.1:9000"), conf));
assertEquals("Invalid value of dfs.user.home.dir.prefix: @name@; "
+ "must be an absolute path", exception.getMessage());
}

@Test
public void testErrorMessageForInvalidNameservice() throws Exception {
Configuration conf = new HdfsConfiguration();
Expand Down
Loading