FileResolver extends UriMappingResolver { @Override protected RResponse get(RRequest request, String source) { final Path p; try { p = base != null ? base.resolve(source).normalize() : Paths.get(source); } catch (InvalidPathException e) { return request.noResultResponse().withWarning(e); } if (canonicalBase != null) { if (!p.toAbsolutePath().startsWith(canonicalBase)) { return null; } } if (!Files.isRegularFile(p)) return null; return new FileResult(request, p); } FileResolver(Path base, Path check);  FileResolver(File base, String check);  FileResolver();  FileResolver(String base);  FileResolver(File base);  FileResolver(File base, File check); @Override UriMappingResolver lookupAll(); @Override String toString();  }
@Test public void test_get_directory() { RRequest req = new RRequest(null, null, null, null); RResponse res = instance.get(req, "schema"); assertThat(res != null && res.hasResult(), is(false)); }
@Test public void test_get_file() { RRequest req = new RRequest(null, null, null, null); RResult res = instance.get(req, "schema/a.xsd").getResult(); assertThat(res.getInputStream(), is(notNullValue())); }
@Test public void test_checked_base_dir() { File checkedBase = new File("src/test/resources/schema"); File base = new File(checkedBase, "foo"); instance = new FileResolver(base, checkedBase); RRequest req = new RRequest(null, null, null, null); RResult res = instance.get(req, "../a.xsd").getResult(); assertThat(res, is(notNullValue())); assertThat(res.getInputStream(), is(notNullValue())); RResponse response = instance.get(req, "../../a.xml"); assertThat(response != null && response.hasResult(), is(false)); instance = new FileResolver(base, (File) null); res = instance.get(req, "../../a.xml").getResult(); assertThat(res, is(notNullValue())); }