|
83 | 83 | import org.apache.hadoop.security.alias.JavaKeyStoreProvider;
|
84 | 84 | import org.apache.hadoop.test.GenericTestUtils;
|
85 | 85 | import org.apache.hadoop.test.LambdaTestUtils;
|
| 86 | +import org.apache.hadoop.util.Shell; |
86 | 87 | import org.junit.Assert;
|
87 | 88 | import org.junit.Before;
|
88 | 89 | import org.junit.Test;
|
@@ -865,13 +866,25 @@ public void testLocalhostReverseLookup() {
|
865 | 866 |
|
866 | 867 | @Test (timeout=15000)
|
867 | 868 | public void testIsValidName() {
|
868 |
| - assertFalse(DFSUtil.isValidName("/foo/../bar")); |
869 |
| - assertFalse(DFSUtil.isValidName("/foo/./bar")); |
870 |
| - assertFalse(DFSUtil.isValidName("/foo//bar")); |
871 |
| - assertTrue(DFSUtil.isValidName("/")); |
872 |
| - assertTrue(DFSUtil.isValidName("/bar/")); |
873 |
| - assertFalse(DFSUtil.isValidName("/foo/:/bar")); |
874 |
| - assertFalse(DFSUtil.isValidName("/foo:bar")); |
| 869 | + String validPaths[] = new String[]{"/", "/bar/"}; |
| 870 | + for (String path : validPaths) { |
| 871 | + assertTrue("Should have been accepted '" + path + "'", DFSUtil.isValidName(path)); |
| 872 | + } |
| 873 | + |
| 874 | + String invalidPaths[] = |
| 875 | + new String[]{"/foo/../bar", "/foo/./bar", "/foo//bar", "/foo/:/bar", "/foo:bar"}; |
| 876 | + for (String path : invalidPaths) { |
| 877 | + assertFalse("Should have been rejected '" + path + "'", DFSUtil.isValidName(path)); |
| 878 | + } |
| 879 | + |
| 880 | + String windowsPath = "/C:/foo/bar"; |
| 881 | + if (Shell.WINDOWS) { |
| 882 | + assertTrue("Should have been accepted '" + windowsPath + "' in windows os.", |
| 883 | + DFSUtil.isValidName(windowsPath)); |
| 884 | + } else { |
| 885 | + assertFalse("Should have been rejected '" + windowsPath + "' in unix os.", |
| 886 | + DFSUtil.isValidName(windowsPath)); |
| 887 | + } |
875 | 888 | }
|
876 | 889 |
|
877 | 890 | @Test(timeout=5000)
|
|
0 commit comments