Skip to content

Commit

Permalink
lint and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
aeitzman committed Apr 9, 2024
1 parent 88c6632 commit d0fc130
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected ExternalAccountCredentials(ExternalAccountCredentials.Builder builder)
this.clientId = builder.clientId;
this.clientSecret = builder.clientSecret;

if (builder.tokenUrl == null){
if (builder.tokenUrl == null) {
try {
this.tokenUrl = DEFAULT_TOKEN_URL.replace("{UNIVERSE_DOMAIN}", this.getUniverseDomain());
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,26 @@ public void constructor_builder_defaultTokenUrlwithUniverseDomain() {
assertEquals("https://sts.testdomain.org/v1/token", credentials.getTokenUrl());
}

@Test
public void constructor_builder_getUniverseDomainFails() {
HashMap<String, Object> credentialSource = new HashMap<>();
credentialSource.put("file", "file");

try {
UniverseDomainErrorTestCredentials.newBuilder()
.setHttpTransportFactory(transportFactory)
.setAudience(
"//iam.googleapis.com/locations/global/workforcePools/pool/providers/provider")
.setSubjectTokenType("subjectTokenType")
.setUniverseDomain("testdomain.org")
.build();
fail("Should not be able to continue without exception.");
} catch (IllegalStateException exception) {
assertEquals(
"Error occurred when attempting to retrieve universe domain.", exception.getMessage());
}
}

@Test
public void constructor_builder_subjectTokenTypeEnum() {
HashMap<String, Object> credentialSource = new HashMap<>();
Expand Down Expand Up @@ -1368,4 +1388,28 @@ public String retrieveSubjectToken() {
return "subjectToken";
}
}

static class UniverseDomainErrorTestCredentials extends TestExternalAccountCredentials {
protected UniverseDomainErrorTestCredentials(TestExternalAccountCredentials.Builder builder) {
super(builder);
}

public static UniverseDomainErrorTestCredentials.Builder newBuilder() {
return new UniverseDomainErrorTestCredentials.Builder();
}

static class Builder extends TestExternalAccountCredentials.Builder {
Builder() {}

@Override
public UniverseDomainErrorTestCredentials build() {
return new UniverseDomainErrorTestCredentials(this);
}
}

@Override
public String getUniverseDomain() throws IOException {
throw new IOException("Test error");
}
}
}

0 comments on commit d0fc130

Please sign in to comment.