Skip to content

Commit 9c1e827

Browse files
committed
address review comments
1 parent ac8cf3e commit 9c1e827

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

sdk-platform-java/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,10 @@ public Credentials getScopedCredentials() {
666666
&& ((GoogleCredentials) credentials).createScopedRequired()) {
667667
credentialsToReturn = ((GoogleCredentials) credentials).createScoped(getScopes());
668668
}
669-
if (getUseJwtAccessWithScope() && credentialsToReturn instanceof ServiceAccountCredentials) {
669+
if (credentialsToReturn instanceof ServiceAccountCredentials) {
670670
credentialsToReturn =
671-
((ServiceAccountCredentials) credentialsToReturn).createWithUseJwtAccessWithScope(true);
671+
((ServiceAccountCredentials) credentialsToReturn)
672+
.createWithUseJwtAccessWithScope(getUseJwtAccessWithScope());
672673
}
673674
return credentialsToReturn;
674675
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ void testIsValidUniverseDomain_userUniverseDomainConfig_nonGDUCredentials() thro
631631
}
632632

633633
@Test
634-
void testGetScopedCredentials_enablesSelfSignedJwtForServiceAccount() {
634+
void testGetScopedCredentials_useJwtAccessWithScope_enablesByDefault() {
635635
TestServiceOptions options =
636636
TestServiceOptions.newBuilder()
637637
.setProjectId("project-id")
@@ -643,7 +643,7 @@ void testGetScopedCredentials_enablesSelfSignedJwtForServiceAccount() {
643643
}
644644

645645
@Test
646-
void testGetScopedCredentials_optsOutSelfSignedJwt() {
646+
void testGetScopedCredentials_useJwtAccessWithScope_canBeDisabled() {
647647
TestServiceOptions options =
648648
new TestServiceOptions.Builder()
649649
.setProjectId("project-id")
@@ -655,6 +655,21 @@ void testGetScopedCredentials_optsOutSelfSignedJwt() {
655655
assertThat(((ServiceAccountCredentials) scoped).getUseJwtAccessWithScope()).isFalse();
656656
}
657657

658+
@Test
659+
void testGetScopedCredentials_useJwtAccessWithScope_overridesCredentials() {
660+
ServiceAccountCredentials trueCredentials =
661+
((ServiceAccountCredentials) credentials).createWithUseJwtAccessWithScope(true);
662+
TestServiceOptions options =
663+
new TestServiceOptions.Builder()
664+
.setProjectId("project-id")
665+
.setCredentials(trueCredentials)
666+
.setUseJwtAccessWithScope(false)
667+
.build();
668+
com.google.auth.Credentials scoped = options.getScopedCredentials();
669+
assertThat(scoped).isInstanceOf(ServiceAccountCredentials.class);
670+
assertThat(((ServiceAccountCredentials) scoped).getUseJwtAccessWithScope()).isFalse();
671+
}
672+
658673
private HttpResponse createHttpResponseWithHeader(final Multimap<String, String> headers)
659674
throws Exception {
660675
HttpTransport mockHttpTransport =

0 commit comments

Comments
 (0)