Skip to content

Commit 320d86c

Browse files
committed
add new test cases to ServiceOptionsTest
1 parent a33e183 commit 320d86c

1 file changed

Lines changed: 43 additions & 2 deletions

File tree

sdk-platform-java/java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ protected TestServiceOptions build() {
285285
}
286286
}
287287

288-
private TestServiceOptions(Builder builder) {
288+
protected TestServiceOptions(Builder builder) {
289289
super(
290290
TestServiceFactory.class,
291291
TestServiceRpcFactory.class,
@@ -337,6 +337,25 @@ public int hashCode() {
337337
}
338338
}
339339

340+
private static class NonSsjwtServiceOptions extends TestServiceOptions {
341+
private static class Builder extends TestServiceOptions.Builder {
342+
@Override
343+
protected NonSsjwtServiceOptions build() {
344+
return new NonSsjwtServiceOptions(this);
345+
}
346+
}
347+
348+
private NonSsjwtServiceOptions(Builder builder) {
349+
super(builder);
350+
}
351+
352+
@Override
353+
protected boolean useSelfSignedJwt() {
354+
return false;
355+
}
356+
}
357+
358+
340359
@Test
341360
public void testBuilder() {
342361
assertSame(credentials, OPTIONS.getCredentials());
@@ -627,7 +646,29 @@ void testIsValidUniverseDomain_userUniverseDomainConfig_nonGDUCredentials() thro
627646
.setUniverseDomain("random.com")
628647
.setCredentials(credentialsNotInGDU)
629648
.build();
630-
assertThat(options.hasValidUniverseDomain()).isTrue();
649+
}
650+
651+
@Test
652+
void testGetScopedCredentials_enablesSelfSignedJwtForServiceAccount() {
653+
TestServiceOptions options =
654+
TestServiceOptions.newBuilder()
655+
.setProjectId("project-id")
656+
.setCredentials(credentials)
657+
.build();
658+
com.google.auth.Credentials scoped = options.getScopedCredentials();
659+
assertThat(scoped).isInstanceOf(ServiceAccountCredentials.class);
660+
}
661+
662+
@Test
663+
void testGetScopedCredentials_optsOutSelfSignedJwt() {
664+
TestServiceOptions options =
665+
new NonSsjwtServiceOptions.Builder()
666+
.setProjectId("project-id")
667+
.setCredentials(credentials)
668+
.build();
669+
com.google.auth.Credentials scoped = options.getScopedCredentials();
670+
assertThat(scoped).isInstanceOf(ServiceAccountCredentials.class);
671+
assertThat(((ServiceAccountCredentials) scoped).getUseJwtAccessWithScope()).isFalse();
631672
}
632673

633674
private HttpResponse createHttpResponseWithHeader(final Multimap<String, String> headers)

0 commit comments

Comments
 (0)