mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(appsync): make Cognito directive groups optional (#8381)
* fix(appsync): make Cognito directive groups optional * chore(ci): retrigger pull request checks * test(appsync): share Cognito authorization context setup
This commit is contained in:
1 parent
5c0246a543
commit
e4d7061eff
4 files changed
+37
-6
No files matched your search
@@ -296,6 +296,19 @@ class AppSyncAuthIntegrationTest {
|
||||
.body("errors", nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cognitoDirectiveDoesNotRequireGroupsInSchema() {
|
||||
String apiId = createApi("cognito-sdl-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
startSchema(apiId, """
|
||||
type Todo @aws_cognito_user_pools { title: String }
|
||||
type Query {
|
||||
todo: Todo @aws_cognito_user_pools
|
||||
secret: String @aws_cognito_user_pools(cognito_groups: ["Admins"])
|
||||
}
|
||||
""");
|
||||
awaitSchemaSuccess(apiId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsAuthOnFieldDefinitionSchemaSucceeds() {
|
||||
String apiId = createApi("aws-auth-" + UUID.randomUUID().toString().substring(0, 8));
|
||||
|
||||
+22
-4
@@ -92,6 +92,21 @@ class SidecarFieldAuthorizationPlannerTest {
|
||||
assertAllowed(planner.planDenyFields(plan, iamContext(api)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void cognitoDirectiveOnlyChecksGroupMembershipWhenGroupsAreListed() {
|
||||
GraphqlApi api = api(AuthenticationType.API_KEY);
|
||||
withAdditional(api, AuthenticationType.AMAZON_COGNITO_USER_POOLS);
|
||||
Map<String, Object> identity = Map.of("groups", List.of("Readers"));
|
||||
AppSyncAuthContext cognito = cognitoContext(api, identity);
|
||||
PlanResult bare = plan(field("Query", "todo", List.of(directive("aws_cognito_user_pools")), List.of()));
|
||||
PlanResult restricted = plan(field("Query", "secret", List.of(directive("aws_cognito_user_pools",
|
||||
Map.of("cognito_groups", List.of("Admins")))), List.of()));
|
||||
|
||||
assertAllowed(planner.planDenyFields(bare, cognito));
|
||||
assertDenied(planner.planDenyFields(bare, apiKeyContext(api)));
|
||||
assertDenied(planner.planDenyFields(restricted, cognito));
|
||||
}
|
||||
|
||||
@Test
|
||||
void awsAuthIgnoredWhenAdditionalModesExist() {
|
||||
PlanResult plan = plan(field("Query", "secret",
|
||||
@@ -99,8 +114,7 @@ class SidecarFieldAuthorizationPlannerTest {
|
||||
GraphqlApi api = api(AuthenticationType.AMAZON_COGNITO_USER_POOLS);
|
||||
withAdditional(api, AuthenticationType.API_KEY);
|
||||
Map<String, Object> identity = IdentityBuilder.cognito(Map.of("sub", "s", "iss", "https://iss"), List.of(), "ALLOW");
|
||||
AppSyncAuthContext ctx = new AppSyncAuthContext(identity, AppSyncAuth.AUTH_TYPE_COGNITO,
|
||||
AuthenticationType.AMAZON_COGNITO_USER_POOLS, Set.of(), api, null, "us-east-1", "000000000000");
|
||||
AppSyncAuthContext ctx = cognitoContext(api, identity);
|
||||
|
||||
assertAllowed(planner.planDenyFields(plan, ctx));
|
||||
}
|
||||
@@ -112,8 +126,7 @@ class SidecarFieldAuthorizationPlannerTest {
|
||||
GraphqlApi api = api(AuthenticationType.AMAZON_COGNITO_USER_POOLS);
|
||||
Map<String, Object> identity = IdentityBuilder.cognito(
|
||||
Map.of("sub", "s", "iss", "https://iss", "cognito:groups", List.of("users")), List.of(), "ALLOW");
|
||||
AppSyncAuthContext ctx = new AppSyncAuthContext(identity, AppSyncAuth.AUTH_TYPE_COGNITO,
|
||||
AuthenticationType.AMAZON_COGNITO_USER_POOLS, Set.of(), api, null, "us-east-1", "000000000000");
|
||||
AppSyncAuthContext ctx = cognitoContext(api, identity);
|
||||
|
||||
assertDenied(planner.planDenyFields(plan, ctx));
|
||||
}
|
||||
@@ -201,6 +214,11 @@ class SidecarFieldAuthorizationPlannerTest {
|
||||
"us-east-1", "000000000000");
|
||||
}
|
||||
|
||||
private static AppSyncAuthContext cognitoContext(GraphqlApi api, Map<String, Object> identity) {
|
||||
return new AppSyncAuthContext(identity, AppSyncAuth.AUTH_TYPE_COGNITO,
|
||||
AuthenticationType.AMAZON_COGNITO_USER_POOLS, Set.of(), api, null, "us-east-1", "000000000000");
|
||||
}
|
||||
|
||||
private static AppSyncAuthContext apiKeyContext(GraphqlApi api) {
|
||||
return new AppSyncAuthContext(
|
||||
null, AppSyncAuth.AUTH_TYPE_API_KEY, AuthenticationType.API_KEY, Set.of(), api, null,
|
||||
|
||||
Reference in new issue
Block a user