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 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 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!"));
}
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()));
}
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");
}
Aggregations