Search in sources :

Example 1 with User

use of bio.terra.cli.businessobject.User 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 2 with User

use of bio.terra.cli.businessobject.User in project terra-cli by DataBiosphere.

the class Status method execute.

/**
 * Populate the current user in the global context and print out a subset of the TerraUser
 * properties.
 */
@Override
protected void execute() {
    // check if current user is defined
    Optional<User> currentUserOpt = Context.getUser();
    UFAuthStatus authStatusReturnValue;
    if (currentUserOpt.isEmpty()) {
        authStatusReturnValue = UFAuthStatus.createWhenCurrentUserIsUndefined();
    } else {
        User currentUser = currentUserOpt.get();
        authStatusReturnValue = UFAuthStatus.createWhenCurrentUserIsDefined(currentUser.getEmail(), currentUser.getProxyGroupEmail(), currentUser.getPetSaEmail(), !currentUser.requiresReauthentication());
    }
    formatOption.printReturnValue(authStatusReturnValue, this::printText);
}
Also used : User(bio.terra.cli.businessobject.User) UFAuthStatus(bio.terra.cli.serialization.userfacing.UFAuthStatus)

Example 3 with User

use of bio.terra.cli.businessobject.User in project terra-cli by DataBiosphere.

the class AuthLoginLogout method logoutTestUser.

@Test
@DisplayName("test user logout updates global context")
void logoutTestUser() throws IOException {
    // select a test user and login
    TestUser testUser = TestUser.chooseTestUser();
    testUser.login();
    // `terra auth revoke`
    TestCommand.runCommandExpectSuccess("auth", "revoke");
    // check that the credential store on disk is empty
    DataStore<StoredCredential> dataStore = TestUser.getCredentialStore();
    assertEquals(0, dataStore.keySet().size(), "credential store is empty");
    // read the global context in from disk again to check what got persisted
    // check that the current user in the global context is unset
    Optional<User> currentUser = Context.getUser();
    assertFalse(currentUser.isPresent(), "current user unset in global context");
}
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 4 with User

use of bio.terra.cli.businessobject.User in project terra-cli by DataBiosphere.

the class CheckAccess method printText.

/**
 * Print this command's output in text format.
 */
public void printText(boolean returnValue) {
    User currentUser = Context.requireUser();
    OUT.println("User's pet SA in their proxy group (" + currentUser.getProxyGroupEmail() + ") DOES " + (returnValue ? "" : "NOT ") + "have access to this resource.");
}
Also used : User(bio.terra.cli.businessobject.User)

Aggregations

User (bio.terra.cli.businessobject.User)4 StoredCredential (com.google.api.client.auth.oauth2.StoredCredential)2 TestUser (harness.TestUser)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 UFAuthStatus (bio.terra.cli.serialization.userfacing.UFAuthStatus)1