@Override public boolean isValidName(String src) { return myFs.isValidName(src); }
@Override public boolean isValidName(String src) { return myFs.isValidName(fullPath(new Path(src)).toUri().toString()); }
/** * Get the path-part of a pathname. Checks that URI matches this file system * and that the path-part is a valid name. * * @param p path * * @return path-part of the Path p */ public String getUriPath(final Path p) { checkPath(p); String s = p.toUri().getPath(); if (!isValidName(s)) { throw new InvalidPathException("Path part " + s + " from URI " + p + " is not a valid filename."); } return s; }
@Override public boolean isValidName(String src) { return myFs.isValidName(src); }
@Override public boolean isValidName(String src) { return myFs.isValidName(src); }
@Override public boolean isValidName(String src) { return myFs.isValidName(src); }
@Override public boolean isValidName(String src) { return myFs.isValidName(src); }
@Override public boolean isValidName(String src) { return myFs.isValidName(fullPath(new Path(src)).toUri().toString()); }
@Override public boolean isValidName(String src) { return myFs.isValidName(fullPath(new Path(src)).toUri().toString()); }
@Override public boolean isValidName(String src) { return myFs.isValidName(fullPath(new Path(src)).toUri().toString()); }
@Override public boolean isValidName(String src) { return myFs.isValidName(fullPath(new Path(src)).toUri().toString()); }
/** * Get the path-part of a pathname. Checks that URI matches this file system * and that the path-part is a valid name. * * @param p path * * @return path-part of the Path p */ public String getUriPath(final Path p) { checkPath(p); String s = p.toUri().getPath(); if (!isValidName(s)) { throw new InvalidPathException("Path part " + s + " from URI " + p + " is not a valid filename."); } return s; }
/** * Get the path-part of a pathname. Checks that URI matches this file system * and that the path-part is a valid name. * * @param p path * * @return path-part of the Path p */ public String getUriPath(final Path p) { checkPath(p); String s = p.toUri().getPath(); if (!isValidName(s)) { throw new InvalidPathException("Path part " + s + " from URI " + p + " is not a valid filename."); } return s; }
/** * Get the path-part of a pathname. Checks that URI matches this file system * and that the path-part is a valid name. * * @param p path * * @return path-part of the Path p */ public String getUriPath(final Path p) { checkPath(p); String s = p.toUri().getPath(); if (!isValidName(s)) { throw new InvalidPathException("Path part " + s + " from URI " + p + " is not a valid filename."); } return s; }
@Test public void testIsValidNameValidInBaseFs() throws Exception { AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem()); ChRootedFs chRootedFs = new ChRootedFs(baseFs, new Path("/chroot")); Mockito.doReturn(true).when(baseFs).isValidName(Mockito.anyString()); Assert.assertTrue(chRootedFs.isValidName("/test")); Mockito.verify(baseFs).isValidName("/chroot/test"); }
@Test public void testIsValidNameInvalidInBaseFs() throws Exception { AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem()); ChRootedFs chRootedFs = new ChRootedFs(baseFs, new Path("/chroot")); Mockito.doReturn(false).when(baseFs).isValidName(Mockito.anyString()); Assert.assertFalse(chRootedFs.isValidName("/test")); Mockito.verify(baseFs).isValidName("/chroot/test"); } }
@Test public void testIsValidNameValidInBaseFs() throws Exception { AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem()); ChRootedFs chRootedFs = new ChRootedFs(baseFs, new Path("/chroot")); Mockito.doReturn(true).when(baseFs).isValidName(Mockito.anyString()); Assert.assertTrue(chRootedFs.isValidName("/test")); Mockito.verify(baseFs).isValidName("/chroot/test"); }
static AbstractFileSystem getMockFs(URI uri) { AbstractFileSystem mockFs = fsCache.get(uri.getAuthority()); if (mockFs == null) { mockFs = mock(AbstractFileSystem.class); when(mockFs.getUri()).thenReturn(uri); when(mockFs.getUriDefaultPort()).thenReturn(1); when(mockFs.getUriPath(any(Path.class))).thenCallRealMethod(); when(mockFs.isValidName(anyString())).thenReturn(true); fsCache.put(uri.getAuthority(), mockFs); } return mockFs; } }
@Test public void testIsValidNameInvalidInBaseFs() throws Exception { AbstractFileSystem baseFs = Mockito.spy(fc.getDefaultFileSystem()); ChRootedFs chRootedFs = new ChRootedFs(baseFs, new Path("/chroot")); Mockito.doReturn(false).when(baseFs).isValidName(Mockito.anyString()); Assert.assertFalse(chRootedFs.isValidName("/test")); Mockito.verify(baseFs).isValidName("/chroot/test"); } }
@Test public void testIsValidNameInvalidNames() { String[] invalidNames = { "/foo/../bar", "/foo/./bar", "/foo/:/bar", "/foo:bar" }; for (String invalidName: invalidNames) { Assert.assertFalse(invalidName + " is not valid", fc.getDefaultFileSystem().isValidName(invalidName)); } }