Skip to content

Commit

Permalink
test(integ.graphql): test cognito and api key authorization
Browse files Browse the repository at this point in the history
Test using cognito user pools as the default authorization mode and an
api key as the additional mode.

Signed-off-by: Duarte Nunes <[email protected]>
  • Loading branch information
duarten committed Feb 13, 2020
1 parent 3231c89 commit 9bc636d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
38 changes: 36 additions & 2 deletions packages/@aws-cdk/aws-appsync/test/integ.graphql.expected.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
{
"Resources": {
"PoolD3F588B8": {
"Type": "AWS::Cognito::UserPool",
"Properties": {
"LambdaConfig": {},
"UserPoolName": "myPool"
}
},
"ApiF70053CD": {
"Type": "AWS::AppSync::GraphQLApi",
"Properties": {
"AuthenticationType": "API_KEY",
"Name": "demoapi"
"AuthenticationType": "AMAZON_COGNITO_USER_POOLS",
"Name": "demoapi",
"AdditionalAuthenticationProviders": [
{
"AuthenticationType": "API_KEY"
}
],
"UserPoolConfig": {
"AwsRegion": {
"Ref": "AWS::Region"
},
"DefaultAction": "ALLOW",
"UserPoolId": {
"Ref": "PoolD3F588B8"
}
}
}
},
"ApiMyAPIKeyApiKeyACDEE2CC": {
"Type": "AWS::AppSync::ApiKey",
"Properties": {
"ApiId": {
"Fn::GetAtt": [
"ApiF70053CD",
"ApiId"
]
},
"Description": "My API Key",
"Expires": 1590202940
}
},
"ApiSchema510EECD7": {
Expand Down
21 changes: 19 additions & 2 deletions packages/@aws-cdk/aws-appsync/test/integ.graphql.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import { UserPool } from '@aws-cdk/aws-cognito';
import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb';
import { App, RemovalPolicy, Stack } from '@aws-cdk/core';
import { App, Duration, RemovalPolicy, Stack } from '@aws-cdk/core';
import { join } from 'path';
import { GraphQLApi, KeyCondition, MappingTemplate } from '../lib';
import { GraphQLApi, KeyCondition, MappingTemplate, UserPoolDefaultAction } from '../lib';

const app = new App();
const stack = new Stack(app, 'aws-appsync-integ');

const userPool = new UserPool(stack, 'Pool', {
userPoolName: 'myPool',
});

const api = new GraphQLApi(stack, 'Api', {
name: `demoapi`,
schemaDefinitionFile: join(__dirname, 'schema.graphql'),
authorizationConfig: {
defaultAuthorization: {
userPool,
defaultAction: UserPoolDefaultAction.ALLOW,
},
additionalAuthorizationModes: [
{
apiKeyDesc: "My API Key",
expires: Duration.days(100),
},
],
},
});

const customerTable = new Table(stack, 'CustomerTable', {
Expand Down

0 comments on commit 9bc636d

Please sign in to comment.