Skip to content

Commit 7ed18f2

Browse files
committed
add testing
1 parent e3b6176 commit 7ed18f2

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

gax-java/gax/src/test/java/com/google/api/gax/core/GoogleCredentialsProviderTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,29 @@ void serviceAccountReplacedWithJwtTokens() throws Exception {
6868
assertThat(jwtCreds.getClientEmail()).isEqualTo(serviceAccountCredentials.getClientEmail());
6969
assertThat(jwtCreds.getPrivateKeyId()).isEqualTo(serviceAccountCredentials.getPrivateKeyId());
7070
assertThat(jwtCreds.getPrivateKey()).isEqualTo(serviceAccountCredentials.getPrivateKey());
71+
assertThat(jwtCreds.getUniverseDomain()).isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
72+
}
73+
74+
@Test
75+
void serviceAccountReplacedWithJwtTokens_customUniverseDomain() throws Exception {
76+
ServiceAccountCredentials serviceAccountCredentials =
77+
CreateServiceAccountCredentials().toBuilder().setUniverseDomain("example.com").build();
78+
79+
GoogleCredentialsProvider provider =
80+
GoogleCredentialsProvider.newBuilder()
81+
.setScopesToApply(ImmutableList.of("scope1", "scope2"))
82+
.setJwtEnabledScopes(ImmutableList.of("scope1"))
83+
.setOAuth2Credentials(serviceAccountCredentials)
84+
.build();
85+
86+
Credentials credentials = provider.getCredentials();
87+
assertThat(credentials).isInstanceOf(ServiceAccountJwtAccessCredentials.class);
88+
ServiceAccountJwtAccessCredentials jwtCreds = (ServiceAccountJwtAccessCredentials) credentials;
89+
assertThat(jwtCreds.getClientId()).isEqualTo(serviceAccountCredentials.getClientId());
90+
assertThat(jwtCreds.getClientEmail()).isEqualTo(serviceAccountCredentials.getClientEmail());
91+
assertThat(jwtCreds.getPrivateKeyId()).isEqualTo(serviceAccountCredentials.getPrivateKeyId());
92+
assertThat(jwtCreds.getPrivateKey()).isEqualTo(serviceAccountCredentials.getPrivateKey());
93+
assertThat(jwtCreds.getUniverseDomain()).isEqualTo("example.com");
7194
}
7295

7396
@Test
@@ -94,6 +117,8 @@ void noJwtWithoutScopeMatch() throws Exception {
94117
assertThat(serviceAccountCredentials2.getPrivateKey())
95118
.isEqualTo(serviceAccountCredentials.getPrivateKey());
96119
assertThat(serviceAccountCredentials2.getScopes()).containsExactly("scope1", "scope2");
120+
assertThat(serviceAccountCredentials2.getUniverseDomain())
121+
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
97122
}
98123

99124
@Test
@@ -120,5 +145,7 @@ void useJwtAccessWithScope() throws Exception {
120145
assertThat(serviceAccountCredentials2.getPrivateKey())
121146
.isEqualTo(serviceAccountCredentials.getPrivateKey());
122147
assertTrue(serviceAccountCredentials2.getUseJwtAccessWithScope());
148+
assertThat(serviceAccountCredentials2.getUniverseDomain())
149+
.isEqualTo(Credentials.GOOGLE_DEFAULT_UNIVERSE);
123150
}
124151
}

0 commit comments

Comments
 (0)