Skip to content

Commit

Permalink
fix: use orginal url as audience for self signed jwt if scheme or hos…
Browse files Browse the repository at this point in the history
…t is null (#642)
  • Loading branch information
arithmetic1728 committed Apr 27, 2021
1 parent 07d6cbc commit b4e6f1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -339,7 +339,7 @@ public boolean hasRequestMetadataOnly() {
*/
@VisibleForTesting
static URI getUriForSelfSignedJWT(URI uri) {
if (uri == null) {
if (uri == null || uri.getScheme() == null || uri.getHost() == null) {
return uri;
}
try {
Expand Down
Expand Up @@ -181,6 +181,20 @@ public void getUriForSelfSignedJWT() {
assertEquals(expected, ServiceAccountJwtAccessCredentials.getUriForSelfSignedJWT(uri));
}

@Test
public void getUriForSelfSignedJWT_noHost() {
URI uri = URI.create("file:foo");
URI expected = URI.create("file:foo");
assertEquals(expected, ServiceAccountJwtAccessCredentials.getUriForSelfSignedJWT(uri));
}

@Test
public void getUriForSelfSignedJWT_forStaticAudience_returnsURI() {
URI uri = URI.create("compute.googleapis.com");
URI expected = URI.create("compute.googleapis.com");
assertEquals(expected, ServiceAccountJwtAccessCredentials.getUriForSelfSignedJWT(uri));
}

@Test
public void hasRequestMetadata_returnsTrue() throws IOException {
Credentials credentials =
Expand Down

0 comments on commit b4e6f1a

Please sign in to comment.