|
@@ -38,6 +38,8 @@ import org.apache.hadoop.hdfs.AppendTestUtil;
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
import org.apache.hadoop.hdfs.DFSConfigKeys;
|
|
import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
|
import org.apache.hadoop.hdfs.DistributedFileSystem;
|
|
|
|
+import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
|
|
+import org.apache.hadoop.hdfs.client.HdfsClientConfigKeys;
|
|
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
|
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
|
|
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
|
|
import org.apache.hadoop.hdfs.protocol.SnapshotDiffReport;
|
|
import org.apache.hadoop.hdfs.protocol.SnapshotException;
|
|
import org.apache.hadoop.hdfs.protocol.SnapshotException;
|
|
@@ -117,6 +119,14 @@ public abstract class BaseTestHttpFSWith extends HFSTestCase {
|
|
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsDefaultName);
|
|
conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsDefaultName);
|
|
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true);
|
|
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true);
|
|
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, true);
|
|
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, true);
|
|
|
|
+ // For BaseTestHttpFSWith#testFileAclsCustomizedUserAndGroupNames
|
|
|
|
+ conf.set(HdfsClientConfigKeys.DFS_WEBHDFS_USER_PATTERN_KEY,
|
|
|
|
+ "^[A-Za-z0-9_][A-Za-z0-9._-]*[$]?$");
|
|
|
|
+ conf.set(HdfsClientConfigKeys.DFS_WEBHDFS_ACL_PERMISSION_PATTERN_KEY,
|
|
|
|
+ "^(default:)?(user|group|mask|other):" +
|
|
|
|
+ "[[0-9A-Za-z_][@A-Za-z0-9._-]]*:([rwx-]{3})?(,(default:)?" +
|
|
|
|
+ "(user|group|mask|other):[[0-9A-Za-z_][@A-Za-z0-9._-]]*:" +
|
|
|
|
+ "([rwx-]{3})?)*$");
|
|
File hdfsSite = new File(new File(homeDir, "conf"), "hdfs-site.xml");
|
|
File hdfsSite = new File(new File(homeDir, "conf"), "hdfs-site.xml");
|
|
OutputStream os = new FileOutputStream(hdfsSite);
|
|
OutputStream os = new FileOutputStream(hdfsSite);
|
|
conf.writeXml(os);
|
|
conf.writeXml(os);
|
|
@@ -1130,6 +1140,7 @@ public abstract class BaseTestHttpFSWith extends HFSTestCase {
|
|
testContentSummary();
|
|
testContentSummary();
|
|
break;
|
|
break;
|
|
case FILEACLS:
|
|
case FILEACLS:
|
|
|
|
+ testFileAclsCustomizedUserAndGroupNames();
|
|
testFileAcls();
|
|
testFileAcls();
|
|
break;
|
|
break;
|
|
case DIRACLS:
|
|
case DIRACLS:
|
|
@@ -1581,4 +1592,53 @@ public abstract class BaseTestHttpFSWith extends HFSTestCase {
|
|
verifyGetSnapshottableDirListing(fs, dfs);
|
|
verifyGetSnapshottableDirListing(fs, dfs);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private void testFileAclsCustomizedUserAndGroupNames() throws Exception {
|
|
|
|
+ if (isLocalFS()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Get appropriate conf from the cluster
|
|
|
|
+ MiniDFSCluster miniDFSCluster = ((TestHdfsHelper) hdfsTestHelper)
|
|
|
|
+ .getMiniDFSCluster();
|
|
|
|
+ Configuration conf = miniDFSCluster.getConfiguration(0);
|
|
|
|
+ // If we call getHttpFSFileSystem() without conf from the mini cluster,
|
|
|
|
+ // WebHDFS will be initialized with the default ACL string, causing the
|
|
|
|
+ // setAcl() later to fail. This is only an issue in the unit test.
|
|
|
|
+ FileSystem httpfs = getHttpFSFileSystem(conf);
|
|
|
|
+ if (!(httpfs instanceof WebHdfsFileSystem)
|
|
|
|
+ && !(httpfs instanceof HttpFSFileSystem)) {
|
|
|
|
+ Assert.fail(httpfs.getClass().getSimpleName() +
|
|
|
|
+ " doesn't support custom user and group name pattern. "
|
|
|
|
+ + "Only WebHdfsFileSystem and HttpFSFileSystem support it.");
|
|
|
|
+ }
|
|
|
|
+ final String aclUser = "user:123:rwx";
|
|
|
|
+ final String aclGroup = "group:foo@bar:r--";
|
|
|
|
+ final String aclSet = "user::rwx," + aclUser + ",group::r--," +
|
|
|
|
+ aclGroup + ",other::r--";
|
|
|
|
+ final String dir = "/aclFileTestCustom";
|
|
|
|
+ // Create test file
|
|
|
|
+ FileSystem proxyFs = FileSystem.get(conf);
|
|
|
|
+ proxyFs.mkdirs(new Path(dir));
|
|
|
|
+ Path path = new Path(dir, "/testACL");
|
|
|
|
+ OutputStream os = proxyFs.create(path);
|
|
|
|
+ os.write(1);
|
|
|
|
+ os.close();
|
|
|
|
+ // Set ACL
|
|
|
|
+ httpfs.setAcl(path, AclEntry.parseAclSpec(aclSet, true));
|
|
|
|
+ // Verify getAclStatus responses are the same
|
|
|
|
+ AclStatus proxyAclStat = proxyFs.getAclStatus(path);
|
|
|
|
+ AclStatus httpfsAclStat = httpfs.getAclStatus(path);
|
|
|
|
+ assertSameAcls(httpfsAclStat, proxyAclStat);
|
|
|
|
+ assertSameAcls(httpfs, proxyFs, path);
|
|
|
|
+ // Verify that custom user and group are set.
|
|
|
|
+ List<String> strEntries = new ArrayList<>();
|
|
|
|
+ for (AclEntry aclEntry : httpfsAclStat.getEntries()) {
|
|
|
|
+ strEntries.add(aclEntry.toStringStable());
|
|
|
|
+ }
|
|
|
|
+ Assert.assertTrue(strEntries.contains(aclUser));
|
|
|
|
+ Assert.assertTrue(strEntries.contains(aclGroup));
|
|
|
|
+ // Clean up
|
|
|
|
+ proxyFs.delete(new Path(dir), true);
|
|
|
|
+ }
|
|
}
|
|
}
|