use of harness.TestUser in project terra-cli by DataBiosphere.
the class SpendProfileUser method listUsersReflectsEnableDisable.
@Test
@DisplayName("list-users reflects enabling and disabling users")
void listUsersReflectsEnableDisable() throws IOException {
// get an email to try and add
String testEmail = generateSamGroupForEmail();
// use a test user that is an owner to grant spend access to the test email
TestUser spendProfileOwner = TestUser.chooseTestUserWithOwnerAccess();
spendProfileOwner.login();
// `terra spend enable --email=$testEmail --policy=USER`
TestCommand.runCommandExpectSuccess("spend", "enable", "--email=" + testEmail, "--policy=USER");
// check that the test email is included in the list-users output
expectListedUserWithPolicies(testEmail, SpendProfilePolicy.USER);
// `terra spend disable --email=$testEmail --policy=USER`
TestCommand.runCommandExpectSuccess("spend", "disable", "--email=" + testEmail, "--policy=USER");
// check that the test email is not included in the list-users output
Optional<UFSpendProfileUser> listUsersOutput = listUsersWithEmail(testEmail);
assertTrue(listUsersOutput.isEmpty(), "user is not included in the test-users output after having their spend access disabled");
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class Workspace method statusDescribeReflectsSet.
@Test
@DisplayName("status, describe reflect workspace set")
void statusDescribeReflectsSet() throws IOException {
// select a test user and login
TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
testUser.login();
// `terra workspace create --format=json` (workspace 1)
UFWorkspace createWorkspace1 = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "create");
// `terra workspace create --format=json` (workspace 2)
UFWorkspace createWorkspace2 = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "create");
// set current workspace = workspace 1
UFWorkspace setWorkspace1 = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "set", "--id=" + createWorkspace1.id);
assertEquals(createWorkspace1.id, setWorkspace1.id, "set returned the expected workspace (1)");
// `terra status --format=json`
UFStatus status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");
// check the current status reflects the workspace set
assertEquals(createWorkspace1.id, status.workspace.id, "status matches set workspace id (1)");
// `terra workspace describe --format=json`
UFWorkspace describeWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
// check the workspace describe reflects the workspace set
assertEquals(createWorkspace1.id, describeWorkspace.id, "describe matches set workspace id (1)");
// set current workspace = workspace 2
UFWorkspace setWorkspace2 = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "set", "--id=" + createWorkspace2.id);
assertEquals(createWorkspace2.id, setWorkspace2.id, "set returned the expected workspace (2)");
// `terra status --format=json`
status = TestCommand.runAndParseCommandExpectSuccess(UFStatus.class, "status");
// check the current status reflects the workspace set
assertEquals(createWorkspace2.id, status.workspace.id, "status matches set workspace id (2)");
// `terra workspace describe --format=json`
describeWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "describe");
// check the workspace describe reflects the workspace set
assertEquals(createWorkspace2.id, describeWorkspace.id, "describe matches set workspace id (2)");
// `terra workspace delete` (workspace 2)
TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
// `terra workspace set` (workspace 1)
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + createWorkspace1.id);
// `terra workspace delete` (workspace 1)
TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class ClientExceptionHandling method samDuplicateGroup.
@Test
@DisplayName("try to create a group twice, check that the output includes the CLI and SAM error messages")
void samDuplicateGroup() throws IOException {
TestUser testUser = TestUser.chooseTestUser();
testUser.login();
// `terra group create --name=$name`
String name = SamGroups.randomGroupName();
TestCommand.runCommandExpectSuccess("group", "create", "--name=" + name);
// track the group so we can clean it up in case this test method fails
trackedGroups.trackGroup(name, testUser);
// try to create another group with the same name
String stdErr = TestCommand.runCommandExpectExitCode(2, "group", "create", "--name=" + name);
assertThat("stderr includes the CLI error message", stdErr, CoreMatchers.containsString("Error creating SAM group"));
assertThat("stderr includes the SAM error message", stdErr, CoreMatchers.containsString("A resource of this type and name already exists"));
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class Group method listUsersReflectsAddRemove.
@Test
@DisplayName("list-users reflects adding and removing a user")
void listUsersReflectsAddRemove() throws IOException {
TestUser groupCreator = TestUser.chooseTestUser();
groupCreator.login();
// `terra group create --name=$name`
String name = SamGroups.randomGroupName();
TestCommand.runCommandExpectSuccess("group", "create", "--name=" + name);
// track the group so we can clean it up in case this test method fails
trackedGroups.trackGroup(name, groupCreator);
// `terra group add-user --name=$name --email=$email --policy=MEMBER`
TestUser groupMember = TestUser.chooseTestUserWhoIsNot(groupCreator);
TestCommand.runCommandExpectSuccess("group", "add-user", "--name=" + name, "--email=" + groupMember.email, "--policy=MEMBER");
// check that group member is included in the list-users output with one policy
expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.MEMBER);
// `terra group add-user --name=$name --email=$email --policy=ADMIN`
TestCommand.runCommandExpectSuccess("group", "add-user", "--name=" + name, "--email=" + groupMember.email, "--policy=ADMIN");
// check that group member is included in the list-users output with two policies
expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.MEMBER, GroupPolicy.ADMIN);
// `terra group describe --name=$name`
UFGroup groupDescribed = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + name);
assertEquals(2, groupDescribed.numMembers, "group describe shows two members");
// `terra group remove-user --name=$name --email=$email --policy=MEMBER`
TestCommand.runCommandExpectSuccess("group", "remove-user", "--name=" + name, "--email=" + groupMember.email, "--policy=MEMBER");
// check that group member is included in the list-users output with one policy
expectListedMemberWithPolicies(name, groupMember.email, GroupPolicy.ADMIN);
// `terra group remove-user --name=$name --email=$email --policy=ADMIN`
TestCommand.runCommandExpectSuccess("group", "remove-user", "--name=" + name, "--email=" + groupMember.email, "--policy=ADMIN");
// check that group member is no longer included in the list-users output
Optional<UFGroupMember> listedGroupMember = listMembersWithEmail(name, groupMember.email);
assertTrue(listedGroupMember.isEmpty(), "test user is no longer included in members list");
// check that the group creator is included in the list-users output
expectListedMemberWithPolicies(name, groupCreator.email, GroupPolicy.ADMIN);
// `terra group delete --name=$name`
TestCommand.runCommandExpectSuccess("group", "delete", "--name=" + name, "--quiet");
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class Group method listDescribeUsersReflectCreateDelete.
@Test
@DisplayName("list, describe, list-users reflect creating and deleting a group")
void listDescribeUsersReflectCreateDelete() throws IOException {
TestUser testUser = TestUser.chooseTestUser();
testUser.login();
// `terra group create --name=$name`
String name = SamGroups.randomGroupName();
UFGroup groupCreated = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "create", "--name=" + name);
// track the group so we can clean it up in case this test method fails
trackedGroups.trackGroup(name, testUser);
// check that the name and email match
assertEquals(name, groupCreated.name, "group name matches after create");
assertThat("group email contains the name", groupCreated.email, CoreMatchers.containsString(name));
assertThat("group creator is an admin", groupCreated.currentUserPolicies.contains(GroupPolicy.ADMIN));
// `terra group list-users --name=$name`
// check that the group creator is included in the list and is an admin
expectListedMemberWithPolicies(name, testUser.email, GroupPolicy.ADMIN);
// `terra group list`
List<UFGroup> groupList = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
}, "group", "list");
// check that the listed group matches the created one
Optional<UFGroup> matchedGroup = groupList.stream().filter(listedGroup -> listedGroup.name.equals(name)).findAny();
assertTrue(matchedGroup.isPresent(), "group appears in list after create");
assertEquals(name, matchedGroup.get().name, "group name matches list output after create");
assertEquals(groupCreated.email, matchedGroup.get().email, "group email matches list output after create");
assertTrue(matchedGroup.get().currentUserPolicies.contains(GroupPolicy.ADMIN), "group policies for current user matches list output after create");
// `terra group describe --name=$name`
UFGroup groupDescribed = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + name);
// check that the described group matches the created one
assertEquals(name, groupDescribed.name, "group name matches describe output after create");
assertEquals(groupCreated.email, groupDescribed.email, "group email matches describe output after create");
assertTrue(groupDescribed.currentUserPolicies.contains(GroupPolicy.ADMIN), "group policies for current user matches describe output after create");
assertEquals(1, groupDescribed.numMembers, "group # members matches describe output after create");
// `terra group delete --name=$name`
TestCommand.runCommandExpectSuccess("group", "delete", "--name=" + name, "--quiet");
// `terra group list`
groupList = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
}, "group", "list");
// check that the group is not included in the list output
matchedGroup = groupList.stream().filter(listedGroup -> listedGroup.name.equals(name)).findAny();
assertTrue(matchedGroup.isEmpty(), "group does not appear in list after delete");
}
Aggregations