@mavogel/awscdk-rootmail 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.jsii +57 -19
  2. package/API.md +117 -2
  3. package/README.md +91 -2
  4. package/docs/img/cloudformation-tpl-min.png +0 -0
  5. package/integ-tests/functions/custom-ses-receive-function.ts +92 -0
  6. package/integ-tests/integ.rootmail-custom-santa.ts +143 -0
  7. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/RootmailIntegTestStack.assets.json +162 -0
  8. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/RootmailIntegTestStack.template.json +4541 -0
  9. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/SetupTestIntegStackDefaultTestDeployAssert6EB6FF77.assets.json +32 -0
  10. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/SetupTestIntegStackDefaultTestDeployAssert6EB6FF77.template.json +249 -0
  11. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.0649b5bfaa322d6bd173d2daef3177389cf0778b556b300ac6bf451704cc3a49/index.js +37981 -0
  12. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.157ba1713f7224463b621261792d18081588ff306a9bc3f75e6c468fabbe1a60/index.js +106 -0
  13. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.4c079063901e6478dbb5ace19e3123641ebf0da2ab648ecf52079c5bec154196/index.js +215 -0
  14. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.53e8368959effe94a6e51bef9c7c5bf0eaf5c4d64eece81632ca62aa34517978.bundle/index.js +31981 -0
  15. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.5cc92ed0cea39e2b8de2dbc527dfb5980a3af9564bd1084d840b9787c7d0467e/index.d.ts +14 -0
  16. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.5cc92ed0cea39e2b8de2dbc527dfb5980a3af9564bd1084d840b9787c7d0467e/index.js +1 -0
  17. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.78b64aaf9aebb4eacbdd42197be10e9d5894360a642f7dcf79aeb84bb3552377/index.js +61 -0
  18. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.7e8a681794eff5fda1841caa360113df5488ecf944055a69b8f1e5a687e269f5/index.js +83 -0
  19. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.9572b451243318765beb576ae7528096b3879783dbaab795c02c01d7f4e83438/index.js +47 -0
  20. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.b8448324ef2c7d5bfa362722df2d397079d5aabaae2749f09180ac5bedfa5c89/index.js +105 -0
  21. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.d2b520d86fd9d964c83dc0d5ce2e4456dbde5fa7ae0c791a71865cbdfe2fb855/index.js +85 -0
  22. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.f2d30cfc360482320a52a4fcde8a70f3569df79ab30be24650fda58eb60052cf/cfn-response.js +1 -0
  23. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.f2d30cfc360482320a52a4fcde8a70f3569df79ab30be24650fda58eb60052cf/consts.js +1 -0
  24. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.f2d30cfc360482320a52a4fcde8a70f3569df79ab30be24650fda58eb60052cf/framework.js +3 -0
  25. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.f2d30cfc360482320a52a4fcde8a70f3569df79ab30be24650fda58eb60052cf/outbound.js +1 -0
  26. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.f2d30cfc360482320a52a4fcde8a70f3569df79ab30be24650fda58eb60052cf/util.js +1 -0
  27. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/asset.f9b17c134d24cf60e1d26c033b5f4f247b759149619ac0aac341b950a10ccf14/index.js +72 -0
  28. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/integ.json +27 -0
  29. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/manifest.json +742 -0
  30. package/integ-tests/integ.rootmail-custom-santa.ts.snapshot/tree.json +5893 -0
  31. package/integ-tests/integ.rootmail.ts.snapshot/SetupTestIntegStackDefaultTestDeployAssert6EB6FF77.assets.json +2 -2
  32. package/integ-tests/integ.rootmail.ts.snapshot/SetupTestIntegStackDefaultTestDeployAssert6EB6FF77.template.json +3 -3
  33. package/integ-tests/integ.rootmail.ts.snapshot/manifest.json +1 -1
  34. package/lib/index-cli-synth.js +22 -11
  35. package/lib/index.js +2 -1
  36. package/lib/rootmail.d.ts +5 -1
  37. package/lib/rootmail.js +3 -2
  38. package/lib/scripts/publish-assets.js +18 -22
  39. package/lib/ses-receive.d.ts +5 -1
  40. package/lib/ses-receive.js +36 -14
  41. package/package.json +11 -6
@@ -0,0 +1,143 @@
1
+ import * as path from 'path';
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import { IntegTest, ExpectedResult, LogType, InvocationType } from '@aws-cdk/integ-tests-alpha';
4
+ import {
5
+ App,
6
+ Duration,
7
+ PhysicalName,
8
+ Stack,
9
+ aws_iam as iam,
10
+ aws_lambda as lambda,
11
+ } from 'aws-cdk-lib';
12
+ import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
13
+ import { Rootmail } from '../src/rootmail';
14
+ // CDK App for Integration Tests
15
+ const app = new App();
16
+ // Stack under test
17
+ const stackUnderTestName = 'RootmailIntegTestStack';
18
+ const stackUnderTest = new Stack(app, stackUnderTestName, {
19
+ description: "This stack includes the application's resources for integration testing.",
20
+ });
21
+
22
+ const testDomain = 'rootmail-test.mavogel.xyz';
23
+ const hostedZoneId = 'Z066250529JROZU7IIY3Q';
24
+ const randomTestId = 'c23qgsa2';
25
+ const testSubdomain = `${randomTestId}-${Stack.of(stackUnderTest).region}`;
26
+ const fullDomain = `${testSubdomain}.${testDomain}`;
27
+
28
+ const customSesReceiveFunction = new NodejsFunction(stackUnderTest, 'custom-ses-receive-function', {
29
+ functionName: PhysicalName.GENERATE_IF_NEEDED,
30
+ entry: path.join(__dirname, 'functions', 'custom-ses-receive-function.ts'),
31
+ runtime: lambda.Runtime.NODEJS_18_X,
32
+ logRetention: 1,
33
+ timeout: Duration.seconds(30),
34
+ });
35
+
36
+ customSesReceiveFunction.addToRolePolicy(new iam.PolicyStatement({
37
+ actions: [
38
+ 's3:List*',
39
+ ],
40
+ resources: ['*'],
41
+ }))
42
+
43
+ const rootmail = new Rootmail(stackUnderTest, 'testRootmail', {
44
+ domain: testDomain,
45
+ subdomain: testSubdomain,
46
+ // tests took on average 10-15 minutes , but we leave some buffer
47
+ totalTimeToWireDNS: Duration.minutes(20),
48
+ wireDNSToHostedZoneID: hostedZoneId,
49
+ customSesReceiveFunction: customSesReceiveFunction,
50
+ setDestroyPolicyToAllResources: false,
51
+ });
52
+
53
+
54
+ // Initialize Integ Test construct
55
+ const integStackName = 'SetupTestIntegStack';
56
+ const integ = new IntegTest(app, integStackName, {
57
+ testCases: [stackUnderTest], // Define a list of cases for this test
58
+ cdkCommandOptions: {
59
+ destroy: {
60
+ args: {
61
+ force: true,
62
+ },
63
+ },
64
+ },
65
+ hooks: {
66
+ postDestroy: [
67
+ 'echo "Post hook"',
68
+ // NOTE: as I do not see the hook called, we need to delete manually
69
+ // `echo "Deleting S3 bucket '${rootmail.emailBucket.bucketName}'`,
70
+ // `python3 cleanup/empty-and-delete-s3-bucket.py ${rootmail.emailBucket.bucketName}`,
71
+ ],
72
+ },
73
+ regions: [stackUnderTest.region],
74
+ });
75
+
76
+ const sendEmailHandler = new NodejsFunction(stackUnderTest, 'send-email-handler', {
77
+ functionName: PhysicalName.GENERATE_IF_NEEDED,
78
+ entry: path.join(__dirname, 'functions', 'send-email-handler.ts'),
79
+ runtime: lambda.Runtime.NODEJS_18_X,
80
+ logRetention: 1,
81
+ timeout: Duration.seconds(30),
82
+ initialPolicy: [
83
+ new iam.PolicyStatement({
84
+ actions: [
85
+ 'ses:SendEmail',
86
+ 'ses:DescribeReceiptRule',
87
+ ],
88
+ resources: ['*'],
89
+ }),
90
+ ],
91
+ });
92
+
93
+ /**
94
+ * Assertion:
95
+ * The application should parse a dummy email, store it in S3 and set create an OPS item.
96
+ */
97
+ const id = `test-id-${randomTestId}`;
98
+ const message = 'This is a mail body';
99
+
100
+ const sendTestEmailAssertion = integ.assertions
101
+ .invokeFunction({
102
+ functionName: sendEmailHandler.functionName,
103
+ logType: LogType.TAIL,
104
+ invocationType: InvocationType.REQUEST_RESPONE, // to run it synchronously
105
+ payload: JSON.stringify({
106
+ id: id,
107
+ text: message,
108
+ sourceMail: `test@${fullDomain}`,
109
+ toMail: `root+${id}@${fullDomain}`,
110
+ }),
111
+ }).expect(ExpectedResult.objectLike(
112
+ // as the object 'return { sendStatusCode: 200 };' is wrapped in a Payload object with other properties
113
+ {
114
+ Payload: {
115
+ sendStatusCode: 200,
116
+ },
117
+ },
118
+ ),
119
+ );
120
+
121
+ const getHostedZoneParametersAssertion = integ.assertions
122
+ /**
123
+ * Check that parameter are present
124
+ */
125
+ .awsApiCall('SSM', 'getParameter', {
126
+ Name: rootmail.hostedZoneParameterName,
127
+ })
128
+ .expect(
129
+ ExpectedResult.objectLike({
130
+ Parameter: {
131
+ Name: rootmail.hostedZoneParameterName,
132
+ Type: 'StringList',
133
+ },
134
+ }),
135
+ );
136
+
137
+ /**
138
+ * Main test case
139
+ */
140
+ // check the parameter store
141
+ getHostedZoneParametersAssertion
142
+ // Send a test email
143
+ .next(sendTestEmailAssertion)
@@ -0,0 +1,162 @@
1
+ {
2
+ "version": "33.0.0",
3
+ "files": {
4
+ "0649b5bfaa322d6bd173d2daef3177389cf0778b556b300ac6bf451704cc3a49": {
5
+ "source": {
6
+ "path": "asset.0649b5bfaa322d6bd173d2daef3177389cf0778b556b300ac6bf451704cc3a49",
7
+ "packaging": "zip"
8
+ },
9
+ "destinations": {
10
+ "current_account-current_region": {
11
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12
+ "objectKey": "0649b5bfaa322d6bd173d2daef3177389cf0778b556b300ac6bf451704cc3a49.zip",
13
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14
+ }
15
+ }
16
+ },
17
+ "5cc92ed0cea39e2b8de2dbc527dfb5980a3af9564bd1084d840b9787c7d0467e": {
18
+ "source": {
19
+ "path": "asset.5cc92ed0cea39e2b8de2dbc527dfb5980a3af9564bd1084d840b9787c7d0467e",
20
+ "packaging": "zip"
21
+ },
22
+ "destinations": {
23
+ "current_account-current_region": {
24
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
25
+ "objectKey": "5cc92ed0cea39e2b8de2dbc527dfb5980a3af9564bd1084d840b9787c7d0467e.zip",
26
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
27
+ }
28
+ }
29
+ },
30
+ "f9b17c134d24cf60e1d26c033b5f4f247b759149619ac0aac341b950a10ccf14": {
31
+ "source": {
32
+ "path": "asset.f9b17c134d24cf60e1d26c033b5f4f247b759149619ac0aac341b950a10ccf14",
33
+ "packaging": "zip"
34
+ },
35
+ "destinations": {
36
+ "current_account-current_region": {
37
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
38
+ "objectKey": "f9b17c134d24cf60e1d26c033b5f4f247b759149619ac0aac341b950a10ccf14.zip",
39
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
40
+ }
41
+ }
42
+ },
43
+ "f2d30cfc360482320a52a4fcde8a70f3569df79ab30be24650fda58eb60052cf": {
44
+ "source": {
45
+ "path": "asset.f2d30cfc360482320a52a4fcde8a70f3569df79ab30be24650fda58eb60052cf",
46
+ "packaging": "zip"
47
+ },
48
+ "destinations": {
49
+ "current_account-current_region": {
50
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
51
+ "objectKey": "f2d30cfc360482320a52a4fcde8a70f3569df79ab30be24650fda58eb60052cf.zip",
52
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
53
+ }
54
+ }
55
+ },
56
+ "157ba1713f7224463b621261792d18081588ff306a9bc3f75e6c468fabbe1a60": {
57
+ "source": {
58
+ "path": "asset.157ba1713f7224463b621261792d18081588ff306a9bc3f75e6c468fabbe1a60",
59
+ "packaging": "zip"
60
+ },
61
+ "destinations": {
62
+ "current_account-current_region": {
63
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
64
+ "objectKey": "157ba1713f7224463b621261792d18081588ff306a9bc3f75e6c468fabbe1a60.zip",
65
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
66
+ }
67
+ }
68
+ },
69
+ "4c079063901e6478dbb5ace19e3123641ebf0da2ab648ecf52079c5bec154196": {
70
+ "source": {
71
+ "path": "asset.4c079063901e6478dbb5ace19e3123641ebf0da2ab648ecf52079c5bec154196",
72
+ "packaging": "zip"
73
+ },
74
+ "destinations": {
75
+ "current_account-current_region": {
76
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
77
+ "objectKey": "4c079063901e6478dbb5ace19e3123641ebf0da2ab648ecf52079c5bec154196.zip",
78
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
79
+ }
80
+ }
81
+ },
82
+ "7e8a681794eff5fda1841caa360113df5488ecf944055a69b8f1e5a687e269f5": {
83
+ "source": {
84
+ "path": "asset.7e8a681794eff5fda1841caa360113df5488ecf944055a69b8f1e5a687e269f5",
85
+ "packaging": "zip"
86
+ },
87
+ "destinations": {
88
+ "current_account-current_region": {
89
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
90
+ "objectKey": "7e8a681794eff5fda1841caa360113df5488ecf944055a69b8f1e5a687e269f5.zip",
91
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
92
+ }
93
+ }
94
+ },
95
+ "9572b451243318765beb576ae7528096b3879783dbaab795c02c01d7f4e83438": {
96
+ "source": {
97
+ "path": "asset.9572b451243318765beb576ae7528096b3879783dbaab795c02c01d7f4e83438",
98
+ "packaging": "zip"
99
+ },
100
+ "destinations": {
101
+ "current_account-current_region": {
102
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
103
+ "objectKey": "9572b451243318765beb576ae7528096b3879783dbaab795c02c01d7f4e83438.zip",
104
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
105
+ }
106
+ }
107
+ },
108
+ "b8448324ef2c7d5bfa362722df2d397079d5aabaae2749f09180ac5bedfa5c89": {
109
+ "source": {
110
+ "path": "asset.b8448324ef2c7d5bfa362722df2d397079d5aabaae2749f09180ac5bedfa5c89",
111
+ "packaging": "zip"
112
+ },
113
+ "destinations": {
114
+ "current_account-current_region": {
115
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
116
+ "objectKey": "b8448324ef2c7d5bfa362722df2d397079d5aabaae2749f09180ac5bedfa5c89.zip",
117
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
118
+ }
119
+ }
120
+ },
121
+ "78b64aaf9aebb4eacbdd42197be10e9d5894360a642f7dcf79aeb84bb3552377": {
122
+ "source": {
123
+ "path": "asset.78b64aaf9aebb4eacbdd42197be10e9d5894360a642f7dcf79aeb84bb3552377",
124
+ "packaging": "zip"
125
+ },
126
+ "destinations": {
127
+ "current_account-current_region": {
128
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
129
+ "objectKey": "78b64aaf9aebb4eacbdd42197be10e9d5894360a642f7dcf79aeb84bb3552377.zip",
130
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
131
+ }
132
+ }
133
+ },
134
+ "d2b520d86fd9d964c83dc0d5ce2e4456dbde5fa7ae0c791a71865cbdfe2fb855": {
135
+ "source": {
136
+ "path": "asset.d2b520d86fd9d964c83dc0d5ce2e4456dbde5fa7ae0c791a71865cbdfe2fb855",
137
+ "packaging": "zip"
138
+ },
139
+ "destinations": {
140
+ "current_account-current_region": {
141
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
142
+ "objectKey": "d2b520d86fd9d964c83dc0d5ce2e4456dbde5fa7ae0c791a71865cbdfe2fb855.zip",
143
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
144
+ }
145
+ }
146
+ },
147
+ "29df648400c115f86c87fc9f5bdb95120b46d2d1c8adfa2b2064e33731fb830b": {
148
+ "source": {
149
+ "path": "RootmailIntegTestStack.template.json",
150
+ "packaging": "file"
151
+ },
152
+ "destinations": {
153
+ "current_account-current_region": {
154
+ "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
155
+ "objectKey": "29df648400c115f86c87fc9f5bdb95120b46d2d1c8adfa2b2064e33731fb830b.json",
156
+ "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
157
+ }
158
+ }
159
+ }
160
+ },
161
+ "dockerImages": {}
162
+ }