HDFS-17249. Fix TestDFSUtil.testIsValidName() unit test failure (#6249)
Contributed by liuguanghua.
This commit is contained in:
parent
a32097a921
commit
342e6caba1
@ -661,9 +661,12 @@ public class DFSUtilClient {
|
|||||||
String[] components = StringUtils.split(src, '/');
|
String[] components = StringUtils.split(src, '/');
|
||||||
for (int i = 0; i < components.length; i++) {
|
for (int i = 0; i < components.length; i++) {
|
||||||
String element = components[i];
|
String element = components[i];
|
||||||
|
// For Windows, we must allow the : in the drive letter.
|
||||||
|
if (Shell.WINDOWS && i == 1 && element.endsWith(":")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (element.equals(".") ||
|
if (element.equals(".") ||
|
||||||
// For Windows, we must allow the : in the drive letter.
|
(element.contains(":")) ||
|
||||||
(!Shell.WINDOWS && i == 1 && element.contains(":")) ||
|
|
||||||
(element.contains("/"))) {
|
(element.contains("/"))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,7 @@ import org.apache.hadoop.security.alias.CredentialProviderFactory;
|
|||||||
import org.apache.hadoop.security.alias.JavaKeyStoreProvider;
|
import org.apache.hadoop.security.alias.JavaKeyStoreProvider;
|
||||||
import org.apache.hadoop.test.GenericTestUtils;
|
import org.apache.hadoop.test.GenericTestUtils;
|
||||||
import org.apache.hadoop.test.LambdaTestUtils;
|
import org.apache.hadoop.test.LambdaTestUtils;
|
||||||
|
import org.apache.hadoop.util.Shell;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -865,13 +866,25 @@ public class TestDFSUtil {
|
|||||||
|
|
||||||
@Test (timeout=15000)
|
@Test (timeout=15000)
|
||||||
public void testIsValidName() {
|
public void testIsValidName() {
|
||||||
assertFalse(DFSUtil.isValidName("/foo/../bar"));
|
String validPaths[] = new String[]{"/", "/bar/"};
|
||||||
assertFalse(DFSUtil.isValidName("/foo/./bar"));
|
for (String path : validPaths) {
|
||||||
assertFalse(DFSUtil.isValidName("/foo//bar"));
|
assertTrue("Should have been accepted '" + path + "'", DFSUtil.isValidName(path));
|
||||||
assertTrue(DFSUtil.isValidName("/"));
|
}
|
||||||
assertTrue(DFSUtil.isValidName("/bar/"));
|
|
||||||
assertFalse(DFSUtil.isValidName("/foo/:/bar"));
|
String invalidPaths[] =
|
||||||
assertFalse(DFSUtil.isValidName("/foo:bar"));
|
new String[]{"/foo/../bar", "/foo/./bar", "/foo//bar", "/foo/:/bar", "/foo:bar"};
|
||||||
|
for (String path : invalidPaths) {
|
||||||
|
assertFalse("Should have been rejected '" + path + "'", DFSUtil.isValidName(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
String windowsPath = "/C:/foo/bar";
|
||||||
|
if (Shell.WINDOWS) {
|
||||||
|
assertTrue("Should have been accepted '" + windowsPath + "' in windows os.",
|
||||||
|
DFSUtil.isValidName(windowsPath));
|
||||||
|
} else {
|
||||||
|
assertFalse("Should have been rejected '" + windowsPath + "' in unix os.",
|
||||||
|
DFSUtil.isValidName(windowsPath));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(timeout=5000)
|
@Test(timeout=5000)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user