use of java.nio.file.InvalidPathException in project jetty.project by eclipse.
the class FileSystemResourceTest method testExist_BadURINullX.
@Test
public void testExist_BadURINullX() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Files.createDirectories(dir);
Path path = dir.resolve("a.jsp");
Files.createFile(path);
try {
// request with null and x at end
URI uri = testdir.getPath().toUri().resolve("a.jsp%00x");
assertThat("NullX URI", uri, notNullValue());
Resource r = newResource(uri);
// if we have r, then it better not exist
assertFalse(r.exists());
} catch (InvalidPathException e) {
// Exception is acceptable
}
}
use of java.nio.file.InvalidPathException in project jetty.project by eclipse.
the class FileSystemResourceTest method testAddPath_WindowsExtensionLess.
@Test
public void testAddPath_WindowsExtensionLess() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Files.createDirectories(dir);
Path basePath = dir.resolve("base");
FS.ensureDirExists(basePath);
Path dirPath = basePath.resolve("aa");
FS.ensureDirExists(dirPath);
Path filePath = dirPath.resolve("foo.txt");
Files.createFile(filePath);
try (Resource base = newResource(basePath.toFile())) {
assertThat("Exists: " + basePath, base.exists(), is(true));
assertThat("Alias: " + basePath, base, hasNoAlias());
Resource r = base.addPath("aa./foo.txt");
assertThat("getURI()", r.getURI().toASCIIString(), containsString("aa./foo.txt"));
if (OS.IS_WINDOWS) {
assertThat("isAlias()", r.isAlias(), is(true));
assertThat("getAlias()", r.getAlias(), notNullValue());
assertThat("getAlias()", r.getAlias().toASCIIString(), containsString("aa/foo.txt"));
assertThat("Exists: " + r, r.exists(), is(true));
} else {
assertThat("isAlias()", r.isAlias(), is(false));
assertThat("Exists: " + r, r.exists(), is(false));
}
} catch (InvalidPathException e) {
// Exception is acceptable
}
}
use of java.nio.file.InvalidPathException in project jetty.project by eclipse.
the class FileSystemResourceTest method testAddRootPath.
@Test
public void testAddRootPath() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Path subdir = dir.resolve("sub");
Files.createDirectories(subdir);
String readableRootDir = findRootDir(dir.getFileSystem());
assumeThat("Readable Root Dir found", readableRootDir, notNullValue());
try (Resource base = newResource(dir.toFile())) {
Resource sub = base.addPath("sub");
assertThat("sub", sub.isDirectory(), is(true));
try {
Resource rrd = sub.addPath(readableRootDir);
// valid path for unix and OSX
assertThat("Readable Root Dir", rrd.exists(), is(false));
} catch (MalformedURLException | InvalidPathException e) {
// valid path on Windows
}
}
}
use of java.nio.file.InvalidPathException in project jetty.project by eclipse.
the class FileSystemResourceTest method testAddInitialSlash.
@Test
public void testAddInitialSlash() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Files.createDirectories(dir);
Path basePath = dir.resolve("base");
FS.ensureDirExists(basePath);
Path filePath = basePath.resolve("foo.txt");
Files.createFile(filePath);
try (Resource base = newResource(basePath.toFile())) {
assertThat("Exists: " + basePath, base.exists(), is(true));
assertThat("Alias: " + basePath, base, hasNoAlias());
Resource r = base.addPath("/foo.txt");
assertThat("getURI()", r.getURI().toASCIIString(), containsString("/foo.txt"));
assertThat("isAlias()", r.isAlias(), is(false));
assertThat("Exists: " + r, r.exists(), is(true));
} catch (InvalidPathException e) {
// Exception is acceptable
}
}
use of java.nio.file.InvalidPathException in project jetty.project by eclipse.
the class FileSystemResourceTest method testNTFSFileStreamAlias.
/**
* NTFS Alternative Data / File Streams.
* <p>
* See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364404(v=vs.85).aspx
* @throws Exception failed test
*/
@Test
public void testNTFSFileStreamAlias() throws Exception {
Path dir = testdir.getPath().normalize().toRealPath();
Files.createDirectories(dir);
Path path = dir.resolve("testfile");
Files.createFile(path);
try (Resource base = newResource(dir.toFile())) {
Resource resource = base.addPath("testfile");
assertThat("resource.alias", resource, hasNoAlias());
assertThat("resource.uri.alias", newResource(resource.getURI()), hasNoAlias());
assertThat("resource.file.alias", newResource(resource.getFile()), hasNoAlias());
try {
// Attempt to reference same file, but via NTFS simple stream
Resource alias = base.addPath("testfile:stream");
if (alias.exists()) {
// If it exists, it must be an alias
assertThat("resource.alias", alias, isAliasFor(resource));
assertThat("resource.uri.alias", newResource(alias.getURI()), isAliasFor(resource));
assertThat("resource.file.alias", newResource(alias.getFile()), isAliasFor(resource));
}
} catch (InvalidPathException e) {
// NTFS filesystem streams are unsupported on some platforms.
assumeNoException(e);
}
}
}
Aggregations