Search in sources :

Example 16 with PathRef

use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-drive-server by nuxeo.

the class TestNuxeoDriveManager method testResetSyncRootsOnCopy.

@Test
public void testResetSyncRootsOnCopy() {
    nuxeoDriveManager.registerSynchronizationRoot(session.getPrincipal(), folder_1_1, session);
    // Copy a sync root
    DocumentModel copy = session.copy(folder_1_1.getRef(), workspace_2.getRef(), null);
    txFeature.nextTransaction();
    assertFalse(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), copy));
    nuxeoDriveManager.invalidateSynchronizationRootsCache(session.getPrincipal().getName());
    // Copy a folder containing a sync root
    copy = session.copy(workspace_1.getRef(), workspace_2.getRef(), null);
    txFeature.nextTransaction();
    assertFalse(nuxeoDriveManager.isSynchronizationRoot(session.getPrincipal(), session.getDocument(new PathRef(copy.getPathAsString() + "/" + folder_1_1.getName()))));
}
Also used : PathRef(org.nuxeo.ecm.core.api.PathRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 17 with PathRef

use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-drive-server by nuxeo.

the class TestNuxeoDriveManager method testSyncRootChildWhenBlockingInheritance.

@Test
public void testSyncRootChildWhenBlockingInheritance() {
    // Create a folder_2_1_1, as a child of folder_2_1
    DocumentModel folder_2_1_1 = session.createDocument(session.createDocumentModel("/default-domain/workspaces/workspace-2/folder-2-1", "folder_2-1-1", "Folder"));
    // Make user1 register workspace-2, should have no effect on child
    // folder-2-1
    // and on folder_2_1_1
    nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), workspace_2, user1Session);
    folder_2_1 = session.getDocument(new PathRef("/default-domain/workspaces/workspace-2/folder-2-1"));
    assertTrue(isUserSubscribed("user1", workspace_2));
    assertFalse(isUserSubscribed("user1", folder_2_1));
    assertFalse(isUserSubscribed("user1", folder_2_1_1));
    // Block permissions inheritance on folder_2_1
    ACP acp = folder_2_1.getACP();
    ACL localACL = acp.getOrCreateACL(ACL.LOCAL_ACL);
    List<ACE> aceList = new ArrayList<>();
    aceList.addAll(Arrays.asList(localACL.getACEs()));
    localACL.clear();
    aceList.add(new ACE(SecurityConstants.EVERYONE, SecurityConstants.EVERYTHING, false));
    localACL.addAll(aceList);
    folder_2_1.setACP(acp, true);
    folder_2_1 = session.saveDocument(folder_2_1);
    // Check that the user1 has no longer access to folder_2_1
    assertFalse(session.hasPermission(Framework.getService(UserManager.class).getPrincipal("user1"), folder_2_1_1.getRef(), SecurityConstants.READ_WRITE));
    // Give permission READ_WRITE to user1 on folder_2_1_1 and make it sync
    // root
    acp = folder_2_1_1.getACP();
    localACL = acp.getOrCreateACL(ACL.LOCAL_ACL);
    localACL.add(new ACE("user1", SecurityConstants.READ_WRITE, true));
    folder_2_1_1.setACP(acp, true);
    folder_2_1_1 = session.saveDocument(folder_2_1_1);
    assertTrue(session.hasPermission(Framework.getService(UserManager.class).getPrincipal("user1"), folder_2_1_1.getRef(), SecurityConstants.READ_WRITE));
    nuxeoDriveManager.registerSynchronizationRoot(user1Session.getPrincipal(), folder_2_1_1, user1Session);
    assertTrue(isUserSubscribed("user1", workspace_2));
    assertFalse(isUserSubscribed("user1", folder_2_1));
    assertTrue(isUserSubscribed("user1", folder_2_1_1));
    Principal user1 = user1Session.getPrincipal();
    checkRootsCount(user1, 2);
}
Also used : ACE(org.nuxeo.ecm.core.api.security.ACE) PathRef(org.nuxeo.ecm.core.api.PathRef) UserManager(org.nuxeo.ecm.platform.usermanager.UserManager) ArrayList(java.util.ArrayList) ACL(org.nuxeo.ecm.core.api.security.ACL) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) ACP(org.nuxeo.ecm.core.api.security.ACP) Principal(java.security.Principal) Test(org.junit.Test)

Example 18 with PathRef

use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testCreateFolder.

@Test
public void testCreateFolder() throws Exception {
    Blob newFolderJSON = (Blob) clientSession.newRequest(NuxeoDriveCreateFolder.ID).set("parentId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).set("name", "newFolder").execute();
    assertNotNull(newFolderJSON);
    DocumentBackedFolderItem newFolder = mapper.readValue(newFolderJSON.getStream(), DocumentBackedFolderItem.class);
    assertNotNull(newFolder);
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    session.save();
    DocumentModel newFolderDoc = session.getDocument(new PathRef("/folder2/newFolder"));
    assertEquals("Folder", newFolderDoc.getType());
    assertEquals("newFolder", newFolderDoc.getTitle());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + newFolderDoc.getId(), newFolder.getId());
    assertEquals(SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId(), newFolder.getParentId());
    assertEquals("newFolder", newFolder.getName());
    assertTrue(newFolder.isFolder());
    assertEquals("Administrator", newFolder.getCreator());
    assertEquals("Administrator", newFolder.getLastContributor());
    assertTrue(newFolder.getCanRename());
    assertTrue(newFolder.getCanDelete());
    assertTrue(newFolder.getCanCreateChild());
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) PathRef(org.nuxeo.ecm.core.api.PathRef) DocumentBackedFolderItem(org.nuxeo.drive.adapter.impl.DocumentBackedFolderItem) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 19 with PathRef

use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-drive-server by nuxeo.

the class TestFileSystemItemOperations method testCreateFile.

@Test
public void testCreateFile() throws Exception {
    StringBlob blob = new StringBlob("This is the content of a new file.");
    blob.setFileName("New file.odt");
    Blob newFileJSON = (Blob) clientSession.newRequest(NuxeoDriveCreateFile.ID).set("parentId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder1.getId()).setInput(blob).execute();
    assertNotNull(newFileJSON);
    DocumentBackedFileItem newFile = mapper.readValue(newFileJSON.getStream(), DocumentBackedFileItem.class);
    assertNotNull(newFile);
    // Need to flush VCS cache to be aware of changes in the session used by the file system item
    session.save();
    DocumentModel newFileDoc = session.getDocument(new PathRef("/folder1/subFolder1/New file.odt"));
    assertEquals("File", newFileDoc.getType());
    assertEquals("New file.odt", newFileDoc.getTitle());
    org.nuxeo.ecm.core.api.Blob newFileBlob = (org.nuxeo.ecm.core.api.Blob) newFileDoc.getPropertyValue("file:content");
    assertNotNull(newFileBlob);
    assertEquals("New file.odt", newFileBlob.getFilename());
    assertEquals("This is the content of a new file.", newFileBlob.getString());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + newFileDoc.getId(), newFile.getId());
    assertEquals(DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + subFolder1.getId(), newFile.getParentId());
    assertEquals("New file.odt", newFile.getName());
    assertFalse(newFile.isFolder());
    assertEquals("Administrator", newFile.getCreator());
    assertEquals("Administrator", newFile.getLastContributor());
    assertTrue(newFile.getCanRename());
    assertTrue(newFile.getCanDelete());
    assertTrue(newFile.getCanUpdate());
    assertEquals("nxfile/test/" + newFileDoc.getId() + "/blobholder:0/New%20file.odt", newFile.getDownloadURL());
    assertEquals("MD5", newFile.getDigestAlgorithm());
    assertEquals(newFileBlob.getDigest(), newFile.getDigest());
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) PathRef(org.nuxeo.ecm.core.api.PathRef) StringBlob(org.nuxeo.ecm.automation.client.model.StringBlob) DocumentBackedFileItem(org.nuxeo.drive.adapter.impl.DocumentBackedFileItem) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) Test(org.junit.Test)

Example 20 with PathRef

use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-drive-server by nuxeo.

the class TestIntegrationTestOperations method testIntegrationTestsSetupAndTearDown.

@Test
public void testIntegrationTestsSetupAndTearDown() throws Exception {
    // ---------------------------------------------------------
    // Setup the integration tests environment as Administrator
    // ---------------------------------------------------------
    Blob testUserCredentialsBlob = (Blob) clientSession.newRequest(NuxeoDriveSetupIntegrationTests.ID).set("userNames", "joe,jack").set("permission", "ReadWrite").execute();
    assertNotNull(testUserCredentialsBlob);
    // Invalidate VCS cache
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // Check test users
    String testUserCredentials = IOUtils.toString(testUserCredentialsBlob.getStream(), "UTF-8");
    assertNotNull(testUserCredentials);
    String[] testUserCrendentialsArray = StringUtils.split(testUserCredentials, ",");
    assertEquals(2, testUserCrendentialsArray.length);
    assertTrue(testUserCrendentialsArray[0].startsWith("drivejoe:"));
    assertTrue(testUserCrendentialsArray[1].startsWith("drivejack:"));
    // useMembersGroup is false by default
    NuxeoPrincipal joePrincipal = userManager.getPrincipal("drivejoe");
    assertNotNull(joePrincipal);
    assertFalse(joePrincipal.getGroups().contains("members"));
    NuxeoPrincipal jackPrincipal = userManager.getPrincipal("drivejack");
    assertNotNull(jackPrincipal);
    assertFalse(jackPrincipal.getGroups().contains("members"));
    // Check test workspace
    DocumentRef testWorkspaceRef = new PathRef(testWorkspacePath);
    DocumentModel testWorkspace = session.getDocument(testWorkspaceRef);
    assertEquals("Workspace", testWorkspace.getType());
    assertEquals("Nuxeo Drive Test Workspace", testWorkspace.getTitle());
    assertTrue(session.hasPermission(joePrincipal, testWorkspaceRef, SecurityConstants.WRITE));
    assertTrue(session.hasPermission(jackPrincipal, testWorkspaceRef, SecurityConstants.WRITE));
    // Create test users' personal workspaces for cleanup check
    userWorkspaceService.getUserPersonalWorkspace("drivejoe", session.getRootDocument());
    userWorkspaceService.getUserPersonalWorkspace("drivejack", session.getRootDocument());
    assertNotNull(session.getDocument(new PathRef(userWorkspaceParentPath + "/drivejoe")));
    assertNotNull(session.getDocument(new PathRef(userWorkspaceParentPath + "/drivejack")));
    // Save personal workspaces
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // ----------------------------------------------------------------------
    // Setup the integration tests environment with other user names without
    // having teared it down previously => should start by cleaning it up
    // ----------------------------------------------------------------------
    testUserCredentialsBlob = (Blob) clientSession.newRequest(NuxeoDriveSetupIntegrationTests.ID).set("userNames", "sarah").set("useMembersGroup", true).set("permission", "ReadWrite").execute();
    assertNotNull(testUserCredentialsBlob);
    // Check cleanup
    assertNull(userManager.getPrincipal("drivejoe"));
    assertNull(userManager.getPrincipal("drivejack"));
    // Process invalidations
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try {
        session.getDocument(new PathRef(userWorkspaceParentPath + "/drivejoe"));
        fail("User workspace should not exist.");
    } catch (DocumentNotFoundException e) {
        assertEquals(userWorkspaceParentPath + "/drivejoe", e.getMessage());
    }
    try {
        session.getDocument(new PathRef(userWorkspaceParentPath + "/drivejack"));
        fail("User workspace should not exist.");
    } catch (DocumentNotFoundException e) {
        assertEquals(userWorkspaceParentPath + "/drivejack", e.getMessage());
    }
    // Check test users
    testUserCredentials = IOUtils.toString(testUserCredentialsBlob.getStream(), "UTF-8");
    assertNotNull(testUserCredentials);
    testUserCrendentialsArray = StringUtils.split(testUserCredentials, ",");
    assertEquals(1, testUserCrendentialsArray.length);
    assertTrue(testUserCrendentialsArray[0].startsWith("drivesarah:"));
    NuxeoPrincipal sarahPrincipal = userManager.getPrincipal("drivesarah");
    assertNotNull(sarahPrincipal);
    assertTrue(sarahPrincipal.getGroups().contains("members"));
    // Check test workspace
    testWorkspace = session.getDocument(testWorkspaceRef);
    assertEquals("Nuxeo Drive Test Workspace", testWorkspace.getTitle());
    assertTrue(session.hasPermission(sarahPrincipal, testWorkspaceRef, SecurityConstants.WRITE));
    // Create test users' personal workspaces for cleanup check
    userWorkspaceService.getUserPersonalWorkspace("drivesarah", session.getRootDocument());
    assertNotNull(session.getDocument(new PathRef(userWorkspaceParentPath + "/drivesarah")));
    // Save personal workspaces
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    // ----------------------------------------------------------------------
    // Try to setup the integration tests environment as an unauthorized
    // user => should fail
    // ----------------------------------------------------------------------
    String sarahCredentials = testUserCrendentialsArray[0];
    String sarahPassword = sarahCredentials.substring(sarahCredentials.indexOf(':') + 1);
    Session unauthorizedSession = automationClient.getSession("drivesarah", sarahPassword);
    try {
        unauthorizedSession.newRequest(NuxeoDriveSetupIntegrationTests.ID).set("userNames", "john,bob").set("permission", "ReadWrite").execute();
        fail("NuxeoDrive.SetupIntegrationTests operation should not be callable by a non administrator.");
    } catch (Exception e) {
    // Expected
    }
    // ----------------------------------------------------------------------
    try {
        unauthorizedSession.newRequest(NuxeoDriveTearDownIntegrationTests.ID).execute();
        fail("NuxeoDrive.TearDownIntegrationTests operation should not be callable by a non administrator.");
    } catch (Exception e) {
    // Expected
    }
    // ----------------------------------------------------------------------
    // Tear down the integration tests environment as Administrator
    // ----------------------------------------------------------------------
    clientSession.newRequest(NuxeoDriveTearDownIntegrationTests.ID).execute();
    assertTrue(userManager.searchUsers("drive").isEmpty());
    // Process invalidations
    TransactionHelper.commitOrRollbackTransaction();
    TransactionHelper.startTransaction();
    try {
        session.getDocument(new PathRef(userWorkspaceParentPath + "/drivesarah"));
        fail("User workspace should not exist.");
    } catch (DocumentNotFoundException e) {
        assertEquals(userWorkspaceParentPath + "/drivesarah", e.getMessage());
    }
    assertFalse(session.exists(testWorkspaceRef));
}
Also used : Blob(org.nuxeo.ecm.automation.client.model.Blob) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) PathRef(org.nuxeo.ecm.core.api.PathRef) NuxeoPrincipal(org.nuxeo.ecm.core.api.NuxeoPrincipal) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) Session(org.nuxeo.ecm.automation.client.Session) CoreSession(org.nuxeo.ecm.core.api.CoreSession) Test(org.junit.Test)

Aggregations

PathRef (org.nuxeo.ecm.core.api.PathRef)26 DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)21 Test (org.junit.Test)14 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)8 Path (org.nuxeo.common.utils.Path)5 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)4 Blob (org.nuxeo.ecm.core.api.Blob)4 ArrayList (java.util.ArrayList)3 Blob (org.nuxeo.ecm.automation.client.model.Blob)3 IdRef (org.nuxeo.ecm.core.api.IdRef)3 ACE (org.nuxeo.ecm.core.api.security.ACE)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 StringBlob (org.nuxeo.ecm.automation.client.model.StringBlob)2 CollectionManager (org.nuxeo.ecm.collections.api.CollectionManager)2 CoreSession (org.nuxeo.ecm.core.api.CoreSession)2 DocumentModelList (org.nuxeo.ecm.core.api.DocumentModelList)2 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)2 BlobHolder (org.nuxeo.ecm.core.api.blobholder.BlobHolder)2 StringBlob (org.nuxeo.ecm.core.api.impl.blob.StringBlob)2