Skip to content

Commit fba6ef0

Browse files
committed
test(auth): Assert multiple scopes are space-separated in JWT claim
This commit adds a test to verify that when a Service Account is configured with multiple scopes during Self-Signed JWT authentication, the scopes are correctly serialized into a single space-separated string within the JWT's 'scope' claim. This brings the Java library's test suite into alignment with the expected auth specification. Other Google Cloud client libraries like Go, Node.js, and Python natively assert that multiple scopes are appropriately space-separated during their JWT generation tests.
1 parent 051aea7 commit fba6ef0

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

google-auth-library-java/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,17 @@ void createScopes_existingAccessTokenInvalidated() throws IOException {
17621762
assertNull(newAccessToken);
17631763
}
17641764

1765+
@Test
1766+
void getRequestMetadata_withMultipleScopes_selfSignedJWT() throws IOException {
1767+
List<String> scopes = Arrays.asList("scope1", "scope2");
1768+
ServiceAccountCredentials credentials =
1769+
createDefaultBuilderWithKey(OAuth2Utils.privateKeyFromPkcs8(PRIVATE_KEY_PKCS8))
1770+
.setScopes(scopes)
1771+
.setUseJwtAccessWithScope(true)
1772+
.build();
1773+
verifyJwtAccess(credentials.getRequestMetadata(CALL_URI), "scope1 scope2");
1774+
}
1775+
17651776
private void verifyJwtAccess(Map<String, List<String>> metadata, String expectedScopeClaim)
17661777
throws IOException {
17671778
assertNotNull(metadata);

0 commit comments

Comments
 (0)