Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,16 @@ void createScopes_existingAccessTokenInvalidated() throws IOException {
assertNull(newAccessToken);
}

@Test
void getRequestMetadata_withUniverseAndDelegation_throws() {
ServiceAccountCredentials credentials =
createDefaultBuilderWithKey(OAuth2Utils.privateKeyFromPkcs8(PRIVATE_KEY_PKCS8))
.setUniverseDomain("example.com")
.setServiceAccountUser("user@example.com")
.build();
assertThrows(IOException.class, () -> credentials.getRequestMetadata(CALL_URI));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Asserting a generic IOException can lead to false positives if the method throws an IOException for other reasons (such as configuration or key issues). It is safer to assert that the exception message contains specific text indicating that domain-wide delegation is not supported with a custom universe domain.

    IOException exception =
        assertThrows(IOException.class, () -> credentials.getRequestMetadata(CALL_URI));
    assertTrue(exception.getMessage().contains("universe domain"));

}

private void verifyJwtAccess(Map<String, List<String>> metadata, String expectedScopeClaim)
throws IOException {
assertNotNull(metadata);
Expand Down
Loading