From 7d53e051fb308c6ecb6e2a0159e50d54aeda2a8e Mon Sep 17 00:00:00 2001 From: svozza Date: Fri, 29 Nov 2024 18:41:06 +0000 Subject: [PATCH] test(parser): refactor appsync schema tests --- .../appsync/cognito-identity-null-group.json | 77 ---------- .../events/appsync/custom-domain-name.json | 56 ------- .../events/appsync/iam-identity-cognito.json | 64 -------- .../appsync/iam-identity-no-cognito.json | 64 -------- .../parser/tests/events/appsync/invalid.json | 18 --- .../tests/events/appsync/lambda-identity.json | 59 -------- .../tests/events/appsync/no-identity.json | 56 ------- .../tests/events/appsync/null-prev.json | 52 ------- .../tests/events/appsync/null-source.json | 48 ------ .../tests/events/appsync/oidc-identity.json | 61 -------- ...nito-identity-group.json => resolver.json} | 0 .../parser/tests/unit/schema/appsync.test.ts | 137 +++++++++++++----- packages/parser/tests/unit/schema/utils.ts | 13 ++ 13 files changed, 110 insertions(+), 595 deletions(-) delete mode 100644 packages/parser/tests/events/appsync/cognito-identity-null-group.json delete mode 100644 packages/parser/tests/events/appsync/custom-domain-name.json delete mode 100644 packages/parser/tests/events/appsync/iam-identity-cognito.json delete mode 100644 packages/parser/tests/events/appsync/iam-identity-no-cognito.json delete mode 100644 packages/parser/tests/events/appsync/invalid.json delete mode 100644 packages/parser/tests/events/appsync/lambda-identity.json delete mode 100644 packages/parser/tests/events/appsync/no-identity.json delete mode 100644 packages/parser/tests/events/appsync/null-prev.json delete mode 100644 packages/parser/tests/events/appsync/null-source.json delete mode 100644 packages/parser/tests/events/appsync/oidc-identity.json rename packages/parser/tests/events/appsync/{cognito-identity-group.json => resolver.json} (100%) diff --git a/packages/parser/tests/events/appsync/cognito-identity-null-group.json b/packages/parser/tests/events/appsync/cognito-identity-null-group.json deleted file mode 100644 index b6e68142d..000000000 --- a/packages/parser/tests/events/appsync/cognito-identity-null-group.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "arguments": { - "id": "my identifier" - }, - "source": { - "name": "Value", - "nested": { - "name": "value", - "list": [] - } - }, - "identity": { - "claims": { - "sub": "192879fc-a240-4bf1-ab5a-d6a00f3063f9", - "email_verified": true, - "iss": "https://cognito-idp.us-west-2.amazonaws.com/us-west-xxxxxxxxxxx", - "phone_number_verified": false, - "cognito:username": "jdoe", - "aud": "7471s60os7h0uu77i1tk27sp9n", - "event_id": "bc334ed8-a938-4474-b644-9547e304e606", - "token_use": "id", - "auth_time": 1599154213, - "phone_number": "+19999999999", - "exp": 1599157813, - "iat": 1599154213, - "email": "jdoe@email.com" - }, - "defaultAuthStrategy": "ALLOW", - "groups": null, - "issuer": "https://cognito-idp.us-west-2.amazonaws.com/us-west-xxxxxxxxxxx", - "sourceIp": ["1.1.1.1"], - "sub": "192879fc-a240-4bf1-ab5a-d6a00f3063f9", - "username": "jdoe" - }, - "request": { - "domainName": null, - "headers": { - "x-forwarded-for": "1.1.1.1, 2.2.2.2", - "cloudfront-viewer-country": "US", - "cloudfront-is-tablet-viewer": "false", - "via": "2.0 xxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)", - "cloudfront-forwarded-proto": "https", - "origin": "https://us-west-1.console.aws.amazon.com", - "content-length": "217", - "accept-language": "en-US,en;q=0.9", - "host": "xxxxxxxxxxxxxxxx.appsync-api.us-west-1.amazonaws.com", - "x-forwarded-proto": "https", - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36", - "accept": "*/*", - "cloudfront-is-mobile-viewer": "false", - "cloudfront-is-smarttv-viewer": "false", - "accept-encoding": "gzip, deflate, br", - "referer": "https://us-west-1.console.aws.amazon.com/appsync/home?region=us-west-1", - "content-type": "application/json", - "sec-fetch-mode": "cors", - "x-amz-cf-id": "3aykhqlUwQeANU-HGY7E_guV5EkNeMMtwyOgiA==", - "x-amzn-trace-id": "Root=1-5f512f51-fac632066c5e848ae714", - "authorization": "eyJraWQiOiJScWFCSlJqYVJlM0hrSnBTUFpIcVRXazNOW...", - "sec-fetch-dest": "empty", - "x-amz-user-agent": "AWS-Console-AppSync/", - "cloudfront-is-desktop-viewer": "true", - "sec-fetch-site": "cross-site", - "x-forwarded-port": "443" - } - }, - "prev": { - "result": {} - }, - "info": { - "selectionSetList": ["id", "field1", "field2"], - "selectionSetGraphQL": "{\n id\n field1\n field2\n}", - "parentTypeName": "Mutation", - "fieldName": "createSomething", - "variables": {} - }, - "stash": {} -} diff --git a/packages/parser/tests/events/appsync/custom-domain-name.json b/packages/parser/tests/events/appsync/custom-domain-name.json deleted file mode 100644 index 3b020994c..000000000 --- a/packages/parser/tests/events/appsync/custom-domain-name.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "arguments": { - "id": "my identifier" - }, - "source": { - "name": "Value", - "nested": { - "name": "value", - "list": [] - } - }, - "request": { - "domainName": "mycustomdomain.example.com", - "headers": { - "x-forwarded-for": "1.1.1.1, 2.2.2.2", - "cloudfront-viewer-country": "US", - "cloudfront-is-tablet-viewer": "false", - "via": "2.0 xxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)", - "cloudfront-forwarded-proto": "https", - "origin": "https://us-west-1.console.aws.amazon.com", - "content-length": "217", - "accept-language": "en-US,en;q=0.9", - "host": "xxxxxxxxxxxxxxxx.appsync-api.us-west-1.amazonaws.com", - "x-forwarded-proto": "https", - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36", - "accept": "*/*", - "cloudfront-is-mobile-viewer": "false", - "cloudfront-is-smarttv-viewer": "false", - "accept-encoding": "gzip, deflate, br", - "referer": "https://us-west-1.console.aws.amazon.com/appsync/home?region=us-west-1", - "content-type": "application/json", - "sec-fetch-mode": "cors", - "x-amz-cf-id": "3aykhqlUwQeANU-HGY7E_guV5EkNeMMtwyOgiA==", - "x-amzn-trace-id": "Root=1-5f512f51-fac632066c5e848ae714", - "authorization": "eyJraWQiOiJScWFCSlJqYVJlM0hrSnBTUFpIcVRXazNOW...", - "sec-fetch-dest": "empty", - "x-amz-user-agent": "AWS-Console-AppSync/", - "cloudfront-is-desktop-viewer": "true", - "sec-fetch-site": "cross-site", - "x-forwarded-port": "443" - } - }, - "prev": { - "result": { - "field1": "value1" - } - }, - "info": { - "selectionSetList": ["id", "field1", "field2"], - "selectionSetGraphQL": "{\n id\n field1\n field2\n}", - "parentTypeName": "Mutation", - "fieldName": "createSomething", - "variables": {} - }, - "stash": {} -} diff --git a/packages/parser/tests/events/appsync/iam-identity-cognito.json b/packages/parser/tests/events/appsync/iam-identity-cognito.json deleted file mode 100644 index 1f37cc38d..000000000 --- a/packages/parser/tests/events/appsync/iam-identity-cognito.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "arguments": { - "id": "my identifier" - }, - "source": { - "name": "Value", - "nested": { - "name": "value", - "list": [] - } - }, - "identity": { - "accountId": "012345678901", - "cognitoIdentityAuthProvider": "cognitoIdentityAuthProvider", - "cognitoIdentityAuthType": "cognitoIdentityAuthType", - "cognitoIdentityId": "cognitoIdentityId", - "cognitoIdentityPoolId": "cognitoIdentityPoolId", - "sourceIp": ["10.10.10.10"], - "userArn": "arn:aws:sts::012345678901:assumed-role/role", - "username": "AROAXYKJUOW6FHGUSK5FA:username" - }, - "request": { - "domainName": null, - "headers": { - "x-forwarded-for": "1.1.1.1, 2.2.2.2", - "cloudfront-viewer-country": "US", - "cloudfront-is-tablet-viewer": "false", - "via": "2.0 xxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)", - "cloudfront-forwarded-proto": "https", - "origin": "https://us-west-1.console.aws.amazon.com", - "content-length": "217", - "accept-language": "en-US,en;q=0.9", - "host": "xxxxxxxxxxxxxxxx.appsync-api.us-west-1.amazonaws.com", - "x-forwarded-proto": "https", - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36", - "accept": "*/*", - "cloudfront-is-mobile-viewer": "false", - "cloudfront-is-smarttv-viewer": "false", - "accept-encoding": "gzip, deflate, br", - "referer": "https://us-west-1.console.aws.amazon.com/appsync/home?region=us-west-1", - "content-type": "application/json", - "sec-fetch-mode": "cors", - "x-amz-cf-id": "3aykhqlUwQeANU-HGY7E_guV5EkNeMMtwyOgiA==", - "x-amzn-trace-id": "Root=1-5f512f51-fac632066c5e848ae714", - "authorization": "eyJraWQiOiJScWFCSlJqYVJlM0hrSnBTUFpIcVRXazNOW...", - "sec-fetch-dest": "empty", - "x-amz-user-agent": "AWS-Console-AppSync/", - "cloudfront-is-desktop-viewer": "true", - "sec-fetch-site": "cross-site", - "x-forwarded-port": "443" - } - }, - "prev": { - "result": {} - }, - "info": { - "selectionSetList": ["id", "field1", "field2"], - "selectionSetGraphQL": "{\n id\n field1\n field2\n}", - "parentTypeName": "Mutation", - "fieldName": "createSomething", - "variables": {} - }, - "stash": {} -} diff --git a/packages/parser/tests/events/appsync/iam-identity-no-cognito.json b/packages/parser/tests/events/appsync/iam-identity-no-cognito.json deleted file mode 100644 index 5d141b050..000000000 --- a/packages/parser/tests/events/appsync/iam-identity-no-cognito.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "arguments": { - "id": "my identifier" - }, - "source": { - "name": "Value", - "nested": { - "name": "value", - "list": [] - } - }, - "identity": { - "accountId": "012345678901", - "cognitoIdentityAuthProvider": null, - "cognitoIdentityAuthType": null, - "cognitoIdentityId": null, - "cognitoIdentityPoolId": null, - "sourceIp": ["10.10.10.10"], - "userArn": "arn:aws:sts::012345678901:assumed-role/role", - "username": "AROAXYKJUOW6FHGUSK5FA:username" - }, - "request": { - "domainName": null, - "headers": { - "x-forwarded-for": "1.1.1.1, 2.2.2.2", - "cloudfront-viewer-country": "US", - "cloudfront-is-tablet-viewer": "false", - "via": "2.0 xxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)", - "cloudfront-forwarded-proto": "https", - "origin": "https://us-west-1.console.aws.amazon.com", - "content-length": "217", - "accept-language": "en-US,en;q=0.9", - "host": "xxxxxxxxxxxxxxxx.appsync-api.us-west-1.amazonaws.com", - "x-forwarded-proto": "https", - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36", - "accept": "*/*", - "cloudfront-is-mobile-viewer": "false", - "cloudfront-is-smarttv-viewer": "false", - "accept-encoding": "gzip, deflate, br", - "referer": "https://us-west-1.console.aws.amazon.com/appsync/home?region=us-west-1", - "content-type": "application/json", - "sec-fetch-mode": "cors", - "x-amz-cf-id": "3aykhqlUwQeANU-HGY7E_guV5EkNeMMtwyOgiA==", - "x-amzn-trace-id": "Root=1-5f512f51-fac632066c5e848ae714", - "authorization": "eyJraWQiOiJScWFCSlJqYVJlM0hrSnBTUFpIcVRXazNOW...", - "sec-fetch-dest": "empty", - "x-amz-user-agent": "AWS-Console-AppSync/", - "cloudfront-is-desktop-viewer": "true", - "sec-fetch-site": "cross-site", - "x-forwarded-port": "443" - } - }, - "prev": { - "result": {} - }, - "info": { - "selectionSetList": ["id", "field1", "field2"], - "selectionSetGraphQL": "{\n id\n field1\n field2\n}", - "parentTypeName": "Mutation", - "fieldName": "createSomething", - "variables": {} - }, - "stash": {} -} diff --git a/packages/parser/tests/events/appsync/invalid.json b/packages/parser/tests/events/appsync/invalid.json deleted file mode 100644 index b0992f4ae..000000000 --- a/packages/parser/tests/events/appsync/invalid.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "arguments": { - "id": "my identifier" - }, - "source": { - "name": "Value", - "nested": { - "name": "value", - "list": [] - } - }, - "prev": { - "result": { - "field1": "value1" - } - }, - "stash": {} -} diff --git a/packages/parser/tests/events/appsync/lambda-identity.json b/packages/parser/tests/events/appsync/lambda-identity.json deleted file mode 100644 index 0e7c92841..000000000 --- a/packages/parser/tests/events/appsync/lambda-identity.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "arguments": { - "id": "my identifier" - }, - "source": { - "name": "Value", - "nested": { - "name": "value", - "list": [] - } - }, - "identity": { - "resolverContext": { - "field1": "value" - } - }, - "request": { - "domainName": null, - "headers": { - "x-forwarded-for": "1.1.1.1, 2.2.2.2", - "cloudfront-viewer-country": "US", - "cloudfront-is-tablet-viewer": "false", - "via": "2.0 xxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)", - "cloudfront-forwarded-proto": "https", - "origin": "https://us-west-1.console.aws.amazon.com", - "content-length": "217", - "accept-language": "en-US,en;q=0.9", - "host": "xxxxxxxxxxxxxxxx.appsync-api.us-west-1.amazonaws.com", - "x-forwarded-proto": "https", - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36", - "accept": "*/*", - "cloudfront-is-mobile-viewer": "false", - "cloudfront-is-smarttv-viewer": "false", - "accept-encoding": "gzip, deflate, br", - "referer": "https://us-west-1.console.aws.amazon.com/appsync/home?region=us-west-1", - "content-type": "application/json", - "sec-fetch-mode": "cors", - "x-amz-cf-id": "3aykhqlUwQeANU-HGY7E_guV5EkNeMMtwyOgiA==", - "x-amzn-trace-id": "Root=1-5f512f51-fac632066c5e848ae714", - "authorization": "eyJraWQiOiJScWFCSlJqYVJlM0hrSnBTUFpIcVRXazNOW...", - "sec-fetch-dest": "empty", - "x-amz-user-agent": "AWS-Console-AppSync/", - "cloudfront-is-desktop-viewer": "true", - "sec-fetch-site": "cross-site", - "x-forwarded-port": "443" - } - }, - "prev": { - "result": {} - }, - "info": { - "selectionSetList": ["id", "field1", "field2"], - "selectionSetGraphQL": "{\n id\n field1\n field2\n}", - "parentTypeName": "Mutation", - "fieldName": "createSomething", - "variables": {} - }, - "stash": {} -} diff --git a/packages/parser/tests/events/appsync/no-identity.json b/packages/parser/tests/events/appsync/no-identity.json deleted file mode 100644 index 253128a21..000000000 --- a/packages/parser/tests/events/appsync/no-identity.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "arguments": { - "id": "my identifier" - }, - "source": { - "name": "Value", - "nested": { - "name": "value", - "list": [] - } - }, - "request": { - "domainName": null, - "headers": { - "x-forwarded-for": "1.1.1.1, 2.2.2.2", - "cloudfront-viewer-country": "US", - "cloudfront-is-tablet-viewer": "false", - "via": "2.0 xxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)", - "cloudfront-forwarded-proto": "https", - "origin": "https://us-west-1.console.aws.amazon.com", - "content-length": "217", - "accept-language": "en-US,en;q=0.9", - "host": "xxxxxxxxxxxxxxxx.appsync-api.us-west-1.amazonaws.com", - "x-forwarded-proto": "https", - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36", - "accept": "*/*", - "cloudfront-is-mobile-viewer": "false", - "cloudfront-is-smarttv-viewer": "false", - "accept-encoding": "gzip, deflate, br", - "referer": "https://us-west-1.console.aws.amazon.com/appsync/home?region=us-west-1", - "content-type": "application/json", - "sec-fetch-mode": "cors", - "x-amz-cf-id": "3aykhqlUwQeANU-HGY7E_guV5EkNeMMtwyOgiA==", - "x-amzn-trace-id": "Root=1-5f512f51-fac632066c5e848ae714", - "authorization": "eyJraWQiOiJScWFCSlJqYVJlM0hrSnBTUFpIcVRXazNOW...", - "sec-fetch-dest": "empty", - "x-amz-user-agent": "AWS-Console-AppSync/", - "cloudfront-is-desktop-viewer": "true", - "sec-fetch-site": "cross-site", - "x-forwarded-port": "443" - } - }, - "prev": { - "result": { - "field1": "value1" - } - }, - "info": { - "selectionSetList": ["id", "field1", "field2"], - "selectionSetGraphQL": "{\n id\n field1\n field2\n}", - "parentTypeName": "Mutation", - "fieldName": "createSomething", - "variables": {} - }, - "stash": {} -} diff --git a/packages/parser/tests/events/appsync/null-prev.json b/packages/parser/tests/events/appsync/null-prev.json deleted file mode 100644 index ecaa3e6af..000000000 --- a/packages/parser/tests/events/appsync/null-prev.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "arguments": { - "id": "my identifier" - }, - "source": { - "name": "Value", - "nested": { - "name": "value", - "list": [] - } - }, - "request": { - "domainName": null, - "headers": { - "x-forwarded-for": "1.1.1.1, 2.2.2.2", - "cloudfront-viewer-country": "US", - "cloudfront-is-tablet-viewer": "false", - "via": "2.0 xxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)", - "cloudfront-forwarded-proto": "https", - "origin": "https://us-west-1.console.aws.amazon.com", - "content-length": "217", - "accept-language": "en-US,en;q=0.9", - "host": "xxxxxxxxxxxxxxxx.appsync-api.us-west-1.amazonaws.com", - "x-forwarded-proto": "https", - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36", - "accept": "*/*", - "cloudfront-is-mobile-viewer": "false", - "cloudfront-is-smarttv-viewer": "false", - "accept-encoding": "gzip, deflate, br", - "referer": "https://us-west-1.console.aws.amazon.com/appsync/home?region=us-west-1", - "content-type": "application/json", - "sec-fetch-mode": "cors", - "x-amz-cf-id": "3aykhqlUwQeANU-HGY7E_guV5EkNeMMtwyOgiA==", - "x-amzn-trace-id": "Root=1-5f512f51-fac632066c5e848ae714", - "authorization": "eyJraWQiOiJScWFCSlJqYVJlM0hrSnBTUFpIcVRXazNOW...", - "sec-fetch-dest": "empty", - "x-amz-user-agent": "AWS-Console-AppSync/", - "cloudfront-is-desktop-viewer": "true", - "sec-fetch-site": "cross-site", - "x-forwarded-port": "443" - } - }, - "prev": null, - "info": { - "selectionSetList": ["id", "field1", "field2"], - "selectionSetGraphQL": "{\n id\n field1\n field2\n}", - "parentTypeName": "Mutation", - "fieldName": "createSomething", - "variables": {} - }, - "stash": {} -} diff --git a/packages/parser/tests/events/appsync/null-source.json b/packages/parser/tests/events/appsync/null-source.json deleted file mode 100644 index eb8d06f04..000000000 --- a/packages/parser/tests/events/appsync/null-source.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "arguments": { - "id": "my identifier" - }, - "source": null, - "request": { - "domainName": null, - "headers": { - "x-forwarded-for": "1.1.1.1, 2.2.2.2", - "cloudfront-viewer-country": "US", - "cloudfront-is-tablet-viewer": "false", - "via": "2.0 xxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)", - "cloudfront-forwarded-proto": "https", - "origin": "https://us-west-1.console.aws.amazon.com", - "content-length": "217", - "accept-language": "en-US,en;q=0.9", - "host": "xxxxxxxxxxxxxxxx.appsync-api.us-west-1.amazonaws.com", - "x-forwarded-proto": "https", - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36", - "accept": "*/*", - "cloudfront-is-mobile-viewer": "false", - "cloudfront-is-smarttv-viewer": "false", - "accept-encoding": "gzip, deflate, br", - "referer": "https://us-west-1.console.aws.amazon.com/appsync/home?region=us-west-1", - "content-type": "application/json", - "sec-fetch-mode": "cors", - "x-amz-cf-id": "3aykhqlUwQeANU-HGY7E_guV5EkNeMMtwyOgiA==", - "x-amzn-trace-id": "Root=1-5f512f51-fac632066c5e848ae714", - "authorization": "eyJraWQiOiJScWFCSlJqYVJlM0hrSnBTUFpIcVRXazNOW...", - "sec-fetch-dest": "empty", - "x-amz-user-agent": "AWS-Console-AppSync/", - "cloudfront-is-desktop-viewer": "true", - "sec-fetch-site": "cross-site", - "x-forwarded-port": "443" - } - }, - "prev": { - "result": {} - }, - "info": { - "selectionSetList": ["id", "field1", "field2"], - "selectionSetGraphQL": "{\n id\n field1\n field2\n}", - "parentTypeName": "Mutation", - "fieldName": "createSomething", - "variables": {} - }, - "stash": {} -} diff --git a/packages/parser/tests/events/appsync/oidc-identity.json b/packages/parser/tests/events/appsync/oidc-identity.json deleted file mode 100644 index 74fc9b026..000000000 --- a/packages/parser/tests/events/appsync/oidc-identity.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "arguments": { - "id": "my identifier" - }, - "source": { - "name": "Value", - "nested": { - "name": "value", - "list": [] - } - }, - "identity": { - "claims": { - "sub": "sub" - }, - "issuer": "issuer", - "sub": "sub" - }, - "request": { - "domainName": null, - "headers": { - "x-forwarded-for": "1.1.1.1, 2.2.2.2", - "cloudfront-viewer-country": "US", - "cloudfront-is-tablet-viewer": "false", - "via": "2.0 xxxxxxxxxxxxxxxx.cloudfront.net (CloudFront)", - "cloudfront-forwarded-proto": "https", - "origin": "https://us-west-1.console.aws.amazon.com", - "content-length": "217", - "accept-language": "en-US,en;q=0.9", - "host": "xxxxxxxxxxxxxxxx.appsync-api.us-west-1.amazonaws.com", - "x-forwarded-proto": "https", - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36", - "accept": "*/*", - "cloudfront-is-mobile-viewer": "false", - "cloudfront-is-smarttv-viewer": "false", - "accept-encoding": "gzip, deflate, br", - "referer": "https://us-west-1.console.aws.amazon.com/appsync/home?region=us-west-1", - "content-type": "application/json", - "sec-fetch-mode": "cors", - "x-amz-cf-id": "3aykhqlUwQeANU-HGY7E_guV5EkNeMMtwyOgiA==", - "x-amzn-trace-id": "Root=1-5f512f51-fac632066c5e848ae714", - "authorization": "eyJraWQiOiJScWFCSlJqYVJlM0hrSnBTUFpIcVRXazNOW...", - "sec-fetch-dest": "empty", - "x-amz-user-agent": "AWS-Console-AppSync/", - "cloudfront-is-desktop-viewer": "true", - "sec-fetch-site": "cross-site", - "x-forwarded-port": "443" - } - }, - "prev": { - "result": {} - }, - "info": { - "selectionSetList": ["id", "field1", "field2"], - "selectionSetGraphQL": "{\n id\n field1\n field2\n}", - "parentTypeName": "Mutation", - "fieldName": "createSomething", - "variables": {} - }, - "stash": {} -} diff --git a/packages/parser/tests/events/appsync/cognito-identity-group.json b/packages/parser/tests/events/appsync/resolver.json similarity index 100% rename from packages/parser/tests/events/appsync/cognito-identity-group.json rename to packages/parser/tests/events/appsync/resolver.json diff --git a/packages/parser/tests/unit/schema/appsync.test.ts b/packages/parser/tests/unit/schema/appsync.test.ts index 4330e42f1..ab9fa35f0 100644 --- a/packages/parser/tests/unit/schema/appsync.test.ts +++ b/packages/parser/tests/unit/schema/appsync.test.ts @@ -10,64 +10,127 @@ import { AppSyncResolverSchema, } from '../../../src/schemas/appsync'; import type { AppSyncResolverEvent } from '../../../src/types'; -import { getTestEvent } from './utils'; +import { getTestEvent, omit } from './utils'; type Table = { name: string; - filename: string; + event: AppSyncResolverEvent; }; describe('AppSync Resolver Schemas', () => { const eventsPath = 'appsync'; - const table = [ - { - name: 'should parse resolver event without identity field', - filename: 'no-identity', - }, + const appSyncResolverEvent: AppSyncResolverEvent = getTestEvent({ + eventsPath, + filename: 'resolver', + }); + + const table: Table[] = [ { name: 'should parse resolver event with null source', - filename: 'null-source', + event: { + ...appSyncResolverEvent, + source: null, + }, }, { name: 'should parse resolver event with null prev', - filename: 'null-prev', - }, - { - name: 'should parse resolver event with custom domain name', - filename: 'custom-domain-name', + event: { + ...appSyncResolverEvent, + prev: null, + }, }, { - name: 'should parse resolver event with cognito identity and rbac groups', - filename: 'cognito-identity-group', + name: 'should parse resolver event without custom domain', + event: { + ...appSyncResolverEvent, + request: { + ...appSyncResolverEvent.request, + domainName: null, + }, + }, }, { name: 'should parse resolver event with cognito identity and no rbac groups', - filename: 'cognito-identity-null-group', + event: { + ...appSyncResolverEvent, + identity: { + claims: { + sub: '192879fc-a240-4bf1-ab5a-d6a00f3063f9', + }, + defaultAuthStrategy: 'ALLOW', + groups: null, + issuer: + 'https://cognito-idp.us-west-2.amazonaws.com/us-west-xxxxxxxxxxx', + sourceIp: ['1.1.1.1'], + sub: '192879fc-a240-4bf1-ab5a-d6a00f3063f9', + username: 'jdoe', + }, + }, }, { name: 'with iam identity with no cognito fields', - filename: 'iam-identity-no-cognito', + event: { + ...appSyncResolverEvent, + identity: { + accountId: '012345678901', + cognitoIdentityAuthProvider: null, + cognitoIdentityAuthType: null, + cognitoIdentityId: null, + cognitoIdentityPoolId: null, + sourceIp: ['10.10.10.10'], + userArn: 'arn:aws:sts::012345678901:assumed-role/role', + username: 'AROAXYKJUOW6FHGUSK5FA:username', + }, + }, }, { name: 'should parse resolver event with iam identity with cognito fields', - filename: 'iam-identity-cognito', + event: { + ...appSyncResolverEvent, + identity: { + accountId: '012345678901', + cognitoIdentityAuthProvider: 'cognitoIdentityAuthProvider', + cognitoIdentityAuthType: 'cognitoIdentityAuthType', + cognitoIdentityId: 'cognitoIdentityId', + cognitoIdentityPoolId: 'cognitoIdentityPoolId', + sourceIp: ['10.10.10.10'], + userArn: 'arn:aws:sts::012345678901:assumed-role/role', + username: 'AROAXYKJUOW6FHGUSK5FA:username', + }, + }, }, { name: 'should parse resolver event with lambda identity', - filename: 'lambda-identity', + event: { + ...appSyncResolverEvent, + identity: { + resolverContext: { + field1: 'value', + }, + }, + }, }, { name: 'should parse resolver event with oidc identity', - filename: 'oidc-identity', + event: { + ...appSyncResolverEvent, + identity: { + claims: { + sub: 'sub', + }, + issuer: 'issuer', + sub: 'sub', + }, + }, }, ]; describe('AppSync Resolver Schema', () => { it('should return validation error when the event is invalid', () => { - const event = getTestEvent({ eventsPath, filename: 'invalid' }); - - const { error } = AppSyncResolverSchema.safeParse(event); + const { error } = AppSyncResolverSchema.safeParse( + omit(['request', 'info'], appSyncResolverEvent) + ); expect(error?.issues).toEqual([ { @@ -87,24 +150,24 @@ describe('AppSync Resolver Schemas', () => { ]); }); - it.each(table)('$name', ({ filename }) => { - const event = getTestEvent({ - eventsPath, - filename, - }); - + it('should parse resolver event without identity field', () => { + const event: Omit = omit( + ['identity'], + appSyncResolverEvent + ); const parsedEvent = AppSyncResolverSchema.parse(event); + expect(parsedEvent).toEqual(event); + }); + it.each(table)('$name', ({ event }: Table) => { + const parsedEvent = AppSyncResolverSchema.parse(event); expect(parsedEvent).toEqual(event); }); }); describe('Batch AppSync Resolver Schema', () => { it('should return validation error when the event is invalid', () => { - const event = getTestEvent({ - eventsPath, - filename: 'invalid', - }); + const event = omit(['request', 'info'], appSyncResolverEvent); const { error } = AppSyncBatchResolverSchema.safeParse([event]); @@ -127,14 +190,8 @@ describe('AppSync Resolver Schemas', () => { }); it('should parse batches of appsync resolver events', () => { - const filenames = table.map((table: Table) => table.filename); - - const events = filenames.map((filename) => - getTestEvent({ eventsPath, filename }) - ); - + const events = table.map((table: Table) => table.event); const parsedEvent = AppSyncBatchResolverSchema.parse(events); - expect(parsedEvent).toEqual(events); }); }); diff --git a/packages/parser/tests/unit/schema/utils.ts b/packages/parser/tests/unit/schema/utils.ts index aa5c9ab53..5ff32cbac 100644 --- a/packages/parser/tests/unit/schema/utils.ts +++ b/packages/parser/tests/unit/schema/utils.ts @@ -134,3 +134,16 @@ export const getTestEvent = >({ 'utf-8' ) ) as T; + +export function omit, Keys extends keyof T>( + keys: readonly Keys[], + obj: T +): Omit { + const result = { ...obj }; + + for (const key of keys) { + delete result[key]; + } + + return result; +}