|
26 | 26 | import java.util.Map; |
27 | 27 |
|
28 | 28 | import static org.elasticsearch.core.PathUtils.getDefaultFileSystem; |
| 29 | +import static org.hamcrest.Matchers.equalTo; |
29 | 30 | import static org.hamcrest.Matchers.is; |
30 | 31 |
|
31 | 32 | @ESTestCase.WithoutSecurityManager |
@@ -193,6 +194,48 @@ public void testNormalizePath() { |
193 | 194 | assertThat(tree.canRead(path("")), is(false)); |
194 | 195 | } |
195 | 196 |
|
| 197 | + public void testNormalizeDirectorySeparatorWindows() { |
| 198 | + assumeTrue("normalization of windows paths", Platform.WINDOWS.isCurrent()); |
| 199 | + |
| 200 | + assertThat(FileAccessTree.normalizePath(Path.of("C:\\a\\b")), equalTo("C:\\a\\b")); |
| 201 | + assertThat(FileAccessTree.normalizePath(Path.of("C:/a.xml")), equalTo("C:\\a.xml")); |
| 202 | + assertThat(FileAccessTree.normalizePath(Path.of("C:/a/b.txt")), equalTo("C:\\a\\b.txt")); |
| 203 | + assertThat(FileAccessTree.normalizePath(Path.of("C:/a/c\\foo.txt")), equalTo("C:\\a\\c\\foo.txt")); |
| 204 | + |
| 205 | + var tree = accessTree( |
| 206 | + entitlement("C:\\a\\b", "read", "C:/a.xml", "read", "C:/a/b.txt", "read", "C:/a/c\\foo.txt", "read"), |
| 207 | + List.of() |
| 208 | + ); |
| 209 | + |
| 210 | + assertThat(tree.canRead(Path.of("C:/a.xml")), is(true)); |
| 211 | + assertThat(tree.canRead(Path.of("C:\\a.xml")), is(true)); |
| 212 | + assertThat(tree.canRead(Path.of("C:/a/")), is(false)); |
| 213 | + assertThat(tree.canRead(Path.of("C:/a/b.txt")), is(true)); |
| 214 | + assertThat(tree.canRead(Path.of("C:/a/b/c.txt")), is(true)); |
| 215 | + assertThat(tree.canRead(Path.of("C:\\a\\b\\c.txt")), is(true)); |
| 216 | + assertThat(tree.canRead(Path.of("C:\\a\\c\\")), is(false)); |
| 217 | + assertThat(tree.canRead(Path.of("C:\\a\\c\\foo.txt")), is(true)); |
| 218 | + } |
| 219 | + |
| 220 | + public void testNormalizeDirectorySeparatorPosix() { |
| 221 | + assumeFalse("normalization of posix paths", Platform.WINDOWS.isCurrent()); |
| 222 | + |
| 223 | + assertThat(FileAccessTree.normalizePath(Path.of("\\a\\b")), equalTo("/a/b")); |
| 224 | + assertThat(FileAccessTree.normalizePath(Path.of("/a.xml")), equalTo("/a.xml")); |
| 225 | + assertThat(FileAccessTree.normalizePath(Path.of("/a/c\\foo.txt")), equalTo("/a/c/foo.txt")); |
| 226 | + |
| 227 | + var tree = accessTree(entitlement("\\a\\b", "read", "/a.xml", "read", "/a/b.txt", "read", "/a/c\\foo.txt", "read"), List.of()); |
| 228 | + |
| 229 | + assertThat(tree.canRead(Path.of("/a.xml")), is(true)); |
| 230 | + assertThat(tree.canRead(Path.of("\\a.xml")), is(true)); |
| 231 | + assertThat(tree.canRead(Path.of("/a/")), is(false)); |
| 232 | + assertThat(tree.canRead(Path.of("/a/b.txt")), is(true)); |
| 233 | + assertThat(tree.canRead(Path.of("/a/b/c.txt")), is(true)); |
| 234 | + assertThat(tree.canRead(Path.of("\\a\\b\\c.txt")), is(true)); |
| 235 | + assertThat(tree.canRead(Path.of("\\a\\c\\")), is(false)); |
| 236 | + assertThat(tree.canRead(Path.of("\\a\\c\\foo.txt")), is(true)); |
| 237 | + } |
| 238 | + |
196 | 239 | public void testNormalizeTrailingSlashes() { |
197 | 240 | var tree = accessTree(entitlement("/trailing/slash/", "read", "/no/trailing/slash", "read"), List.of()); |
198 | 241 | assertThat(tree.canRead(path("/trailing/slash")), is(true)); |
|
0 commit comments