Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add integ tests #65

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions test/integ.deployIdentitySource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import { App, Stack } from 'aws-cdk-lib';
import { UserPool, UserPoolClient } from 'aws-cdk-lib/aws-cognito';
import { Construct } from 'constructs';
import { IdentitySource } from '../src/identity-source';
import { PolicyStore, ValidationSettingsMode } from '../src/policy-store';

const app = new App();
class IdentitySourceStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);

const validationSettingsStrict = {
mode: ValidationSettingsMode.STRICT,
};
const cedarJsonSchema = {
PhotoApp: {
entityTypes: {
User: {},
Photo: {},
},
actions: {
viewPhoto: {
appliesTo: {
principalTypes: ['User'],
resourceTypes: ['Photo'],
},
},
},
},
};
const cedarSchema = {
cedarJson: JSON.stringify(cedarJsonSchema),
};
const policyStore = new PolicyStore(this, 'PolicyStore', {
schema: cedarSchema,
validationSettings: validationSettingsStrict,
});
const userPool = new UserPool(this, 'UserPool');
const userPoolClient = new UserPoolClient(this, 'UserPoolClient', {
userPool: userPool,
});
new IdentitySource(this, 'IdentitySource', {
configuration: {
cognitoUserPoolConfiguration: {
clientIds: [userPoolClient.userPoolClientId],
userPool: userPool,
},
},
policyStore: policyStore,
principalEntityType: 'User',
});
}
}

const stackUnderTest = new IdentitySourceStack(app, 'IdentitySourceStack');
new IntegTest(app, 'IdentitySourceTest', {
testCases: [stackUnderTest],
cdkCommandOptions: {
destroy: {
enabled: true,
},
},
regions: [stackUnderTest.region],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "36.0.0",
"files": {
"0c0a55914d7f66e80e058a13a6ff9089236bee2010108ac3376ede5142b173bc": {
"source": {
"path": "IdentitySourceStack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "0c0a55914d7f66e80e058a13a6ff9089236bee2010108ac3376ede5142b173bc.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"Resources": {
"PolicyStore888EE7DF": {
"Type": "AWS::VerifiedPermissions::PolicyStore",
"Properties": {
"Schema": {
"CedarJson": "{\"PhotoApp\":{\"entityTypes\":{\"User\":{},\"Photo\":{}},\"actions\":{\"viewPhoto\":{\"appliesTo\":{\"principalTypes\":[\"User\"],\"resourceTypes\":[\"Photo\"]}}}}}"
},
"ValidationSettings": {
"Mode": "STRICT"
}
}
},
"UserPool6BA7E5F2": {
"Type": "AWS::Cognito::UserPool",
"Properties": {
"AccountRecoverySetting": {
"RecoveryMechanisms": [
{
"Name": "verified_phone_number",
"Priority": 1
},
{
"Name": "verified_email",
"Priority": 2
}
]
},
"AdminCreateUserConfig": {
"AllowAdminCreateUserOnly": true
},
"EmailVerificationMessage": "The verification code to your new account is {####}",
"EmailVerificationSubject": "Verify your new account",
"SmsVerificationMessage": "The verification code to your new account is {####}",
"VerificationMessageTemplate": {
"DefaultEmailOption": "CONFIRM_WITH_CODE",
"EmailMessage": "The verification code to your new account is {####}",
"EmailSubject": "Verify your new account",
"SmsMessage": "The verification code to your new account is {####}"
}
},
"UpdateReplacePolicy": "Retain",
"DeletionPolicy": "Retain"
},
"UserPoolClient2F5918F7": {
"Type": "AWS::Cognito::UserPoolClient",
"Properties": {
"AllowedOAuthFlows": [
"implicit",
"code"
],
"AllowedOAuthFlowsUserPoolClient": true,
"AllowedOAuthScopes": [
"profile",
"phone",
"email",
"openid",
"aws.cognito.signin.user.admin"
],
"CallbackURLs": [
"https://example.com"
],
"SupportedIdentityProviders": [
"COGNITO"
],
"UserPoolId": {
"Ref": "UserPool6BA7E5F2"
}
}
},
"IdentitySourceCFC05C57": {
"Type": "AWS::VerifiedPermissions::IdentitySource",
"Properties": {
"Configuration": {
"CognitoUserPoolConfiguration": {
"ClientIds": [
{
"Ref": "UserPoolClient2F5918F7"
}
],
"UserPoolArn": {
"Fn::GetAtt": [
"UserPool6BA7E5F2",
"Arn"
]
}
}
},
"PolicyStoreId": {
"Fn::GetAtt": [
"PolicyStore888EE7DF",
"PolicyStoreId"
]
},
"PrincipalEntityType": "User"
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "36.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
"path": "IdentitySourceTestDefaultTestDeployAssertC6DCD63D.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
1 change: 1 addition & 0 deletions test/integ.deployIdentitySource.ts.snapshot/cdk.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"36.0.0"}
20 changes: 20 additions & 0 deletions test/integ.deployIdentitySource.ts.snapshot/integ.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "36.0.0",
"testCases": {
"IdentitySourceTest/DefaultTest": {
"stacks": [
"IdentitySourceStack"
],
"regions": [
"${Token[AWS.Region.13]}"
],
"cdkCommandOptions": {
"destroy": {
"enabled": true
}
},
"assertionStack": "IdentitySourceTest/DefaultTest/DeployAssert",
"assertionStackName": "IdentitySourceTestDefaultTestDeployAssertC6DCD63D"
}
}
}
Loading
Loading