mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(apigatewayv2): accept array aud claim in HTTP API JWT authorizer (#7377)
This commit is contained in:
1 parent
4617e4a4f8
commit
feb9364760
2 files changed
+112
-9
No files matched your search
@@ -65,6 +65,77 @@ class JwtClaimsWireFormatTest {
|
||||
"nested object claims fall back to JSON text");
|
||||
}
|
||||
|
||||
@Test
|
||||
void parsesStringAudienceAsSingleEntry() {
|
||||
ApiGatewayExecuteController.JwtClaims claims = controller.parseJwtClaims(unsignedToken("""
|
||||
{"sub": "u", "aud": "https://api.example.com"}
|
||||
"""));
|
||||
|
||||
assertNotNull(claims);
|
||||
assertEquals(List.of("https://api.example.com"), claims.audiences());
|
||||
}
|
||||
|
||||
@Test
|
||||
void parsesArrayAudienceKeepingEveryEntry() {
|
||||
// Auth0 issues this shape whenever the openid scope is requested.
|
||||
ApiGatewayExecuteController.JwtClaims claims = controller.parseJwtClaims(unsignedToken("""
|
||||
{"sub": "u", "aud": ["https://api.example.com", "https://tenant.auth0.com/userinfo"]}
|
||||
"""));
|
||||
|
||||
assertNotNull(claims);
|
||||
assertEquals(List.of("https://api.example.com", "https://tenant.auth0.com/userinfo"),
|
||||
claims.audiences());
|
||||
}
|
||||
|
||||
@Test
|
||||
void audienceMatches_arrayAudContainingConfiguredAudience_matches() {
|
||||
ApiGatewayExecuteController.JwtClaims claims = controller.parseJwtClaims(unsignedToken("""
|
||||
{"sub": "u", "aud": ["https://api.example.com", "https://tenant.auth0.com/userinfo"]}
|
||||
"""));
|
||||
|
||||
assertTrue(ApiGatewayExecuteController.audienceMatches(
|
||||
List.of("https://api.example.com"), claims));
|
||||
}
|
||||
|
||||
@Test
|
||||
void audienceMatches_arrayAudWithoutConfiguredAudience_doesNotMatch() {
|
||||
ApiGatewayExecuteController.JwtClaims claims = controller.parseJwtClaims(unsignedToken("""
|
||||
{"sub": "u", "aud": ["https://other.example.com", "https://tenant.auth0.com/userinfo"]}
|
||||
"""));
|
||||
|
||||
assertFalse(ApiGatewayExecuteController.audienceMatches(
|
||||
List.of("https://api.example.com"), claims));
|
||||
}
|
||||
|
||||
@Test
|
||||
void audienceMatches_cognitoAccessTokenClientId_matches() {
|
||||
ApiGatewayExecuteController.JwtClaims claims = controller.parseJwtClaims(unsignedToken("""
|
||||
{"sub": "u", "client_id": "app-client-123"}
|
||||
"""));
|
||||
|
||||
assertNotNull(claims);
|
||||
assertEquals(List.of(), claims.audiences());
|
||||
assertTrue(ApiGatewayExecuteController.audienceMatches(List.of("app-client-123"), claims));
|
||||
}
|
||||
|
||||
@Test
|
||||
void audienceMatches_mismatchedAudWithMatchingClientId_doesNotMatch() {
|
||||
ApiGatewayExecuteController.JwtClaims claims = controller.parseJwtClaims(unsignedToken("""
|
||||
{"sub": "u", "aud": ["other"], "client_id": "expected"}
|
||||
"""));
|
||||
|
||||
assertFalse(ApiGatewayExecuteController.audienceMatches(List.of("expected"), claims));
|
||||
}
|
||||
|
||||
@Test
|
||||
void audienceMatches_emptyAudArrayWithMatchingClientId_doesNotMatch() {
|
||||
ApiGatewayExecuteController.JwtClaims claims = controller.parseJwtClaims(unsignedToken("""
|
||||
{"sub": "u", "aud": [], "client_id": "expected"}
|
||||
"""));
|
||||
|
||||
assertFalse(ApiGatewayExecuteController.audienceMatches(List.of("expected"), claims));
|
||||
}
|
||||
|
||||
@Test
|
||||
void derivesScopesFromScpArrayFirst() {
|
||||
ApiGatewayExecuteController.JwtClaims claims = controller.parseJwtClaims(unsignedToken("""
|
||||
|
||||
Reference in new issue
Block a user