Skip to content

Commit

Permalink
Change test for impersonated credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
aeitzman committed Dec 1, 2023
1 parent 8d12e07 commit a8b2f92
Showing 1 changed file with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -464,21 +464,6 @@ public void fromJson_nullJson_throws() {
}
}

@Test
public void fromJson_invalidServiceAccountImpersonationUrl_throws() {
GenericJson json = buildJsonIdentityPoolCredential();
json.put("service_account_impersonation_url", "https://iamcredentials.googleapis.com");

try {
ExternalAccountCredentials.fromJson(json, OAuth2Utils.HTTP_TRANSPORT_FACTORY);
fail("Exception should be thrown.");
} catch (IllegalArgumentException e) {
assertEquals(
"Unable to determine target principal from service account impersonation URL.",
e.getMessage());
}
}

@Test
public void fromJson_nullTransport_throws() {
try {
Expand Down Expand Up @@ -1041,6 +1026,26 @@ public void exchangeExternalCredentialForAccessToken_throws() throws IOException
}
}

@Test
public void exchangeExternalCredentialForAccessToken_invalidImpersonatedCredentialsThrows() throws IOException {
GenericJson json = buildJsonIdentityPoolCredential();
json.put("service_account_impersonation_url", "https://iamcredentials.googleapis.com");
ExternalAccountCredentials credential =
ExternalAccountCredentials.fromJson(json, transportFactory);

StsTokenExchangeRequest stsTokenExchangeRequest =
StsTokenExchangeRequest.newBuilder("credential", "subjectTokenType").build();

try {
credential.exchangeExternalCredentialForAccessToken(stsTokenExchangeRequest);
fail("Exception should be thrown.");
} catch (IllegalArgumentException e) {
assertEquals(
"Unable to determine target principal from service account impersonation URL.",
e.getMessage());
}
}

@Test
public void getRequestMetadata_withQuotaProjectId() throws IOException {
TestExternalAccountCredentials testCredentials =
Expand Down

0 comments on commit a8b2f92

Please sign in to comment.