-
Notifications
You must be signed in to change notification settings - Fork 280
chore: Add test for non-2xx responses from idTokenWithAudience calls #1656
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bdc7e78
chore: Add test for non-2xx responses from idTokenWithAudience calls
lqiu96 e147f53
chore: Update comments in test
lqiu96 7f60f56
chore(deps): update dependency com.google.auth:google-auth-library-oa…
renovate-bot c2e60bc
chore: Update test name
lqiu96 50165d4
Merge remote-tracking branch 'origin/main' into fix-parsing-token
lqiu96 2b2a431
chore: Remove universe domain
lqiu96 9f8d07b
Merge branch 'main' into fix-parsing-token
lqiu96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import static org.junit.Assert.assertNotNull; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertSame; | ||
| import static org.junit.Assert.assertThrows; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
|
|
@@ -975,6 +976,58 @@ public void idTokenWithAudience_iamFlow_targetAudienceDoesNotMatchAudClaim() thr | |
| tokenCredential.getIdToken().getJsonWebSignature().getPayload().getAudience()); | ||
| } | ||
|
|
||
| @Test | ||
| public void idTokenWithAudience_oauthEndpoint_non2XXStatusCode() throws IOException { | ||
| String universeDomain = "test.com"; | ||
| MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory(); | ||
| transportFactory.transport.setError(new IOException("404 Not Found")); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TokenServerTransportFactory sets an error response with |
||
| ServiceAccountCredentials credentials = | ||
| createDefaultBuilder() | ||
| .setScopes(SCOPES) | ||
| .setHttpTransportFactory(transportFactory) | ||
| .setUniverseDomain(universeDomain) | ||
| .build(); | ||
|
|
||
| String targetAudience = "audience"; | ||
| IdTokenCredentials tokenCredential = | ||
| IdTokenCredentials.newBuilder() | ||
| .setIdTokenProvider(credentials) | ||
| .setTargetAudience(targetAudience) | ||
| .build(); | ||
|
|
||
| // Ensure that a non 2xx status code returns an exception and doesn't continue execution | ||
| assertThrows(IOException.class, tokenCredential::refresh); | ||
| } | ||
|
|
||
| @Test | ||
| public void idTokenWithAudience_iamEndpoint_non2XXStatusCode() throws IOException { | ||
| String universeDomain = "test.com"; | ||
|
zhumin8 marked this conversation as resolved.
|
||
| MockIAMCredentialsServiceTransportFactory transportFactory = | ||
| new MockIAMCredentialsServiceTransportFactory(universeDomain); | ||
| transportFactory.getTransport().setTargetPrincipal(CLIENT_EMAIL); | ||
| transportFactory.getTransport().setIdToken(DEFAULT_ID_TOKEN); | ||
| transportFactory | ||
| .getTransport() | ||
| .addStatusCodeAndMessage(HttpStatusCodes.STATUS_CODE_NOT_FOUND, "Not Found"); | ||
| ServiceAccountCredentials credentials = | ||
| createDefaultBuilder() | ||
| .setScopes(SCOPES) | ||
| .setHttpTransportFactory(transportFactory) | ||
| .setUniverseDomain(universeDomain) | ||
| .build(); | ||
|
|
||
| String targetAudience = "audience"; | ||
| IdTokenCredentials tokenCredential = | ||
| IdTokenCredentials.newBuilder() | ||
| .setIdTokenProvider(credentials) | ||
| .setTargetAudience(targetAudience) | ||
| .build(); | ||
|
|
||
| // Ensure that a non 2xx status code returns an exception and doesn't continue execution | ||
| // Non 2xx status codes will be returned as HttpResponseException | ||
| assertThrows(IOException.class, tokenCredential::refresh); | ||
| } | ||
|
|
||
| @Test | ||
| public void getScopes_nullReturnsEmpty() throws IOException { | ||
| ServiceAccountCredentials credentials = createDefaultBuilder().build(); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.