use of org.nuxeo.ecm.automation.client.Session in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemOperations method testConflictedNames.
@Test
public void testConflictedNames() throws Exception {
// Try a canonical example with the Administrator user
Blob jsonOut = (Blob) clientSession.newRequest(NuxeoDriveGenerateConflictedItemName.ID).set("name", "My file (with accents \u00e9).doc").execute();
assertNotNull(jsonOut);
String newName = mapper.readValue(jsonOut.getStream(), String.class);
assertTrue(newName.startsWith("My file (with accents \u00e9) (Administrator - "));
assertTrue(newName.endsWith(").doc"));
// Try with a filename with filename extension
jsonOut = (Blob) clientSession.newRequest(NuxeoDriveGenerateConflictedItemName.ID).set("name", "My file").execute();
assertNotNull(jsonOut);
newName = mapper.readValue(jsonOut.getStream(), String.class);
assertTrue(newName.startsWith("My file (Administrator - "));
assertTrue(newName.endsWith(")"));
// Test with a user that has a firstname and a lastname
// Joe Strummer likes conflicting files
createUser("joe", "joe", "Joe", "Strummer");
Session joeSession = automationClient.getSession("joe", "joe");
jsonOut = (Blob) joeSession.newRequest(NuxeoDriveGenerateConflictedItemName.ID).set("name", "The Clashing File.xls").execute();
assertNotNull(jsonOut);
newName = mapper.readValue(jsonOut.getStream(), String.class);
assertTrue(newName.startsWith("The Clashing File (Joe Strummer - "));
assertTrue(newName.endsWith(").xls"));
deleteUser("joe");
}
use of org.nuxeo.ecm.automation.client.Session in project nuxeo-drive-server by nuxeo.
the class TestFileSystemItemOperations method testCanMove.
@Test
public void testCanMove() throws Exception {
// ------------------------------------------------------
// File to File => false
// ------------------------------------------------------
Blob canMoveFSItemJSON = (Blob) clientSession.newRequest(NuxeoDriveCanMove.ID).set("srcId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).set("destId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file2.getId()).execute();
assertNotNull(canMoveFSItemJSON);
String canMoveFSItem = mapper.readValue(canMoveFSItemJSON.getStream(), String.class);
assertEquals("false", canMoveFSItem);
// ------------------------------------------------------
// Sync root => false
// ------------------------------------------------------
canMoveFSItemJSON = (Blob) clientSession.newRequest(NuxeoDriveCanMove.ID).set("srcId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot1.getId()).set("destId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
assertNotNull(canMoveFSItemJSON);
canMoveFSItem = mapper.readValue(canMoveFSItemJSON.getStream(), String.class);
assertEquals("false", canMoveFSItem);
// ------------------------------------------------------
// Top level folder => false
// ------------------------------------------------------
canMoveFSItemJSON = (Blob) clientSession.newRequest(NuxeoDriveCanMove.ID).set("srcId", fileSystemItemAdapterService.getTopLevelFolderItemFactory().getTopLevelFolderItem(session.getPrincipal()).getId()).set("destId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
assertNotNull(canMoveFSItemJSON);
canMoveFSItem = mapper.readValue(canMoveFSItemJSON.getStream(), String.class);
assertEquals("false", canMoveFSItem);
// --------------------------------------------------------
// No REMOVE permission on the source backing doc => false
// --------------------------------------------------------
Principal joe = createUser("joe", "joe");
DocumentModel rootDoc = session.getRootDocument();
setPermission(rootDoc, "joe", SecurityConstants.READ, true);
nuxeoDriveManager.registerSynchronizationRoot(joe, syncRoot1, session);
nuxeoDriveManager.registerSynchronizationRoot(joe, syncRoot2, session);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
Session joeSession = automationClient.getSession("joe", "joe");
canMoveFSItemJSON = (Blob) joeSession.newRequest(NuxeoDriveCanMove.ID).set("srcId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).set("destId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
assertNotNull(canMoveFSItemJSON);
canMoveFSItem = mapper.readValue(canMoveFSItemJSON.getStream(), String.class);
assertEquals("false", canMoveFSItem);
// -------------------------------------------------------------------
// No ADD_CHILDREN permission on the destination backing doc => false
// -------------------------------------------------------------------
setPermission(syncRoot1, "joe", SecurityConstants.WRITE, true);
canMoveFSItemJSON = (Blob) joeSession.newRequest(NuxeoDriveCanMove.ID).set("srcId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).set("destId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
assertNotNull(canMoveFSItemJSON);
canMoveFSItem = mapper.readValue(canMoveFSItemJSON.getStream(), String.class);
assertEquals("false", canMoveFSItem);
// ----------------------------------------------------------------------
// REMOVE permission on the source backing doc + REMOVE_CHILDREN
// permission on its parent + ADD_CHILDREN permission on the destination
// backing doc => true
// ----------------------------------------------------------------------
setPermission(syncRoot2, "joe", SecurityConstants.WRITE, true);
nuxeoDriveManager.unregisterSynchronizationRoot(joe, syncRoot2, session);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
canMoveFSItemJSON = (Blob) joeSession.newRequest(NuxeoDriveCanMove.ID).set("srcId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).set("destId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
assertNotNull(canMoveFSItemJSON);
canMoveFSItem = mapper.readValue(canMoveFSItemJSON.getStream(), String.class);
// syncRoot2 is not registered as a sync root for joe
assertEquals("false", canMoveFSItem);
nuxeoDriveManager.registerSynchronizationRoot(joe, syncRoot2, session);
TransactionHelper.commitOrRollbackTransaction();
TransactionHelper.startTransaction();
canMoveFSItemJSON = (Blob) joeSession.newRequest(NuxeoDriveCanMove.ID).set("srcId", DEFAULT_FILE_SYSTEM_ITEM_ID_PREFIX + file1.getId()).set("destId", SYNC_ROOT_FOLDER_ITEM_ID_PREFIX + syncRoot2.getId()).execute();
assertNotNull(canMoveFSItemJSON);
canMoveFSItem = mapper.readValue(canMoveFSItemJSON.getStream(), String.class);
// syncRoot2 is now a registered root for joe
assertEquals("true", canMoveFSItem);
// ----------------------------------------------------------------------
// Reset permissions
// ----------------------------------------------------------------------
resetPermissions(rootDoc, "joe");
resetPermissions(syncRoot1, "joe");
resetPermissions(syncRoot2, "joe");
deleteUser("joe");
}
use of org.nuxeo.ecm.automation.client.Session 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