use of org.xwiki.vfs.VfsException in project xwiki-platform by xwiki.
the class PathConverterTest method convertWhenNoPermission.
@Test
public void convertWhenNoPermission() throws Exception {
ResourceReferenceSerializer<VfsResourceReference, URI> serializer = this.mocker.getInstance(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, URI.class), "truevfs");
VfsResourceReference reference = new VfsResourceReference(URI.create("attach:Sandbox.WebHome@my.zip"), "a/b/c");
when(serializer.serialize(reference)).thenReturn(URI.create("attach://xwiki:Sandbox.WebHome/my.zip/a/b/c"));
VfsPermissionChecker permissionChecker = this.mocker.getInstance(VfsPermissionChecker.class, "cascading");
doThrow(new VfsException("unauthorized")).when(permissionChecker).checkPermission(reference);
try {
this.mocker.getComponentUnderTest().convert(new DefaultParameterizedType(null, Path.class), "attach:Sandbox.WebHome@my.zip/a/b/c");
fail("Should have thrown an exception here");
} catch (ConversionException expected) {
assertEquals("Failed to convert [attach:Sandbox.WebHome@my.zip/a/b/c] to a Path object", expected.getMessage());
assertEquals("VfsException: unauthorized", ExceptionUtils.getRootCauseMessage(expected));
}
}
use of org.xwiki.vfs.VfsException in project xwiki-platform by xwiki.
the class VfsScriptServiceTest method urlError.
@Test
public void urlError() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt");
VfsManager manager = this.mocker.getInstance(VfsManager.class);
when(manager.getURL(reference)).thenThrow(new VfsException("error"));
assertNull(this.mocker.getComponentUnderTest().url(new VfsResourceReference(URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt")));
}
use of org.xwiki.vfs.VfsException in project xwiki-platform by xwiki.
the class DefaultVfsPathFactory method create.
@Override
public Path create(URI uri) throws VfsException {
try {
VfsResourceReference reference = this.vfsResourceReferenceConverter.convert(VfsResourceReference.class, uri.toString());
this.permissionChecker.checkPermission(reference);
URI trueVFSURI = this.trueVfsResourceReferenceSerializer.serialize(reference);
return new TPath(trueVFSURI);
} catch (Exception e) {
throw new VfsException(String.format("Failed to create Path instance for [%s]", uri.toString()), e);
}
}
use of org.xwiki.vfs.VfsException in project xwiki-platform by xwiki.
the class CascadingVfsPermissionCheckerTest method checkPermissionWhenReservedScheme.
@Test
public void checkPermissionWhenReservedScheme() throws Exception {
VfsResourceReference reference = new VfsResourceReference(URI.create("cascading:whatever"), "whatever");
try {
this.mocker.getComponentUnderTest().checkPermission(reference);
fail("Should have raised exception");
} catch (VfsException expected) {
assertEquals("[cascading] is a reserved VFS URI scheme and cannot be used.", expected.getMessage());
}
}
use of org.xwiki.vfs.VfsException in project xwiki-platform by xwiki.
the class VfsResourceReferenceHandlerTest method handleWhenNoGenericPermissionForScheme.
@Test
public void handleWhenNoGenericPermissionForScheme() throws Exception {
setUp("customscheme", "wiki3", "space3", "page3", "test.zip", Arrays.asList("test.txt"));
// Don't allow permission for "customscheme"
VfsPermissionChecker checker = this.mocker.getInstance(VfsPermissionChecker.class, "cascading");
doThrow(new VfsException("no permission")).when(checker).checkPermission(this.reference);
try {
this.mocker.getComponentUnderTest().handle(this.reference, mock(ResourceReferenceHandlerChain.class));
fail("Should have thrown exception here");
} catch (ResourceReferenceHandlerException expected) {
assertEquals("VfsException: no permission", ExceptionUtils.getRootCauseMessage(expected));
}
}
Aggregations