Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix service account credentials createScopedRequired #601

Merged
merged 2 commits into from Mar 18, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -561,6 +561,12 @@ public static ServiceAccountCredentials fromStream(
fileType, SERVICE_ACCOUNT_FILE_TYPE));
}

/** Returns whether the scopes are empty, meaning createScoped must be called before use. */
@Override
public boolean createScopedRequired() {
return scopes.isEmpty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think without having defaultScopes.isEmpty() here as well, the Client Library for Storage will never use self-signed JWTs. And there may be more APIs like this.

This can be fixed in a future PR, however.

}

/**
* Refreshes the OAuth2 access token by getting a new access token using a JSON Web Token (JWT).
*/
Expand Down
Expand Up @@ -479,12 +479,12 @@ public void createdScoped_defaultScopes() throws IOException {
}

@Test
public void createScopedRequired_emptyScopes_false() throws IOException {
public void createScopedRequired_emptyScopes() throws IOException {
GoogleCredentials credentials =
ServiceAccountCredentials.fromPkcs8(
CLIENT_ID, CLIENT_EMAIL, PRIVATE_KEY_PKCS8, PRIVATE_KEY_ID, EMPTY_SCOPES);

assertFalse(credentials.createScopedRequired());
assertTrue(credentials.createScopedRequired());
}

@Test
Expand Down