use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project terra-workspace-manager by DataBiosphere.
the class ClientTestUtils method getClientForTestRunnerSA.
/**
* Build the Workspace Manager Service API client object for the given server specification. It is
* setting the access token for the Test Runner SA specified in the given server specification.
*
* <p>A Test Runner SA is a GCP SA with appropriate permissions / scopes to run all the client
* tests within this repo. For example, to run resiliency tests against K8S infrastructure, you'll
* need a SA powerful enough to do things like list, read, and update.
*
* @param server the server we are testing against
* @return the API client object
*/
public static ApiClient getClientForTestRunnerSA(ServerSpecification server) throws IOException {
if (server.testRunnerServiceAccount == null) {
throw new IllegalArgumentException("Workspace Manager Service client service account is required");
}
// refresh the client service account token
GoogleCredentials serviceAccountCredential = AuthenticationUtils.getServiceAccountCredential(server.testRunnerServiceAccount, AuthenticationUtils.userLoginScopes);
AccessToken accessToken = AuthenticationUtils.getAccessToken(serviceAccountCredential);
logger.debug("Generated access token for workspace manager service client SA: {}", server.testRunnerServiceAccount.name);
return buildClient(accessToken, server);
}
use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project terra-workspace-manager by DataBiosphere.
the class ClientTestUtils method getClientForTestUser.
/**
* Build the Workspace Manager API client object for the given test user and server
* specifications. The test user's token is always refreshed
*
* @param testUser the test user whose credentials are supplied to the API client object
* @param server the server we are testing against
* @return the API client object for this user
*/
public static ApiClient getClientForTestUser(TestUserSpecification testUser, ServerSpecification server) throws IOException {
AccessToken accessToken = null;
// this is useful if the caller wants to make ONLY unauthenticated calls
if (testUser != null) {
logger.debug("Fetching credentials and building Workspace Manager ApiClient object for test user: {}", testUser.name);
GoogleCredentials userCredential = AuthenticationUtils.getDelegatedUserCredential(testUser, TEST_USER_SCOPES);
accessToken = AuthenticationUtils.getAccessToken(userCredential);
}
return buildClient(accessToken, server);
}
use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project terra-workspace-manager by DataBiosphere.
the class SamClientUtils method getSamApiClient.
private static ApiClient getSamApiClient(TestUserSpecification testUser, ServerSpecification server) throws Exception {
AccessToken accessToken = null;
// this is useful if the caller wants to make ONLY unauthenticated calls
if (testUser != null) {
logger.debug("Fetching credentials and building Sam ApiClient object for test user: {}", testUser.name);
GoogleCredentials userCredential = AuthenticationUtils.getDelegatedUserCredential(testUser, ClientTestUtils.TEST_USER_SCOPES);
accessToken = AuthenticationUtils.getAccessToken(userCredential);
}
return buildSamClient(accessToken, server);
}
use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project java-bigtable by googleapis.
the class BigtableChannelPrimerTest method testErrorsAreLoggedForBasic.
@Test
public void testErrorsAreLoggedForBasic() {
BigtableChannelPrimer basicPrimer = BigtableChannelPrimer.create(OAuth2Credentials.create(new AccessToken(TOKEN_VALUE, null)), "fake-project", "fake-instance", "fake-app-profile", ImmutableList.<String>of());
ManagedChannel channel = Mockito.mock(ManagedChannel.class, new ThrowsException(new UnsupportedOperationException()));
primer.primeChannel(channel);
assertThat(logHandler.logs).hasSize(1);
for (LogRecord log : logHandler.logs) {
assertThat(log.getMessage()).contains("Unexpected");
}
}
use of com.microsoft.identity.common.internal.providers.oauth2.AccessToken in project hadoop-connectors by GoogleCloudDataproc.
the class HadoopCredentialsConfigurationTest method userCredentials_credentialFactory_noNewRefreshToken.
@Test
public void userCredentials_credentialFactory_noNewRefreshToken() throws IOException {
// GIVEN
String initialRefreshToken = "FAKE_REFRESH_TOKEN";
String tokenServerUrl = "http://localhost/token";
configuration.set(getConfigKey(TOKEN_SERVER_URL_SUFFIX), tokenServerUrl);
configuration.setEnum(getConfigKey(AUTHENTICATION_TYPE_SUFFIX), AuthenticationType.USER_CREDENTIALS);
configuration.set(getConfigKey(AUTH_REFRESH_TOKEN_SUFFIX), initialRefreshToken);
configuration.set(getConfigKey(AUTH_CLIENT_ID_SUFFIX), "FAKE_CLIENT_ID");
configuration.set(getConfigKey(AUTH_CLIENT_SECRET_SUFFIX), "FAKE_CLIENT_SECRET");
long expireInSec = 300L;
String accessTokenAsString = "SlAV32hkKG";
TokenResponse tokenResponse = new TokenResponse().setAccessToken(accessTokenAsString).setExpiresInSeconds(expireInSec);
MockHttpTransport transport = mockTransport(jsonDataResponse(tokenResponse));
// WHEN
GoogleCredentials credentials = getCredentials(transport);
credentials.refresh();
// THEN
assertThat(credentials).isInstanceOf(UserCredentials.class);
UserCredentials userCredentials = (UserCredentials) credentials;
assertThat(userCredentials.getClientId()).isEqualTo("FAKE_CLIENT_ID");
assertThat(userCredentials.getClientSecret()).isEqualTo("FAKE_CLIENT_SECRET");
AccessToken accessToken = userCredentials.getAccessToken();
assertThat(accessToken).isNotNull();
// To avoid any timebase issue, we test a time range instead
assertThat(accessToken.getExpirationTime()).isGreaterThan(Date.from(Instant.now().plusSeconds(expireInSec - 10)));
assertThat(accessToken.getExpirationTime()).isLessThan(Date.from(Instant.now().plusSeconds(expireInSec + 10)));
String refreshToken = userCredentials.getRefreshToken();
assertThat(refreshToken).isEqualTo(initialRefreshToken);
}
Aggregations