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()))));
}
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);
}
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());
}
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());
}
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));
}
Aggregations