Search in sources :

Example 11 with TestUser

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");
}
Also used : TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with TestUser

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);
    }
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) UFGroupMember(bio.terra.cli.serialization.userfacing.UFGroupMember) Arrays(java.util.Arrays) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) TestCommand(harness.TestCommand) SamGroups(harness.utils.SamGroups) TestUser(harness.TestUser) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) DisplayName(org.junit.jupiter.api.DisplayName) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) GroupPolicy(bio.terra.cli.service.SamService.GroupPolicy) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ClearContextUnit(harness.baseclasses.ClearContextUnit) Optional(java.util.Optional) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Tag(org.junit.jupiter.api.Tag) TypeReference(com.fasterxml.jackson.core.type.TypeReference) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 13 with TestUser

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();
}
Also used : UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) Map(java.util.Map) TestUser(harness.TestUser) AfterAll(org.junit.jupiter.api.AfterAll)

Example 14 with TestUser

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);
    }
}
Also used : Arrays(java.util.Arrays) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) TestCommand(harness.TestCommand) SamGroups(harness.utils.SamGroups) TestUser(harness.TestUser) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) DisplayName(org.junit.jupiter.api.DisplayName) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) ClearContextUnit(harness.baseclasses.ClearContextUnit) UFSpendProfileUser(bio.terra.cli.serialization.userfacing.UFSpendProfileUser) Optional(java.util.Optional) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Tag(org.junit.jupiter.api.Tag) TypeReference(com.fasterxml.jackson.core.type.TypeReference) SpendProfilePolicy(bio.terra.cli.service.SpendProfileManagerService.SpendProfilePolicy) UFGroup(bio.terra.cli.serialization.userfacing.UFGroup) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 15 with TestUser

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");
}
Also used : TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

TestUser (harness.TestUser)30 Test (org.junit.jupiter.api.Test)28 DisplayName (org.junit.jupiter.api.DisplayName)27 UFWorkspace (bio.terra.cli.serialization.userfacing.UFWorkspace)7 UFGroup (bio.terra.cli.serialization.userfacing.UFGroup)5 UFStatus (bio.terra.cli.serialization.userfacing.UFStatus)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 TestCommand (harness.TestCommand)5 IOException (java.io.IOException)5 List (java.util.List)5 UFWorkspaceLight (bio.terra.cli.serialization.userfacing.UFWorkspaceLight)4 UFWorkspaceUser (bio.terra.cli.serialization.userfacing.UFWorkspaceUser)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ClearContextUnit (harness.baseclasses.ClearContextUnit)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Matchers.emptyString (org.hamcrest.Matchers.emptyString)4 AfterAll (org.junit.jupiter.api.AfterAll)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4