Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public Credentials getCredentials() throws IOException {
.setPrivateKey(serviceAccount.getPrivateKey())
.setPrivateKeyId(serviceAccount.getPrivateKeyId())
.setQuotaProjectId(serviceAccount.getQuotaProjectId())
.setUniverseDomain(serviceAccount.getUniverseDomain())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,51 @@ void serviceAccountReplacedWithJwtTokens() throws Exception {
assertThat(jwtCreds.getClientEmail()).isEqualTo(serviceAccountCredentials.getClientEmail());
assertThat(jwtCreds.getPrivateKeyId()).isEqualTo(serviceAccountCredentials.getPrivateKeyId());
assertThat(jwtCreds.getPrivateKey()).isEqualTo(serviceAccountCredentials.getPrivateKey());
assertThat(jwtCreds.getUniverseDomain()).isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
}

@Test
void serviceAccountReplacedWithJwtTokens_setEmptyDomain() throws Exception {
ServiceAccountCredentials serviceAccountCredentials =
CreateServiceAccountCredentials().toBuilder().setUniverseDomain("").build();

GoogleCredentialsProvider provider =
GoogleCredentialsProvider.newBuilder()
.setScopesToApply(ImmutableList.of("scope1", "scope2"))
.setJwtEnabledScopes(ImmutableList.of("scope1"))
.setOAuth2Credentials(serviceAccountCredentials)
.build();

Credentials credentials = provider.getCredentials();
assertThat(credentials).isInstanceOf(ServiceAccountJwtAccessCredentials.class);
ServiceAccountJwtAccessCredentials jwtCreds = (ServiceAccountJwtAccessCredentials) credentials;
assertThat(jwtCreds.getClientId()).isEqualTo(serviceAccountCredentials.getClientId());
assertThat(jwtCreds.getClientEmail()).isEqualTo(serviceAccountCredentials.getClientEmail());
assertThat(jwtCreds.getPrivateKeyId()).isEqualTo(serviceAccountCredentials.getPrivateKeyId());
assertThat(jwtCreds.getPrivateKey()).isEqualTo(serviceAccountCredentials.getPrivateKey());
assertThat(jwtCreds.getUniverseDomain()).isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
}

@Test
void serviceAccountReplacedWithJwtTokens_customUniverseDomain() throws Exception {
ServiceAccountCredentials serviceAccountCredentials =
CreateServiceAccountCredentials().toBuilder().setUniverseDomain("example.com").build();

GoogleCredentialsProvider provider =
GoogleCredentialsProvider.newBuilder()
.setScopesToApply(ImmutableList.of("scope1", "scope2"))
.setJwtEnabledScopes(ImmutableList.of("scope1"))
.setOAuth2Credentials(serviceAccountCredentials)
.build();

Credentials credentials = provider.getCredentials();
assertThat(credentials).isInstanceOf(ServiceAccountJwtAccessCredentials.class);
ServiceAccountJwtAccessCredentials jwtCreds = (ServiceAccountJwtAccessCredentials) credentials;
assertThat(jwtCreds.getClientId()).isEqualTo(serviceAccountCredentials.getClientId());
assertThat(jwtCreds.getClientEmail()).isEqualTo(serviceAccountCredentials.getClientEmail());
assertThat(jwtCreds.getPrivateKeyId()).isEqualTo(serviceAccountCredentials.getPrivateKeyId());
assertThat(jwtCreds.getPrivateKey()).isEqualTo(serviceAccountCredentials.getPrivateKey());
assertThat(jwtCreds.getUniverseDomain()).isEqualTo("example.com");
}

@Test
Expand All @@ -94,6 +139,8 @@ void noJwtWithoutScopeMatch() throws Exception {
assertThat(serviceAccountCredentials2.getPrivateKey())
.isEqualTo(serviceAccountCredentials.getPrivateKey());
assertThat(serviceAccountCredentials2.getScopes()).containsExactly("scope1", "scope2");
assertThat(serviceAccountCredentials2.getUniverseDomain())
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
}

@Test
Expand All @@ -120,5 +167,7 @@ void useJwtAccessWithScope() throws Exception {
assertThat(serviceAccountCredentials2.getPrivateKey())
.isEqualTo(serviceAccountCredentials.getPrivateKey());
assertTrue(serviceAccountCredentials2.getUseJwtAccessWithScope());
assertThat(serviceAccountCredentials2.getUniverseDomain())
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
}
}
Loading