Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arithmetic1728 committed Jul 8, 2021
1 parent 9273ff3 commit bcf9304
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Expand Up @@ -985,14 +985,11 @@ public void getRequestMetadata(
/** Provide the request metadata by putting an access JWT directly in the metadata. */
@Override
public Map<String, List<String>> getRequestMetadata(URI uri) throws IOException {
if (createScopedRequired()) {
if (!useJWTAccessWithScope) {
throw new IOException(
"Scopes are not configured for service account. Specify the scopes"
+ " by calling createScoped or passing scopes to constructor.");
} else if (uri == null) {
throw new IOException("Scopes and uri are not configured for service account.");
}
if (scopes.isEmpty() && defaultScopes.isEmpty() && uri == null) {
throw new IOException(
"Scopes and uri are not configured for service account. Either pass uri"
+ " to getRequestMetadata, or specify the scopes"
+ " by calling createScoped or passing scopes to constructor.");
}
if (useJWTAccessWithScope) {
JwtCredentials jwtCredentials = createSelfSignedJwtCredentials(uri);
Expand Down
Expand Up @@ -419,12 +419,12 @@ public void createdScoped_enablesAccessTokens() throws IOException {
null);

try {
credentials.getRequestMetadata(CALL_URI);
fail("Should not be able to get token without scopes");
credentials.getRequestMetadata(null);
fail("Should not be able to get token without scopes, defaultScopes and uri");
} catch (IOException e) {
assertTrue(
"expected to fail with exception",
e.getMessage().contains("Scopes are not configured for service account"));
e.getMessage().contains("Scopes and uri are not configured for service account"));
}

GoogleCredentials scopedCredentials = credentials.createScoped(SCOPES);
Expand Down

0 comments on commit bcf9304

Please sign in to comment.