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