From 7ddac43c418bb8b0cc3fd8d4f9d8752ad65bd842 Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Thu, 18 Mar 2021 14:47:06 -0700 Subject: [PATCH] fix: follow up fix service account credentials createScopedRequired (#605) --- .../google/auth/oauth2/ServiceAccountCredentials.java | 2 +- .../auth/oauth2/ServiceAccountCredentialsTest.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java index 741a4b27d..c0b3cab98 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java @@ -564,7 +564,7 @@ public static ServiceAccountCredentials fromStream( /** Returns whether the scopes are empty, meaning createScoped must be called before use. */ @Override public boolean createScopedRequired() { - return scopes.isEmpty(); + return scopes.isEmpty() && defaultScopes.isEmpty(); } /** diff --git a/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java index 604f68c60..e75a70257 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java @@ -488,7 +488,7 @@ public void createScopedRequired_emptyScopes() throws IOException { } @Test - public void createScopedRequired_nonEmptyScopes_false() throws IOException { + public void createScopedRequired_nonEmptyScopes() throws IOException { GoogleCredentials credentials = ServiceAccountCredentials.fromPkcs8( CLIENT_ID, CLIENT_EMAIL, PRIVATE_KEY_PKCS8, PRIVATE_KEY_ID, SCOPES); @@ -496,6 +496,15 @@ public void createScopedRequired_nonEmptyScopes_false() throws IOException { assertFalse(credentials.createScopedRequired()); } + @Test + public void createScopedRequired_nonEmptyDefaultScopes() throws IOException { + GoogleCredentials credentials = + ServiceAccountCredentials.fromPkcs8( + CLIENT_ID, CLIENT_EMAIL, PRIVATE_KEY_PKCS8, PRIVATE_KEY_ID, null, SCOPES); + + assertFalse(credentials.createScopedRequired()); + } + @Test public void fromJSON_getProjectId() throws IOException { MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory();