Search in sources :

Example 16 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class AttachVfsResourceReferenceSerializerTest method serialize.

@Test
public void serialize() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("attach:attachment"), "path1/path2/test.txt");
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("vfs", "attach:wiki:space.page@attachment", "path1", "path2", "test.txt"));
    URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance(new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath");
    when(normalizer.normalize(extendedURL)).thenReturn(extendedURL);
    AttachmentReferenceResolver<String> attachmentResolver = this.mocker.getInstance(AttachmentReferenceResolver.TYPE_STRING, "current");
    AttachmentReference attachmentReference = new AttachmentReference("attachment", new DocumentReference("wiki", Arrays.asList("space"), "page"));
    when(attachmentResolver.resolve("attachment")).thenReturn(attachmentReference);
    EntityReferenceSerializer<String> entitySerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
    when(entitySerializer.serialize(attachmentReference)).thenReturn("wiki:space.page@attachment");
    assertEquals("/vfs/attach%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt", this.mocker.getComponentUnderTest().serialize(reference).toString());
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) URLNormalizer(org.xwiki.url.URLNormalizer) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 17 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class PathConverterTest method convertWhenOk.

@Test
public void convertWhenOk() 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"));
    Path path = this.mocker.getComponentUnderTest().convert(new DefaultParameterizedType(null, Path.class), "attach:Sandbox.WebHome@my.zip/a/b/c");
    assertEquals("attach://xwiki:Sandbox.WebHome/my.zip/a/b/c", path.toString());
    assertEquals(TPath.class.getName(), path.getClass().getName());
}
Also used : TPath(net.java.truevfs.access.TPath) Path(java.nio.file.Path) ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) TPath(net.java.truevfs.access.TPath) URI(java.net.URI) Test(org.junit.Test)

Example 18 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class VfsScriptServiceTest method url.

@Test
public void url() 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)).thenReturn("/generated/url");
    assertEquals("/generated/url", this.mocker.getComponentUnderTest().url(new VfsResourceReference(URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt")));
}
Also used : VfsManager(org.xwiki.vfs.VfsManager) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) Test(org.junit.Test)

Example 19 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class CascadingVfsPermissionCheckerTest method checkPermissionWithAttachSchemeChecker.

@Test
public void checkPermissionWithAttachSchemeChecker() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("attach:whatever"), "whatever");
    AttachmentReferenceResolver<String> resolver = this.mocker.registerMockComponent(AttachmentReferenceResolver.TYPE_STRING);
    DocumentReference attachmentDocumentReference = new DocumentReference("wiki", "space", "page");
    AttachmentReference attachmentReference = new AttachmentReference("file", attachmentDocumentReference);
    when(resolver.resolve("whatever")).thenReturn(attachmentReference);
    ContextualAuthorizationManager authorizationManager = this.mocker.registerMockComponent(ContextualAuthorizationManager.class);
    when(authorizationManager.hasAccess(Right.VIEW, attachmentReference)).thenReturn(true);
    this.mocker.getComponentUnderTest().checkPermission(reference);
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 20 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class CascadingVfsPermissionCheckerTest method checkPermissionWhenNoSpecificSchemeCheckerAndNotAllowed.

@Test
public void checkPermissionWhenNoSpecificSchemeCheckerAndNotAllowed() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("customscheme:whatever"), "whatever");
    AuthorizationManager authorizationManager = this.mocker.registerMockComponent(AuthorizationManager.class);
    when(authorizationManager.hasAccess(Right.PROGRAM, this.contextUser, null)).thenReturn(false);
    try {
        this.mocker.getComponentUnderTest().checkPermission(reference);
        fail("Should have raised exception");
    } catch (VfsException expected) {
        assertEquals("Current logged-in user ([" + this.contextUser + "]) needs to have Programming Rights to use the [customscheme] VFS", expected.getMessage());
    }
}
Also used : VfsException(org.xwiki.vfs.VfsException) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) ContextualAuthorizationManager(org.xwiki.security.authorization.ContextualAuthorizationManager) Test(org.junit.Test)

Aggregations

VfsResourceReference (org.xwiki.vfs.VfsResourceReference)26 Test (org.junit.Test)19 URI (java.net.URI)11 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)10 ResourceReferenceSerializer (org.xwiki.resource.ResourceReferenceSerializer)8 ExtendedURL (org.xwiki.url.ExtendedURL)7 TPath (net.java.truevfs.access.TPath)6 VfsException (org.xwiki.vfs.VfsException)6 Path (java.nio.file.Path)5 DocumentReference (org.xwiki.model.reference.DocumentReference)3 ConversionException (org.xwiki.properties.converter.ConversionException)3 SerializeResourceReferenceException (org.xwiki.resource.SerializeResourceReferenceException)3 ContextualAuthorizationManager (org.xwiki.security.authorization.ContextualAuthorizationManager)3 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 AttachmentReference (org.xwiki.model.reference.AttachmentReference)2 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)2 URLNormalizer (org.xwiki.url.URLNormalizer)2 VfsManager (org.xwiki.vfs.VfsManager)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1