use of harness.TestUser in project terra-cli by DataBiosphere.
the class Workspace method statusDescribeListReflectUpdate.
@Test
@DisplayName("status, describe, workspace list reflect workspace update")
void statusDescribeListReflectUpdate() throws IOException {
// select a test user and login
TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
testUser.login();
String name = "statusDescribeListReflectUpdate";
String description = "status list reflect update";
UFWorkspace createdWorkspace = WorkspaceUtils.createWorkspace(testUser, name, description);
// check the created workspace name and description are set
assertNotNull(createdWorkspace.name, "create workspace name is defined");
assertNotNull(createdWorkspace.description, "create workspace description is defined");
// `terra workspace update --format=json --new-id=$newId --new-name=$newName
// --new-description=$newDescription`
String newId = "newid";
String newName = "NEW_statusDescribeListReflectUpdate";
String newDescription = "NEW status describe list reflect update";
TestCommand.runCommandExpectSuccess("workspace", "update", "--format=json", "--new-id=" + newId, "--new-name=" + newName, "--new-description=" + newDescription);
// `terra status --format=json`
UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");
// check the current status reflects the update
assertEquals(newId, status.workspace.id, "status matches updated workspace id");
assertEquals(newName, status.workspace.name, "status matches updated workspace name");
assertEquals(newDescription, status.workspace.description, "status matches updated workspace description");
// `terra workspace describe --format=json`
UFWorkspace describeWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
// check the workspace describe reflects the update
assertEquals(newName, describeWorkspace.name, "describe matches updated workspace name");
assertEquals(newDescription, describeWorkspace.description, "describe matches updated workspace description");
// check the workspace list reflects the update
List<UFWorkspaceLight> matchingWorkspaces = listWorkspacesWithId(newId);
assertEquals(1, matchingWorkspaces.size(), "updated workspace is included exactly once in list");
assertEquals(newName, matchingWorkspaces.get(0).name, "updated workspace name matches that in list");
assertEquals(newDescription, matchingWorkspaces.get(0).description, "updated workspace description matches that in list");
// `terra workspace delete`
TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class WorkspaceOverride method workspaceUser.
@Test
@DisplayName("workspace user commands respect workspace override")
void workspaceUser() throws IOException {
// login as the workspace creator and select a test user to share the workspace with
workspaceCreator.login();
TestUser testUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
// `terra workspace set --id=$id1`
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + workspace1.id);
// `terra workspace add-user --email=$email --role=READER --workspace=$id2`
TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + testUser.email, "--role=READER", "--workspace=" + workspace2.id);
// check that the user exists in the list output for workspace 2, but not workspace 1
// `terra workspace list-users --email=$email --role=READER --workspace=$id2`
expectListedUserWithRoles(testUser.email, workspace2.id, WorkspaceUser.Role.READER);
// `terra workspace list-users --email=$email --role=READER`
Optional<UFWorkspaceUser> workspaceUser = workspaceListUsersWithEmail(testUser.email);
assertTrue(workspaceUser.isEmpty(), "test user is not in users list for workspace 1");
// `terra workspace remove-user --email=$email --role=READER --workspace=$id2`
TestCommand.runCommandExpectSuccess("workspace", "remove-user", "--email=" + testUser.email, "--role=READER", "--workspace=" + workspace2.id);
// `terra workspace list-users --email=$email --role=READER --workspace=$id2`
// check that the user no longer exists in the list output for workspace 2
workspaceUser = workspaceListUsersWithEmail(testUser.email, workspace2.id);
assertTrue(workspaceUser.isEmpty(), "test user is no longer in users list for workspace 2");
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class WorkspaceUser method listReflectAdd.
@Test
@DisplayName("list users reflects adding a user")
void listReflectAdd() throws IOException {
// login as the workspace creator and select a test user to share the workspace with
workspaceCreator.login();
TestUser testUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
// `terra workspace set --id=$id`
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getUserFacingId());
// `terra workspace add-user --email=$email --role=READER --format=json
UFWorkspaceUser addUserReader = TestCommand.runAndParseCommandExpectSuccess(UFWorkspaceUser.class, "workspace", "add-user", "--email=" + testUser.email, "--role=READER");
// check that the user has the READER role
assertTrue(addUserReader.roles.contains(READER), "reader role returned by add-user");
// check that the user is in the list as a reader
expectListedUserWithRoles(testUser.email, READER);
// `terra workspace add-user --email=$email --role=WRITER --format=json
UFWorkspaceUser addUserWriter = TestCommand.runAndParseCommandExpectSuccess(UFWorkspaceUser.class, "workspace", "add-user", "--email=" + testUser.email, "--role=WRITER");
// check that the user has both the READER and WRITER roles
assertTrue(addUserWriter.roles.containsAll(Arrays.asList(READER, WRITER)), "reader and writer roles returned by add-user");
// check that the user is in the list as a reader + writer
expectListedUserWithRoles(testUser.email, READER, WRITER);
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class WorkspaceUser method listReflectRemove.
@Test
@DisplayName("list users reflects removing a user")
void listReflectRemove() throws IOException {
// login as the workspace creator and select a test user to share the workspace with
workspaceCreator.login();
TestUser testUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
// `terra workspace set --id=$id`
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getUserFacingId());
// `terra workspace add-user --email=$email --role=READER --format=json
TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + testUser.email, "--role=READER", "--format=json");
// `terra workspace add-user --email=$email --role=OWNER --format=json
TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + testUser.email, "--role=OWNER", "--format=json");
// `terra workspace remove-user --email=$email --role=READER --format=json
TestCommand.runCommandExpectSuccess("workspace", "remove-user", "--email=" + testUser.email, "--role=READER");
// check that the user is in the list as an OWNER only
expectListedUserWithRoles(testUser.email, OWNER);
// `terra workspace remove-user --email=$email --role=READER`
TestCommand.runCommandExpectSuccess("workspace", "remove-user", "--email=" + testUser.email, "--role=OWNER");
// check that the user is not in the list
Optional<UFWorkspaceUser> workspaceUser = workspaceListUsersWithEmail(testUser.email);
assertTrue(workspaceUser.isEmpty(), "test user is not in users list");
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class CleanupTestUserWorkspaces method deleteWorkspaces.
/**
* List all workspaces the test user has access to and try to delete each one that the test user
* owns. Deletes up to 100 workspaces at a time.
*/
private static void deleteWorkspaces(TestUser testUser, boolean isDryRun) throws IOException {
System.out.println("Deleting workspaces for testuser " + testUser.email);
TestContext.clearGlobalContextDir();
testUser.login();
// `terra workspace list`
List<UFWorkspace> listWorkspaces = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
}, "workspace", "list", "--limit=100");
List<UFWorkspaceUser> listWorkspaceUsers;
for (UFWorkspace workspace : listWorkspaces) {
try {
// `terra workspace list-users`
listWorkspaceUsers = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
}, "workspace", "list-users", "--workspace=" + workspace.id);
// find the user in the list
Optional<UFWorkspaceUser> workspaceUser = listWorkspaceUsers.stream().filter(user -> user.email.equalsIgnoreCase(testUser.email)).findAny();
// skip deleting if the test user is not an owner
if (workspaceUser.isEmpty() || !workspaceUser.get().roles.contains(WorkspaceUser.Role.OWNER)) {
System.out.println("Skip deleting workspace because test user is not an owner: id=" + workspace.id + ", testuser=" + testUser.email);
continue;
}
System.out.println("Deleting workspace: id=" + workspace.id + ", testuser=" + testUser.email);
if (!isDryRun) {
// `terra workspace delete --workspace=$id`
TestCommand.runCommandExpectSuccess("workspace", "delete", "--workspace=" + workspace.id, "--quiet");
System.out.println("Cleaned up workspace: id=" + workspace.id + ", testuser=" + testUser.email);
}
deletedWorkspaces.add(workspace.id);
} catch (Throwable ex) {
System.out.println("Error deleting workspace: id=" + workspace.id + ", testuser=" + testUser.email);
ex.printStackTrace();
failedWorkspaces.add(workspace.id);
continue;
}
}
// `terra auth revoke`
TestCommand.runCommandExpectSuccess("auth", "revoke");
}
Aggregations