Search in sources :

Example 6 with TestUser

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

Example 7 with TestUser

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

Example 8 with TestUser

use of harness.TestUser in project terra-cli by DataBiosphere.

the class Nextflow method helloWorld.

@Test
@DisplayName("nextflow run hello")
void helloWorld() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUserWithSpendAccess();
    testUser.login();
    // create a workspace
    int exitCode = TestBashScript.runScript("CreateWorkspace.sh");
    assertEquals(0, exitCode, "workspace created without errors");
    // run the script that runs the NF hello world workflow
    exitCode = TestBashScript.runScript("NextflowHelloWorld.sh");
    // check that the NF script ran successfully
    assertEquals(0, exitCode, "script completed without errors");
    // check that the NF output includes the "Hello world!" string that indicates the workflow ran
    String scriptOutput = Files.readString(TestBashScript.getOutputFilePath("nextflowHelloWorld_stdout.txt"), StandardCharsets.UTF_8);
    assertThat("nextflow output includes the hello world string", scriptOutput, CoreMatchers.containsString("Hello world!"));
}
Also used : TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with TestUser

use of harness.TestUser in project terra-cli by DataBiosphere.

the class AuthLoginLogout method loginTestUser.

@Test
@DisplayName("test user login updates global context")
void loginTestUser() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUser();
    testUser.login();
    // check that the credential exists in the store on disk
    DataStore<StoredCredential> dataStore = TestUser.getCredentialStore();
    assertEquals(1, dataStore.keySet().size(), "credential store only contains one entry");
    assertTrue(dataStore.containsKey(GoogleOauth.CREDENTIAL_STORE_KEY), "credential store contains hard-coded single user key");
    StoredCredential storedCredential = dataStore.get(GoogleOauth.CREDENTIAL_STORE_KEY);
    assertThat(storedCredential.getAccessToken(), CoreMatchers.not(emptyOrNullString()));
    // check that the current user in the global context = the test user
    Optional<User> currentUser = Context.getUser();
    assertTrue(currentUser.isPresent(), "current user set in global context");
    assertThat("test user email matches the current user set in global context", testUser.email, equalToIgnoringCase(currentUser.get().getEmail()));
}
Also used : TestUser(harness.TestUser) User(bio.terra.cli.businessobject.User) StoredCredential(com.google.api.client.auth.oauth2.StoredCredential) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with TestUser

use of harness.TestUser in project terra-cli by DataBiosphere.

the class AuthStatus method authStatusWhenLoggedIn.

@Test
@DisplayName("auth status includes user email and says logged in")
void authStatusWhenLoggedIn() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUser();
    testUser.login();
    // `terra auth status --format=json`
    UFAuthStatus authStatus = TestCommand.runAndParseCommandExpectSuccess(UFAuthStatus.class, "auth", "status");
    // check that it says logged in and includes the user & proxy emails
    assertThat("auth status email matches test user", authStatus.userEmail, equalToIgnoringCase(testUser.email));
    assertThat("auth status includes proxy group email", authStatus.proxyGroupEmail, CoreMatchers.not(emptyOrNullString()));
    assertTrue(VALID_EMAIL_ADDRESS.matcher(authStatus.proxyGroupEmail).find(), "proxy group email is a valid email");
    assertThat("auth status without workspace defined does not include pet SA email", authStatus.serviceAccountEmail, CoreMatchers.is(emptyOrNullString()));
    assertTrue(authStatus.loggedIn, "auth status indicates user is logged in");
}
Also used : TestUser(harness.TestUser) UFAuthStatus(bio.terra.cli.serialization.userfacing.UFAuthStatus) 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