mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -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
@@ -207,7 +207,7 @@ The following **AppSync directives** are pre-defined and recognized in schemas:
|
||||
|-----------|-----------|---------|
|
||||
| `@aws_api_key` | OBJECT, FIELD_DEFINITION | Require API key auth |
|
||||
| `@aws_iam` | OBJECT, FIELD_DEFINITION | Require IAM auth |
|
||||
| `@aws_cognito_user_pools(cognito_groups: [String!]!)` | OBJECT, FIELD_DEFINITION | Require Cognito user pool auth |
|
||||
| `@aws_cognito_user_pools(cognito_groups: [String!])` | OBJECT, FIELD_DEFINITION | Require Cognito user pool auth |
|
||||
| `@aws_oidc` | OBJECT, FIELD_DEFINITION | Require OIDC auth |
|
||||
| `@aws_lambda` | OBJECT, FIELD_DEFINITION | Require Lambda auth |
|
||||
| `@aws_subscribe(mutations: [String!]!)` | FIELD_DEFINITION | Link subscription to mutation |
|
||||
|
||||
@@ -7,7 +7,7 @@ public enum AppSyncDirective {
|
||||
AWS_API_KEY("aws_api_key", "directive @aws_api_key on OBJECT | FIELD_DEFINITION"),
|
||||
AWS_IAM("aws_iam", "directive @aws_iam on OBJECT | FIELD_DEFINITION"),
|
||||
AWS_COGNITO_USER_POOLS("aws_cognito_user_pools",
|
||||
"directive @aws_cognito_user_pools(cognito_groups: [String!]!) on OBJECT | FIELD_DEFINITION"),
|
||||
"directive @aws_cognito_user_pools(cognito_groups: [String!]) on OBJECT | FIELD_DEFINITION"),
|
||||
AWS_OIDC("aws_oidc", "directive @aws_oidc on OBJECT | FIELD_DEFINITION"),
|
||||
AWS_LAMBDA("aws_lambda", "directive @aws_lambda on OBJECT | FIELD_DEFINITION"),
|
||||
AWS_SUBSCRIBE("aws_subscribe", "directive @aws_subscribe(mutations: [String!]!) on FIELD_DEFINITION"),
|
||||
|
||||
@@ -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