use of harness.TestUser in project terra-cli by DataBiosphere.
the class Group method onlyAdminCanModifyGroup.
@Test
@DisplayName("only an admin, not a member, can modify a group")
void onlyAdminCanModifyGroup() 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`
TestUser groupMember = TestUser.chooseTestUserWhoIsNot(groupCreator);
TestCommand.runCommandExpectSuccess("group", "add-user", "--name=" + name, "--email=" + groupMember.email, "--policy=MEMBER");
// `terra group delete --name=$name` as member
groupMember.login();
TestCommand.runCommandExpectExitCode(2, "group", "delete", "--name=" + name, "--quiet");
// `terra group add-user --email=$email --policy=ADMIN` as member
TestCommand.runCommandExpectExitCode(2, "group", "add-user", "--name=" + name, "--email=" + groupMember.email, "--policy=ADMIN");
// `terra group remove-user --email=$email --policy=MEMBER` as member
TestCommand.runCommandExpectExitCode(2, "group", "remove-user", "--name=" + name, "--email=" + groupMember.email, "--policy=MEMBER");
// `terra group delete --name=$name` as admin
groupCreator.login();
TestCommand.runCommandExpectSuccess("group", "delete", "--name=" + name, "--quiet");
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class Group method cliTestersGroupMembership.
@Test
@DisplayName("cli-testers group includes the appropriate test users")
void cliTestersGroupMembership() throws IOException {
// NOTE: this test is checking that test users and spend access are setup as expected for CLI
// testing. it's not really testing CLI functionality specifically.
TestUser groupAdmin = TestUser.chooseTestUserWithOwnerAccess();
groupAdmin.login();
List<TestUser> expectedGroupMembers = TestUser.getTestUsers().stream().filter(testUser -> testUser.spendEnabled.equals(TestUser.SpendEnabled.CLI_TEST_USERS_GROUP)).collect(Collectors.toList());
for (TestUser expectedGroupMember : expectedGroupMembers) {
// check that the test user is included in the list-users output
expectListedMemberWithPolicies(TestUser.CLI_TEST_USERS_GROUP_NAME, expectedGroupMember.email, GroupPolicy.MEMBER);
}
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class SpendProfileUser method cleanupOnce.
@AfterAll
void cleanupOnce() throws IOException, InterruptedException {
spendProfileOwner.login();
// try to disable spend for each group that was created by a method in this class
for (Map.Entry<String, TestUser> groupNameToCreator : trackedGroups.getTrackedGroups().entrySet()) {
UFGroup groupInfo = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + groupNameToCreator.getKey());
TestCommand.runCommand("spend", "disable", "--email=" + groupInfo.email, "--policy=USER");
TestCommand.runCommand("spend", "disable", "--email=" + groupInfo.email, "--policy=OWNER");
}
// then try to delete the groups
trackedGroups.deleteAllTrackedGroups();
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class SpendProfileUser method testUserSpendProfileMembership.
@Test
@DisplayName("spend profile includes cli-testers group and the appropriate test users")
void testUserSpendProfileMembership() throws IOException {
// NOTE: this test is checking that test users and spend access are setup as expected for CLI
// testing. it's not really testing CLI functionality specifically.
// only an owner on the spend profile can list enabled users
TestUser spendProfileOwner = TestUser.chooseTestUserWithOwnerAccess();
spendProfileOwner.login();
// check that the cli-testers group is included in the list-users output
UFGroup cliTestersGroup = TestCommand.runAndParseCommandExpectSuccess(UFGroup.class, "group", "describe", "--name=" + TestUser.CLI_TEST_USERS_GROUP_NAME);
expectListedUserWithPolicies(cliTestersGroup.email, SpendProfilePolicy.USER);
// check that each test user who is enabled on the spend profile directly, is included in the
// list-users output
List<TestUser> expectedSpendUsers = TestUser.getTestUsers().stream().filter(testUser -> testUser.spendEnabled.equals(TestUser.SpendEnabled.DIRECTLY)).collect(Collectors.toList());
for (TestUser expectedSpendUser : expectedSpendUsers) {
expectListedUserWithPolicies(expectedSpendUser.email, SpendProfilePolicy.USER);
}
}
use of harness.TestUser in project terra-cli by DataBiosphere.
the class SpendProfileUser method onlyAdminCanEnableDisable.
@Test
@DisplayName("only users who are an admin on the spend profile can enable and disable others")
void onlyAdminCanEnableDisable() throws IOException {
// get an email to try and add
String testEmail = generateSamGroupForEmail();
// check that none of the test users can enable this email
for (TestUser testUser : TestUser.getTestUsers()) {
if (testUser.spendEnabled.equals(TestUser.SpendEnabled.OWNER)) {
continue;
}
testUser.login();
// `terra spend enable --email=$testEmail --policy=USER`
TestCommand.runCommandExpectExitCode(2, "spend", "enable", "--email=" + testEmail, "--policy=USER");
}
// use a test user that is an owner to grant spend access to the test email
TestUser spendProfileOwner = TestUser.chooseTestUserWithOwnerAccess();
spendProfileOwner.login();
TestCommand.runCommandExpectSuccess("spend", "enable", "--email=" + testEmail, "--policy=USER");
// check that none of the test users can disable this email
for (TestUser testUser : TestUser.getTestUsers()) {
if (testUser.spendEnabled.equals(TestUser.SpendEnabled.OWNER)) {
continue;
}
testUser.login();
// `terra spend disable --email=$testEmail --policy=USER`
TestCommand.runCommandExpectExitCode(2, "spend", "disable", "--email=" + testEmail, "--policy=USER");
}
// use a test user that is an owner to remove spend access for the test email
spendProfileOwner.login();
TestCommand.runCommandExpectSuccess("spend", "disable", "--email=" + testEmail, "--policy=USER");
}
Aggregations