|
@@ -20,6 +20,7 @@ package org.apache.hadoop.hdfs.web;
|
|
|
|
|
|
import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.KERBEROS;
|
|
import static org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod.KERBEROS;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
+import static org.junit.Assert.assertFalse;
|
|
import static org.mockito.Mockito.mock;
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -29,9 +30,15 @@ import java.net.URL;
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
|
+import org.apache.hadoop.fs.FileStatus;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
|
+import org.apache.hadoop.fs.LocatedFileStatus;
|
|
import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.fs.Path;
|
|
|
|
+import org.apache.hadoop.fs.RemoteIterator;
|
|
|
|
+import org.apache.hadoop.fs.WebHdfs;
|
|
import org.apache.hadoop.fs.permission.FsAction;
|
|
import org.apache.hadoop.fs.permission.FsAction;
|
|
|
|
+import org.apache.hadoop.hdfs.DFSTestUtil;
|
|
|
|
+import org.apache.hadoop.hdfs.MiniDFSCluster;
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
|
|
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
|
|
import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
|
|
@@ -357,4 +364,54 @@ public class TestWebHdfsUrl {
|
|
}
|
|
}
|
|
return (WebHdfsFileSystem) FileSystem.get(uri, conf);
|
|
return (WebHdfsFileSystem) FileSystem.get(uri, conf);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private static final String SPECIAL_CHARACTER_FILENAME =
|
|
|
|
+ "specialFile ?\"\\()[]_-=&+;,{}#%'`~!@$^*|<>.";
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testWebHdfsSpecialCharacterFile() throws Exception {
|
|
|
|
+ UserGroupInformation ugi =
|
|
|
|
+ UserGroupInformation.createRemoteUser("test-user");
|
|
|
|
+ ugi.setAuthenticationMethod(KERBEROS);
|
|
|
|
+ UserGroupInformation.setLoginUser(ugi);
|
|
|
|
+
|
|
|
|
+ final Configuration conf = WebHdfsTestUtil.createConf();
|
|
|
|
+ final Path dir = new Path("/testWebHdfsSpecialCharacterFile");
|
|
|
|
+
|
|
|
|
+ final short numDatanodes = 1;
|
|
|
|
+ final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf)
|
|
|
|
+ .numDataNodes(numDatanodes)
|
|
|
|
+ .build();
|
|
|
|
+ try {
|
|
|
|
+ cluster.waitActive();
|
|
|
|
+ final FileSystem fs = WebHdfsTestUtil
|
|
|
|
+ .getWebHdfsFileSystem(conf, WebHdfs.SCHEME);
|
|
|
|
+
|
|
|
|
+ //create a file
|
|
|
|
+ final long length = 1L << 10;
|
|
|
|
+ final Path file1 = new Path(dir, SPECIAL_CHARACTER_FILENAME);
|
|
|
|
+
|
|
|
|
+ DFSTestUtil.createFile(fs, file1, length, numDatanodes, 20120406L);
|
|
|
|
+
|
|
|
|
+ //get file status and check that it was written properly.
|
|
|
|
+ final FileStatus s1 = fs.getFileStatus(file1);
|
|
|
|
+ assertEquals("Write failed for file " + file1, length, s1.getLen());
|
|
|
|
+
|
|
|
|
+ boolean found = false;
|
|
|
|
+ RemoteIterator<LocatedFileStatus> statusRemoteIterator =
|
|
|
|
+ fs.listFiles(dir, false);
|
|
|
|
+ while (statusRemoteIterator.hasNext()) {
|
|
|
|
+ LocatedFileStatus locatedFileStatus = statusRemoteIterator.next();
|
|
|
|
+ if (locatedFileStatus.isFile() &&
|
|
|
|
+ SPECIAL_CHARACTER_FILENAME
|
|
|
|
+ .equals(locatedFileStatus.getPath().getName())) {
|
|
|
|
+ found = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ assertFalse("Could not find file with special character", !found);
|
|
|
|
+ } finally {
|
|
|
|
+ cluster.shutdown();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|