|
@@ -43,7 +43,6 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
-import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.fs.XAttrCodec;
|
|
@@ -137,9 +136,9 @@ public class TestHttpFSServer extends HFSTestCase {
|
|
|
//HDFS configuration
|
|
|
File hadoopConfDir = new File(new File(homeDir, "conf"), "hadoop-conf");
|
|
|
hadoopConfDir.mkdirs();
|
|
|
- String fsDefaultName = TestHdfsHelper.getHdfsConf().get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY);
|
|
|
- Configuration conf = new Configuration(false);
|
|
|
- conf.set(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, fsDefaultName);
|
|
|
+ Configuration hdfsConf = TestHdfsHelper.getHdfsConf();
|
|
|
+ // Http Server's conf should be based on HDFS's conf
|
|
|
+ Configuration conf = new Configuration(hdfsConf);
|
|
|
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true);
|
|
|
conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_XATTRS_ENABLED_KEY, true);
|
|
|
File hdfsSite = new File(hadoopConfDir, "hdfs-site.xml");
|
|
@@ -346,6 +345,20 @@ public class TestHttpFSServer extends HFSTestCase {
|
|
|
return (String) details.get("permission");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Given the JSON output from the GETTRASHPATH call, return the
|
|
|
+ * 'path' value.
|
|
|
+ *
|
|
|
+ * @param statusJson JSON from GETTRASHPATH
|
|
|
+ * @return The value of 'path' in statusJson
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private String getPath(String statusJson) throws Exception {
|
|
|
+ JSONParser parser = new JSONParser();
|
|
|
+ JSONObject details = (JSONObject) parser.parse(statusJson);
|
|
|
+ return (String) details.get("Path");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Given the JSON output from the GETACLSTATUS call, return the
|
|
|
* 'entries' value as a List<String>.
|
|
@@ -671,6 +684,40 @@ public class TestHttpFSServer extends HFSTestCase {
|
|
|
Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ @TestDir
|
|
|
+ @TestJetty
|
|
|
+ @TestHdfs
|
|
|
+ public void testGetTrashRoot() throws Exception {
|
|
|
+ String user = HadoopUsersConfTestHelper.getHadoopUsers()[0];
|
|
|
+ createHttpFSServer(false);
|
|
|
+ String trashJson = getStatus("/", "GETTRASHROOT");
|
|
|
+ String trashPath = getPath(trashJson);
|
|
|
+
|
|
|
+ Path expectedPath = new Path(FileSystem.USER_HOME_PREFIX,
|
|
|
+ new Path(user, FileSystem.TRASH_PREFIX));
|
|
|
+ Assert.assertEquals(expectedPath.toUri().getPath(), trashPath);
|
|
|
+
|
|
|
+ byte[] array = new byte[]{0, 1, 2, 3};
|
|
|
+ FileSystem fs = FileSystem.get(TestHdfsHelper.getHdfsConf());
|
|
|
+ fs.mkdirs(new Path("/tmp"));
|
|
|
+ OutputStream os = fs.create(new Path("/tmp/foo"));
|
|
|
+ os.write(array);
|
|
|
+ os.close();
|
|
|
+
|
|
|
+ trashJson = getStatus("/tmp/foo", "GETTRASHROOT");
|
|
|
+ trashPath = getPath(trashJson);
|
|
|
+ Assert.assertEquals(expectedPath.toUri().getPath(), trashPath);
|
|
|
+
|
|
|
+ //TestHdfsHelp has already set up EZ environment
|
|
|
+ final Path ezFile = TestHdfsHelper.ENCRYPTED_FILE;
|
|
|
+ final Path ezPath = TestHdfsHelper.ENCRYPTION_ZONE;
|
|
|
+ trashJson = getStatus(ezFile.toUri().getPath(), "GETTRASHROOT");
|
|
|
+ trashPath = getPath(trashJson);
|
|
|
+ expectedPath = new Path(ezPath, new Path(FileSystem.TRASH_PREFIX, user));
|
|
|
+ Assert.assertEquals(expectedPath.toUri().getPath(), trashPath);
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
@TestDir
|
|
|
@TestJetty
|
|
@@ -754,6 +801,21 @@ public class TestHttpFSServer extends HFSTestCase {
|
|
|
conn = (HttpURLConnection) url.openConnection();
|
|
|
Assert.assertEquals(HttpURLConnection.HTTP_FORBIDDEN,
|
|
|
conn.getResponseCode());
|
|
|
+
|
|
|
+ // getTrash test with delegation
|
|
|
+ url = new URL(TestJettyHelper.getJettyURL(),
|
|
|
+ "/webhdfs/v1/?op=GETTRASHROOT&delegation=" + tokenStr);
|
|
|
+ conn = (HttpURLConnection) url.openConnection();
|
|
|
+ Assert.assertEquals(HttpURLConnection.HTTP_FORBIDDEN,
|
|
|
+ conn.getResponseCode());
|
|
|
+
|
|
|
+ url = new URL(TestJettyHelper.getJettyURL(),
|
|
|
+ "/webhdfs/v1/?op=GETTRASHROOT");
|
|
|
+ conn = (HttpURLConnection) url.openConnection();
|
|
|
+ conn.setRequestProperty("Cookie",
|
|
|
+ AuthenticatedURL.AUTH_COOKIE + "=" + tokenSigned);
|
|
|
+ Assert.assertEquals(HttpURLConnection.HTTP_OK,
|
|
|
+ conn.getResponseCode());
|
|
|
}
|
|
|
|
|
|
}
|