@stacksjs/ts-cloud-core 0.1.1
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.
- package/LICENSE.md +21 -0
- package/README.md +321 -0
- package/package.json +31 -0
- package/src/advanced-features.test.ts +465 -0
- package/src/aws/cloudformation.ts +421 -0
- package/src/aws/cloudfront.ts +158 -0
- package/src/aws/credentials.test.ts +132 -0
- package/src/aws/credentials.ts +545 -0
- package/src/aws/index.ts +87 -0
- package/src/aws/s3.test.ts +188 -0
- package/src/aws/s3.ts +1088 -0
- package/src/aws/signature.test.ts +670 -0
- package/src/aws/signature.ts +1155 -0
- package/src/backup/disaster-recovery.test.ts +726 -0
- package/src/backup/disaster-recovery.ts +500 -0
- package/src/backup/index.ts +34 -0
- package/src/backup/manager.test.ts +498 -0
- package/src/backup/manager.ts +432 -0
- package/src/cicd/circleci.ts +430 -0
- package/src/cicd/github-actions.ts +424 -0
- package/src/cicd/gitlab-ci.ts +255 -0
- package/src/cicd/index.ts +8 -0
- package/src/cli/history.ts +396 -0
- package/src/cli/index.ts +10 -0
- package/src/cli/progress.ts +458 -0
- package/src/cli/repl.ts +454 -0
- package/src/cli/suggestions.ts +327 -0
- package/src/cli/table.test.ts +319 -0
- package/src/cli/table.ts +332 -0
- package/src/cloudformation/builder.test.ts +327 -0
- package/src/cloudformation/builder.ts +378 -0
- package/src/cloudformation/builders/api-gateway.ts +449 -0
- package/src/cloudformation/builders/cache.ts +334 -0
- package/src/cloudformation/builders/cdn.ts +278 -0
- package/src/cloudformation/builders/compute.ts +485 -0
- package/src/cloudformation/builders/database.ts +392 -0
- package/src/cloudformation/builders/functions.ts +343 -0
- package/src/cloudformation/builders/messaging.ts +140 -0
- package/src/cloudformation/builders/monitoring.ts +300 -0
- package/src/cloudformation/builders/network.ts +264 -0
- package/src/cloudformation/builders/queue.ts +147 -0
- package/src/cloudformation/builders/security.ts +399 -0
- package/src/cloudformation/builders/storage.ts +285 -0
- package/src/cloudformation/index.ts +30 -0
- package/src/cloudformation/types.ts +173 -0
- package/src/compliance/aws-config.ts +543 -0
- package/src/compliance/cloudtrail.ts +376 -0
- package/src/compliance/compliance.test.ts +423 -0
- package/src/compliance/guardduty.ts +446 -0
- package/src/compliance/index.ts +66 -0
- package/src/compliance/security-hub.ts +456 -0
- package/src/containers/build-optimization.ts +416 -0
- package/src/containers/containers.test.ts +508 -0
- package/src/containers/image-scanning.ts +360 -0
- package/src/containers/index.ts +9 -0
- package/src/containers/registry.ts +293 -0
- package/src/containers/service-mesh.ts +520 -0
- package/src/database/database.test.ts +762 -0
- package/src/database/index.ts +9 -0
- package/src/database/migrations.ts +444 -0
- package/src/database/performance.ts +528 -0
- package/src/database/replicas.ts +534 -0
- package/src/database/users.ts +494 -0
- package/src/dependency-graph.ts +143 -0
- package/src/deployment/ab-testing.ts +582 -0
- package/src/deployment/blue-green.ts +452 -0
- package/src/deployment/canary.ts +500 -0
- package/src/deployment/deployment.test.ts +526 -0
- package/src/deployment/index.ts +61 -0
- package/src/deployment/progressive.ts +62 -0
- package/src/dns/dns.test.ts +641 -0
- package/src/dns/dnssec.ts +315 -0
- package/src/dns/index.ts +8 -0
- package/src/dns/resolver.ts +496 -0
- package/src/dns/routing.ts +593 -0
- package/src/email/advanced/analytics.ts +445 -0
- package/src/email/advanced/index.ts +11 -0
- package/src/email/advanced/rules.ts +465 -0
- package/src/email/advanced/scheduling.ts +352 -0
- package/src/email/advanced/search.ts +412 -0
- package/src/email/advanced/shared-mailboxes.ts +404 -0
- package/src/email/advanced/templates.ts +455 -0
- package/src/email/advanced/threading.ts +281 -0
- package/src/email/analytics.ts +467 -0
- package/src/email/bounce-handling.ts +425 -0
- package/src/email/email.test.ts +431 -0
- package/src/email/handlers/__tests__/inbound.test.ts +38 -0
- package/src/email/handlers/__tests__/outbound.test.ts +37 -0
- package/src/email/handlers/converter.ts +227 -0
- package/src/email/handlers/feedback.ts +228 -0
- package/src/email/handlers/inbound.ts +169 -0
- package/src/email/handlers/outbound.ts +178 -0
- package/src/email/index.ts +15 -0
- package/src/email/reputation.ts +303 -0
- package/src/email/templates.ts +352 -0
- package/src/errors/index.test.ts +434 -0
- package/src/errors/index.ts +416 -0
- package/src/health-checks/index.ts +40 -0
- package/src/index.ts +360 -0
- package/src/intrinsic-functions.ts +118 -0
- package/src/lambda/concurrency.ts +330 -0
- package/src/lambda/destinations.ts +345 -0
- package/src/lambda/dlq.ts +425 -0
- package/src/lambda/index.ts +11 -0
- package/src/lambda/lambda.test.ts +840 -0
- package/src/lambda/layers.ts +263 -0
- package/src/lambda/versions.ts +376 -0
- package/src/lambda/vpc.ts +399 -0
- package/src/local/config.ts +114 -0
- package/src/local/index.ts +6 -0
- package/src/local/mock-aws.ts +351 -0
- package/src/modules/ai.ts +340 -0
- package/src/modules/api.ts +478 -0
- package/src/modules/auth.ts +805 -0
- package/src/modules/cache.ts +417 -0
- package/src/modules/cdn.ts +1062 -0
- package/src/modules/communication.ts +1094 -0
- package/src/modules/compute.ts +3348 -0
- package/src/modules/database.ts +554 -0
- package/src/modules/deployment.ts +1079 -0
- package/src/modules/dns.ts +337 -0
- package/src/modules/email.ts +1538 -0
- package/src/modules/filesystem.ts +515 -0
- package/src/modules/index.ts +32 -0
- package/src/modules/messaging.ts +486 -0
- package/src/modules/monitoring.ts +2086 -0
- package/src/modules/network.ts +664 -0
- package/src/modules/parameter-store.ts +325 -0
- package/src/modules/permissions.ts +1081 -0
- package/src/modules/phone.ts +494 -0
- package/src/modules/queue.ts +1260 -0
- package/src/modules/redirects.ts +464 -0
- package/src/modules/registry.ts +699 -0
- package/src/modules/search.ts +401 -0
- package/src/modules/secrets.ts +416 -0
- package/src/modules/security.ts +731 -0
- package/src/modules/sms.ts +389 -0
- package/src/modules/storage.ts +1120 -0
- package/src/modules/workflow.ts +680 -0
- package/src/multi-account/config.ts +521 -0
- package/src/multi-account/index.ts +7 -0
- package/src/multi-account/manager.ts +427 -0
- package/src/multi-region/cross-region.ts +410 -0
- package/src/multi-region/index.ts +8 -0
- package/src/multi-region/manager.ts +483 -0
- package/src/multi-region/regions.ts +435 -0
- package/src/network-security/index.ts +48 -0
- package/src/observability/index.ts +9 -0
- package/src/observability/logs.ts +522 -0
- package/src/observability/metrics.ts +460 -0
- package/src/observability/observability.test.ts +782 -0
- package/src/observability/synthetics.ts +568 -0
- package/src/observability/xray.ts +358 -0
- package/src/phone/advanced/analytics.ts +349 -0
- package/src/phone/advanced/callbacks.ts +428 -0
- package/src/phone/advanced/index.ts +8 -0
- package/src/phone/advanced/ivr-builder.ts +504 -0
- package/src/phone/advanced/recording.ts +310 -0
- package/src/phone/handlers/__tests__/incoming-call.test.ts +40 -0
- package/src/phone/handlers/incoming-call.ts +117 -0
- package/src/phone/handlers/missed-call.ts +116 -0
- package/src/phone/handlers/voicemail.ts +179 -0
- package/src/phone/index.ts +9 -0
- package/src/presets/api-backend.ts +134 -0
- package/src/presets/data-pipeline.ts +204 -0
- package/src/presets/extend.test.ts +295 -0
- package/src/presets/extend.ts +297 -0
- package/src/presets/fullstack-app.ts +144 -0
- package/src/presets/index.ts +27 -0
- package/src/presets/jamstack.ts +135 -0
- package/src/presets/microservices.ts +167 -0
- package/src/presets/ml-api.ts +208 -0
- package/src/presets/nodejs-server.ts +104 -0
- package/src/presets/nodejs-serverless.ts +114 -0
- package/src/presets/realtime-app.ts +184 -0
- package/src/presets/static-site.ts +64 -0
- package/src/presets/traditional-web-app.ts +339 -0
- package/src/presets/wordpress.ts +138 -0
- package/src/preview/github.test.ts +249 -0
- package/src/preview/github.ts +297 -0
- package/src/preview/index.ts +37 -0
- package/src/preview/manager.test.ts +440 -0
- package/src/preview/manager.ts +326 -0
- package/src/preview/notifications.test.ts +582 -0
- package/src/preview/notifications.ts +341 -0
- package/src/queue/batch-processing.ts +402 -0
- package/src/queue/dlq-monitoring.ts +402 -0
- package/src/queue/fifo.ts +342 -0
- package/src/queue/index.ts +9 -0
- package/src/queue/management.ts +428 -0
- package/src/queue/queue.test.ts +429 -0
- package/src/resource-mgmt/index.ts +39 -0
- package/src/resource-naming.ts +62 -0
- package/src/s3/index.ts +523 -0
- package/src/schema/cloud-config.schema.json +554 -0
- package/src/schema/index.ts +68 -0
- package/src/security/certificate-manager.ts +492 -0
- package/src/security/index.ts +9 -0
- package/src/security/scanning.ts +545 -0
- package/src/security/secrets-manager.ts +476 -0
- package/src/security/secrets-rotation.ts +456 -0
- package/src/security/security.test.ts +738 -0
- package/src/sms/advanced/ab-testing.ts +389 -0
- package/src/sms/advanced/analytics.ts +336 -0
- package/src/sms/advanced/campaigns.ts +523 -0
- package/src/sms/advanced/chatbot.ts +224 -0
- package/src/sms/advanced/index.ts +10 -0
- package/src/sms/advanced/link-tracking.ts +248 -0
- package/src/sms/advanced/mms.ts +308 -0
- package/src/sms/handlers/__tests__/send.test.ts +40 -0
- package/src/sms/handlers/delivery-status.ts +133 -0
- package/src/sms/handlers/receive.ts +162 -0
- package/src/sms/handlers/send.ts +174 -0
- package/src/sms/index.ts +9 -0
- package/src/stack-diff.ts +389 -0
- package/src/static-site/index.ts +85 -0
- package/src/template-builder.ts +110 -0
- package/src/template-validator.ts +574 -0
- package/src/utils/cache.ts +291 -0
- package/src/utils/diff.ts +269 -0
- package/src/utils/hash.ts +227 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/parallel.ts +294 -0
- package/src/validators/credentials.test.ts +274 -0
- package/src/validators/credentials.ts +233 -0
- package/src/validators/quotas.test.ts +434 -0
- package/src/validators/quotas.ts +217 -0
- package/test/ai.test.ts +327 -0
- package/test/api.test.ts +511 -0
- package/test/auth.test.ts +632 -0
- package/test/cache.test.ts +406 -0
- package/test/cdn.test.ts +247 -0
- package/test/compute.test.ts +861 -0
- package/test/database.test.ts +523 -0
- package/test/deployment.test.ts +499 -0
- package/test/dns.test.ts +270 -0
- package/test/email.test.ts +439 -0
- package/test/filesystem.test.ts +382 -0
- package/test/integration.test.ts +350 -0
- package/test/messaging.test.ts +514 -0
- package/test/monitoring.test.ts +634 -0
- package/test/network.test.ts +425 -0
- package/test/permissions.test.ts +488 -0
- package/test/queue.test.ts +484 -0
- package/test/registry.test.ts +306 -0
- package/test/security.test.ts +462 -0
- package/test/storage.test.ts +463 -0
- package/test/template-validator.test.ts +559 -0
- package/test/workflow.test.ts +592 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { Auth } from '../src/modules/auth'
|
|
3
|
+
import { TemplateBuilder } from '../src/template-builder'
|
|
4
|
+
import type { EnvironmentType } from '@stacksjs/ts-cloud-types'
|
|
5
|
+
|
|
6
|
+
const slug = 'test-app'
|
|
7
|
+
const environment: EnvironmentType = 'development'
|
|
8
|
+
|
|
9
|
+
describe('auth Module - User Pool', () => {
|
|
10
|
+
test('should create a basic user pool', () => {
|
|
11
|
+
const { userPool, logicalId } = Auth.createUserPool({
|
|
12
|
+
slug,
|
|
13
|
+
environment,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
expect(userPool.Type).toBe('AWS::Cognito::UserPool')
|
|
17
|
+
expect(userPool.Properties?.UserPoolName).toContain('test-app')
|
|
18
|
+
expect(logicalId).toBeTruthy()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('should create a user pool with custom name', () => {
|
|
22
|
+
const { userPool } = Auth.createUserPool({
|
|
23
|
+
slug,
|
|
24
|
+
environment,
|
|
25
|
+
userPoolName: 'my-custom-pool',
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
expect(userPool.Properties?.UserPoolName).toBe('my-custom-pool')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('should create a user pool with alias attributes', () => {
|
|
32
|
+
const { userPool } = Auth.createUserPool({
|
|
33
|
+
slug,
|
|
34
|
+
environment,
|
|
35
|
+
aliasAttributes: ['email', 'phone_number'],
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
expect(userPool.Properties?.UsernameAttributes).toEqual(['email', 'phone_number'])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
test('should create a user pool with auto-verified attributes', () => {
|
|
42
|
+
const { userPool } = Auth.createUserPool({
|
|
43
|
+
slug,
|
|
44
|
+
environment,
|
|
45
|
+
autoVerifiedAttributes: ['email'],
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
expect(userPool.Properties?.AutoVerifiedAttributes).toEqual(['email'])
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('should create a user pool with password policy', () => {
|
|
52
|
+
const { userPool } = Auth.createUserPool({
|
|
53
|
+
slug,
|
|
54
|
+
environment,
|
|
55
|
+
passwordPolicy: {
|
|
56
|
+
minimumLength: 12,
|
|
57
|
+
requireLowercase: true,
|
|
58
|
+
requireUppercase: true,
|
|
59
|
+
requireNumbers: true,
|
|
60
|
+
requireSymbols: true,
|
|
61
|
+
temporaryPasswordValidityDays: 7,
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
expect(userPool.Properties?.Policies?.PasswordPolicy?.MinimumLength).toBe(12)
|
|
66
|
+
expect(userPool.Properties?.Policies?.PasswordPolicy?.RequireLowercase).toBe(true)
|
|
67
|
+
expect(userPool.Properties?.Policies?.PasswordPolicy?.RequireUppercase).toBe(true)
|
|
68
|
+
expect(userPool.Properties?.Policies?.PasswordPolicy?.RequireNumbers).toBe(true)
|
|
69
|
+
expect(userPool.Properties?.Policies?.PasswordPolicy?.RequireSymbols).toBe(true)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test('should create a user pool with MFA configuration', () => {
|
|
73
|
+
const { userPool } = Auth.createUserPool({
|
|
74
|
+
slug,
|
|
75
|
+
environment,
|
|
76
|
+
mfaConfiguration: 'OPTIONAL',
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
expect(userPool.Properties?.MfaConfiguration).toBe('OPTIONAL')
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('should create a user pool with email configuration', () => {
|
|
83
|
+
const { userPool } = Auth.createUserPool({
|
|
84
|
+
slug,
|
|
85
|
+
environment,
|
|
86
|
+
emailConfiguration: {
|
|
87
|
+
emailSendingAccount: 'DEVELOPER',
|
|
88
|
+
from: 'noreply@example.com',
|
|
89
|
+
replyToEmailAddress: 'support@example.com',
|
|
90
|
+
sourceArn: 'arn:aws:ses:us-east-1:123456789012:identity/example.com',
|
|
91
|
+
},
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
expect(userPool.Properties?.EmailConfiguration?.EmailSendingAccount).toBe('DEVELOPER')
|
|
95
|
+
expect(userPool.Properties?.EmailConfiguration?.From).toBe('noreply@example.com')
|
|
96
|
+
expect(userPool.Properties?.EmailConfiguration?.ReplyToEmailAddress).toBe('support@example.com')
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
test('should create a user pool with Lambda triggers', () => {
|
|
100
|
+
const { userPool } = Auth.createUserPool({
|
|
101
|
+
slug,
|
|
102
|
+
environment,
|
|
103
|
+
lambdaTriggers: {
|
|
104
|
+
preSignUp: 'arn:aws:lambda:us-east-1:123456789012:function:pre-signup',
|
|
105
|
+
postConfirmation: 'arn:aws:lambda:us-east-1:123456789012:function:post-confirmation',
|
|
106
|
+
},
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
expect(userPool.Properties?.LambdaConfig?.PreSignUp).toBe('arn:aws:lambda:us-east-1:123456789012:function:pre-signup')
|
|
110
|
+
expect(userPool.Properties?.LambdaConfig?.PostConfirmation).toBe('arn:aws:lambda:us-east-1:123456789012:function:post-confirmation')
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
test('should create a user pool with advanced security mode', () => {
|
|
114
|
+
const { userPool } = Auth.createUserPool({
|
|
115
|
+
slug,
|
|
116
|
+
environment,
|
|
117
|
+
userPoolAddOns: {
|
|
118
|
+
advancedSecurityMode: 'ENFORCED',
|
|
119
|
+
},
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
expect(userPool.Properties?.UserPoolAddOns?.AdvancedSecurityMode).toBe('ENFORCED')
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('should create a user pool with account recovery settings', () => {
|
|
126
|
+
const { userPool } = Auth.createUserPool({
|
|
127
|
+
slug,
|
|
128
|
+
environment,
|
|
129
|
+
accountRecoverySetting: {
|
|
130
|
+
recoveryMechanisms: [
|
|
131
|
+
{ Name: 'verified_email', Priority: 1 },
|
|
132
|
+
{ Name: 'verified_phone_number', Priority: 2 },
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
expect(userPool.Properties?.AccountRecoverySetting?.RecoveryMechanisms).toHaveLength(2)
|
|
138
|
+
expect(userPool.Properties?.AccountRecoverySetting?.RecoveryMechanisms?.[0].Name).toBe('verified_email')
|
|
139
|
+
})
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
describe('auth Module - User Pool Client', () => {
|
|
143
|
+
test('should create a basic user pool client', () => {
|
|
144
|
+
const { logicalId: poolId } = Auth.createUserPool({
|
|
145
|
+
slug,
|
|
146
|
+
environment,
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
const { client, logicalId } = Auth.createUserPoolClient(poolId, {
|
|
150
|
+
slug,
|
|
151
|
+
environment,
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
expect(client.Type).toBe('AWS::Cognito::UserPoolClient')
|
|
155
|
+
expect(client.Properties?.ClientName).toContain('test-app')
|
|
156
|
+
expect(logicalId).toBeTruthy()
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
test('should create a client with custom name', () => {
|
|
160
|
+
const { logicalId: poolId } = Auth.createUserPool({
|
|
161
|
+
slug,
|
|
162
|
+
environment,
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const { client } = Auth.createUserPoolClient(poolId, {
|
|
166
|
+
slug,
|
|
167
|
+
environment,
|
|
168
|
+
clientName: 'my-app-client',
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
expect(client.Properties?.ClientName).toBe('my-app-client')
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
test('should create a client with secret', () => {
|
|
175
|
+
const { logicalId: poolId } = Auth.createUserPool({
|
|
176
|
+
slug,
|
|
177
|
+
environment,
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
const { client } = Auth.createUserPoolClient(poolId, {
|
|
181
|
+
slug,
|
|
182
|
+
environment,
|
|
183
|
+
generateSecret: true,
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
expect(client.Properties?.GenerateSecret).toBe(true)
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('should create a client with token validity', () => {
|
|
190
|
+
const { logicalId: poolId } = Auth.createUserPool({
|
|
191
|
+
slug,
|
|
192
|
+
environment,
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
const { client } = Auth.createUserPoolClient(poolId, {
|
|
196
|
+
slug,
|
|
197
|
+
environment,
|
|
198
|
+
refreshTokenValidity: 30,
|
|
199
|
+
accessTokenValidity: 60,
|
|
200
|
+
idTokenValidity: 60,
|
|
201
|
+
tokenValidityUnits: {
|
|
202
|
+
RefreshToken: 'days',
|
|
203
|
+
AccessToken: 'minutes',
|
|
204
|
+
IdToken: 'minutes',
|
|
205
|
+
},
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
expect(client.Properties?.RefreshTokenValidity).toBe(30)
|
|
209
|
+
expect(client.Properties?.AccessTokenValidity).toBe(60)
|
|
210
|
+
expect(client.Properties?.IdTokenValidity).toBe(60)
|
|
211
|
+
expect(client.Properties?.TokenValidityUnits?.RefreshToken).toBe('days')
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
test('should create a client with explicit auth flows', () => {
|
|
215
|
+
const { logicalId: poolId } = Auth.createUserPool({
|
|
216
|
+
slug,
|
|
217
|
+
environment,
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
const { client } = Auth.createUserPoolClient(poolId, {
|
|
221
|
+
slug,
|
|
222
|
+
environment,
|
|
223
|
+
explicitAuthFlows: [...Auth.AuthFlows.standard],
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
expect(client.Properties?.ExplicitAuthFlows).toContain('ALLOW_USER_SRP_AUTH')
|
|
227
|
+
expect(client.Properties?.ExplicitAuthFlows).toContain('ALLOW_REFRESH_TOKEN_AUTH')
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
test('should create a client with OAuth configuration', () => {
|
|
231
|
+
const { logicalId: poolId } = Auth.createUserPool({
|
|
232
|
+
slug,
|
|
233
|
+
environment,
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
const { client } = Auth.createUserPoolClient(poolId, {
|
|
237
|
+
slug,
|
|
238
|
+
environment,
|
|
239
|
+
callbackURLs: ['https://example.com/callback'],
|
|
240
|
+
logoutURLs: ['https://example.com/logout'],
|
|
241
|
+
allowedOAuthFlows: ['code'],
|
|
242
|
+
allowedOAuthScopes: [...Auth.OAuthScopes.basic],
|
|
243
|
+
allowedOAuthFlowsUserPoolClient: true,
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
expect(client.Properties?.CallbackURLs).toEqual(['https://example.com/callback'])
|
|
247
|
+
expect(client.Properties?.LogoutURLs).toEqual(['https://example.com/logout'])
|
|
248
|
+
expect(client.Properties?.AllowedOAuthFlows).toEqual(['code'])
|
|
249
|
+
expect(client.Properties?.AllowedOAuthScopes).toContain('openid')
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
test('should create a client with token revocation enabled', () => {
|
|
253
|
+
const { logicalId: poolId } = Auth.createUserPool({
|
|
254
|
+
slug,
|
|
255
|
+
environment,
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
const { client } = Auth.createUserPoolClient(poolId, {
|
|
259
|
+
slug,
|
|
260
|
+
environment,
|
|
261
|
+
enableTokenRevocation: true,
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
expect(client.Properties?.EnableTokenRevocation).toBe(true)
|
|
265
|
+
})
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
describe('auth Module - User Pool Domain', () => {
|
|
269
|
+
test('should create a user pool domain', () => {
|
|
270
|
+
const { logicalId: poolId } = Auth.createUserPool({
|
|
271
|
+
slug,
|
|
272
|
+
environment,
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
const { domain, logicalId } = Auth.createUserPoolDomain(poolId, {
|
|
276
|
+
slug,
|
|
277
|
+
environment,
|
|
278
|
+
domain: 'my-app-auth',
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
expect(domain.Type).toBe('AWS::Cognito::UserPoolDomain')
|
|
282
|
+
expect(domain.Properties?.Domain).toBe('my-app-auth')
|
|
283
|
+
expect(logicalId).toBeTruthy()
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
test('should create a custom domain', () => {
|
|
287
|
+
const { logicalId: poolId } = Auth.createUserPool({
|
|
288
|
+
slug,
|
|
289
|
+
environment,
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
const { domain } = Auth.createUserPoolDomain(poolId, {
|
|
293
|
+
slug,
|
|
294
|
+
environment,
|
|
295
|
+
domain: 'auth.example.com',
|
|
296
|
+
customDomainConfig: {
|
|
297
|
+
CertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/12345678',
|
|
298
|
+
},
|
|
299
|
+
})
|
|
300
|
+
|
|
301
|
+
expect(domain.Properties?.Domain).toBe('auth.example.com')
|
|
302
|
+
expect(domain.Properties?.CustomDomainConfig?.CertificateArn).toBeTruthy()
|
|
303
|
+
})
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
describe('auth Module - Identity Pool', () => {
|
|
307
|
+
test('should create a basic identity pool', () => {
|
|
308
|
+
const { identityPool, logicalId } = Auth.createIdentityPool({
|
|
309
|
+
slug,
|
|
310
|
+
environment,
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
expect(identityPool.Type).toBe('AWS::Cognito::IdentityPool')
|
|
314
|
+
expect(identityPool.Properties?.IdentityPoolName).toContain('test-app')
|
|
315
|
+
expect(identityPool.Properties?.AllowUnauthenticatedIdentities).toBe(false)
|
|
316
|
+
expect(logicalId).toBeTruthy()
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
test('should create an identity pool with custom name', () => {
|
|
320
|
+
const { identityPool } = Auth.createIdentityPool({
|
|
321
|
+
slug,
|
|
322
|
+
environment,
|
|
323
|
+
identityPoolName: 'my-identity-pool',
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
expect(identityPool.Properties?.IdentityPoolName).toBe('my-identity-pool')
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
test('should create an identity pool allowing unauthenticated access', () => {
|
|
330
|
+
const { identityPool } = Auth.createIdentityPool({
|
|
331
|
+
slug,
|
|
332
|
+
environment,
|
|
333
|
+
allowUnauthenticatedIdentities: true,
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
expect(identityPool.Properties?.AllowUnauthenticatedIdentities).toBe(true)
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
test('should create an identity pool with Cognito provider', () => {
|
|
340
|
+
const { identityPool } = Auth.createIdentityPool({
|
|
341
|
+
slug,
|
|
342
|
+
environment,
|
|
343
|
+
cognitoIdentityProviders: [
|
|
344
|
+
{
|
|
345
|
+
ClientId: 'abc123',
|
|
346
|
+
ProviderName: 'cognito-idp.us-east-1.amazonaws.com/us-east-1_ABC123',
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
expect(identityPool.Properties?.CognitoIdentityProviders).toHaveLength(1)
|
|
352
|
+
expect(identityPool.Properties?.CognitoIdentityProviders?.[0].ClientId).toBe('abc123')
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
test('should create an identity pool with social providers', () => {
|
|
356
|
+
const { identityPool } = Auth.createIdentityPool({
|
|
357
|
+
slug,
|
|
358
|
+
environment,
|
|
359
|
+
supportedLoginProviders: {
|
|
360
|
+
'accounts.google.com': 'google-client-id',
|
|
361
|
+
'graph.facebook.com': 'facebook-app-id',
|
|
362
|
+
},
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
expect(identityPool.Properties?.SupportedLoginProviders).toBeDefined()
|
|
366
|
+
expect(identityPool.Properties?.SupportedLoginProviders?.['accounts.google.com']).toBe('google-client-id')
|
|
367
|
+
})
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
describe('auth Module - Identity Pool Roles', () => {
|
|
371
|
+
test('should create authenticated role', () => {
|
|
372
|
+
const { logicalId: identityPoolId } = Auth.createIdentityPool({
|
|
373
|
+
slug,
|
|
374
|
+
environment,
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
const { role, logicalId } = Auth.createAuthenticatedRole({
|
|
378
|
+
slug,
|
|
379
|
+
environment,
|
|
380
|
+
identityPoolLogicalId: identityPoolId,
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
expect(role.Type).toBe('AWS::IAM::Role')
|
|
384
|
+
expect(role.Properties?.RoleName).toContain('cognito-authenticated-role')
|
|
385
|
+
expect(role.Properties?.AssumeRolePolicyDocument?.Statement?.[0].Principal?.Federated).toBe('cognito-identity.amazonaws.com')
|
|
386
|
+
expect(logicalId).toBeTruthy()
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
test('should create unauthenticated role', () => {
|
|
390
|
+
const { logicalId: identityPoolId } = Auth.createIdentityPool({
|
|
391
|
+
slug,
|
|
392
|
+
environment,
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
const { role, logicalId } = Auth.createUnauthenticatedRole({
|
|
396
|
+
slug,
|
|
397
|
+
environment,
|
|
398
|
+
identityPoolLogicalId: identityPoolId,
|
|
399
|
+
})
|
|
400
|
+
|
|
401
|
+
expect(role.Type).toBe('AWS::IAM::Role')
|
|
402
|
+
expect(role.Properties?.RoleName).toContain('cognito-unauthenticated-role')
|
|
403
|
+
expect(logicalId).toBeTruthy()
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
test('should create identity pool role attachment', () => {
|
|
407
|
+
const { logicalId: identityPoolId } = Auth.createIdentityPool({
|
|
408
|
+
slug,
|
|
409
|
+
environment,
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
const { attachment, logicalId } = Auth.createIdentityPoolRoleAttachment(identityPoolId, {
|
|
413
|
+
slug,
|
|
414
|
+
environment,
|
|
415
|
+
authenticatedRole: 'arn:aws:iam::123456789012:role/Cognito_AuthRole',
|
|
416
|
+
unauthenticatedRole: 'arn:aws:iam::123456789012:role/Cognito_UnauthRole',
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
expect(attachment.Type).toBe('AWS::Cognito::IdentityPoolRoleAttachment')
|
|
420
|
+
expect(attachment.Properties?.Roles?.authenticated).toBeTruthy()
|
|
421
|
+
expect(attachment.Properties?.Roles?.unauthenticated).toBeTruthy()
|
|
422
|
+
expect(logicalId).toBeTruthy()
|
|
423
|
+
})
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
describe('auth Module - Password Policies', () => {
|
|
427
|
+
test('should have relaxed password policy', () => {
|
|
428
|
+
const policy = Auth.PasswordPolicies.relaxed()
|
|
429
|
+
|
|
430
|
+
expect(policy.minimumLength).toBe(8)
|
|
431
|
+
expect(policy.requireLowercase).toBe(false)
|
|
432
|
+
expect(policy.requireUppercase).toBe(false)
|
|
433
|
+
expect(policy.requireNumbers).toBe(false)
|
|
434
|
+
expect(policy.requireSymbols).toBe(false)
|
|
435
|
+
})
|
|
436
|
+
|
|
437
|
+
test('should have standard password policy', () => {
|
|
438
|
+
const policy = Auth.PasswordPolicies.standard()
|
|
439
|
+
|
|
440
|
+
expect(policy.minimumLength).toBe(8)
|
|
441
|
+
expect(policy.requireLowercase).toBe(true)
|
|
442
|
+
expect(policy.requireUppercase).toBe(true)
|
|
443
|
+
expect(policy.requireNumbers).toBe(true)
|
|
444
|
+
expect(policy.requireSymbols).toBe(false)
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
test('should have strict password policy', () => {
|
|
448
|
+
const policy = Auth.PasswordPolicies.strict()
|
|
449
|
+
|
|
450
|
+
expect(policy.minimumLength).toBe(12)
|
|
451
|
+
expect(policy.requireLowercase).toBe(true)
|
|
452
|
+
expect(policy.requireUppercase).toBe(true)
|
|
453
|
+
expect(policy.requireNumbers).toBe(true)
|
|
454
|
+
expect(policy.requireSymbols).toBe(true)
|
|
455
|
+
})
|
|
456
|
+
})
|
|
457
|
+
|
|
458
|
+
describe('auth Module - Auth Flows', () => {
|
|
459
|
+
test('should have standard auth flows', () => {
|
|
460
|
+
expect(Auth.AuthFlows.standard).toContain('ALLOW_USER_SRP_AUTH')
|
|
461
|
+
expect(Auth.AuthFlows.standard).toContain('ALLOW_REFRESH_TOKEN_AUTH')
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
test('should have admin auth flows', () => {
|
|
465
|
+
expect(Auth.AuthFlows.admin).toContain('ALLOW_ADMIN_USER_PASSWORD_AUTH')
|
|
466
|
+
expect(Auth.AuthFlows.admin).toContain('ALLOW_REFRESH_TOKEN_AUTH')
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
test('should have custom auth flows', () => {
|
|
470
|
+
expect(Auth.AuthFlows.custom).toContain('ALLOW_CUSTOM_AUTH')
|
|
471
|
+
expect(Auth.AuthFlows.custom).toContain('ALLOW_REFRESH_TOKEN_AUTH')
|
|
472
|
+
})
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
describe('auth Module - OAuth Scopes', () => {
|
|
476
|
+
test('should have basic OAuth scopes', () => {
|
|
477
|
+
expect(Auth.OAuthScopes.basic).toContain('openid')
|
|
478
|
+
expect(Auth.OAuthScopes.basic).toContain('email')
|
|
479
|
+
expect(Auth.OAuthScopes.basic).toContain('profile')
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
test('should have all OAuth scopes', () => {
|
|
483
|
+
expect(Auth.OAuthScopes.all).toContain('openid')
|
|
484
|
+
expect(Auth.OAuthScopes.all).toContain('email')
|
|
485
|
+
expect(Auth.OAuthScopes.all).toContain('profile')
|
|
486
|
+
expect(Auth.OAuthScopes.all).toContain('phone')
|
|
487
|
+
expect(Auth.OAuthScopes.all).toContain('aws.cognito.signin.user.admin')
|
|
488
|
+
})
|
|
489
|
+
})
|
|
490
|
+
|
|
491
|
+
describe('auth Module - Use Cases', () => {
|
|
492
|
+
test('should create web app authentication setup', () => {
|
|
493
|
+
const { userPool, poolId, client, clientId } = Auth.UseCases.webApp(
|
|
494
|
+
slug,
|
|
495
|
+
environment,
|
|
496
|
+
'https://example.com/callback',
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
expect(userPool.Type).toBe('AWS::Cognito::UserPool')
|
|
500
|
+
expect(client.Type).toBe('AWS::Cognito::UserPoolClient')
|
|
501
|
+
expect(client.Properties?.AllowedOAuthFlows).toContain('code')
|
|
502
|
+
expect(client.Properties?.CallbackURLs).toContain('https://example.com/callback')
|
|
503
|
+
expect(poolId).toBeTruthy()
|
|
504
|
+
expect(clientId).toBeTruthy()
|
|
505
|
+
})
|
|
506
|
+
|
|
507
|
+
test('should create mobile app authentication setup', () => {
|
|
508
|
+
const {
|
|
509
|
+
userPool,
|
|
510
|
+
poolId,
|
|
511
|
+
client,
|
|
512
|
+
clientId,
|
|
513
|
+
identityPool,
|
|
514
|
+
identityPoolId,
|
|
515
|
+
authRole,
|
|
516
|
+
authRoleId,
|
|
517
|
+
attachment,
|
|
518
|
+
attachmentId,
|
|
519
|
+
} = Auth.UseCases.mobileApp(slug, environment)
|
|
520
|
+
|
|
521
|
+
expect(userPool.Type).toBe('AWS::Cognito::UserPool')
|
|
522
|
+
expect(client.Type).toBe('AWS::Cognito::UserPoolClient')
|
|
523
|
+
expect(identityPool.Type).toBe('AWS::Cognito::IdentityPool')
|
|
524
|
+
expect(authRole.Type).toBe('AWS::IAM::Role')
|
|
525
|
+
expect(attachment.Type).toBe('AWS::Cognito::IdentityPoolRoleAttachment')
|
|
526
|
+
expect(poolId).toBeTruthy()
|
|
527
|
+
expect(clientId).toBeTruthy()
|
|
528
|
+
expect(identityPoolId).toBeTruthy()
|
|
529
|
+
expect(authRoleId).toBeTruthy()
|
|
530
|
+
expect(attachmentId).toBeTruthy()
|
|
531
|
+
})
|
|
532
|
+
})
|
|
533
|
+
|
|
534
|
+
describe('auth Module - Integration with TemplateBuilder', () => {
|
|
535
|
+
test('should add user pool to template', () => {
|
|
536
|
+
const builder = new TemplateBuilder()
|
|
537
|
+
|
|
538
|
+
const { userPool, logicalId } = Auth.createUserPool({
|
|
539
|
+
slug,
|
|
540
|
+
environment,
|
|
541
|
+
passwordPolicy: Auth.PasswordPolicies.standard(),
|
|
542
|
+
mfaConfiguration: 'OPTIONAL',
|
|
543
|
+
})
|
|
544
|
+
|
|
545
|
+
builder.addResource(logicalId, userPool)
|
|
546
|
+
|
|
547
|
+
const template = builder.build()
|
|
548
|
+
|
|
549
|
+
expect(template.Resources[logicalId]).toBeDefined()
|
|
550
|
+
expect(template.Resources[logicalId].Type).toBe('AWS::Cognito::UserPool')
|
|
551
|
+
})
|
|
552
|
+
|
|
553
|
+
test('should add complete authentication stack to template', () => {
|
|
554
|
+
const builder = new TemplateBuilder()
|
|
555
|
+
|
|
556
|
+
const { userPool, logicalId: poolId } = Auth.createUserPool({
|
|
557
|
+
slug,
|
|
558
|
+
environment,
|
|
559
|
+
aliasAttributes: ['email'],
|
|
560
|
+
autoVerifiedAttributes: ['email'],
|
|
561
|
+
passwordPolicy: Auth.PasswordPolicies.standard(),
|
|
562
|
+
})
|
|
563
|
+
|
|
564
|
+
const { client, logicalId: clientId } = Auth.createUserPoolClient(poolId, {
|
|
565
|
+
slug,
|
|
566
|
+
environment,
|
|
567
|
+
explicitAuthFlows: [...Auth.AuthFlows.standard],
|
|
568
|
+
})
|
|
569
|
+
|
|
570
|
+
const { domain, logicalId: domainId } = Auth.createUserPoolDomain(poolId, {
|
|
571
|
+
slug,
|
|
572
|
+
environment,
|
|
573
|
+
domain: 'my-app-auth',
|
|
574
|
+
})
|
|
575
|
+
|
|
576
|
+
builder.addResource(poolId, userPool)
|
|
577
|
+
builder.addResource(clientId, client)
|
|
578
|
+
builder.addResource(domainId, domain)
|
|
579
|
+
|
|
580
|
+
const template = builder.build()
|
|
581
|
+
|
|
582
|
+
expect(Object.keys(template.Resources)).toHaveLength(3)
|
|
583
|
+
expect(template.Resources[poolId].Type).toBe('AWS::Cognito::UserPool')
|
|
584
|
+
expect(template.Resources[clientId].Type).toBe('AWS::Cognito::UserPoolClient')
|
|
585
|
+
expect(template.Resources[domainId].Type).toBe('AWS::Cognito::UserPoolDomain')
|
|
586
|
+
})
|
|
587
|
+
|
|
588
|
+
test('should add identity pool stack to template', () => {
|
|
589
|
+
const builder = new TemplateBuilder()
|
|
590
|
+
|
|
591
|
+
const { identityPool, logicalId: identityPoolId } = Auth.createIdentityPool({
|
|
592
|
+
slug,
|
|
593
|
+
environment,
|
|
594
|
+
allowUnauthenticatedIdentities: false,
|
|
595
|
+
})
|
|
596
|
+
|
|
597
|
+
const { role: authRole, logicalId: authRoleId } = Auth.createAuthenticatedRole({
|
|
598
|
+
slug,
|
|
599
|
+
environment,
|
|
600
|
+
identityPoolLogicalId: identityPoolId,
|
|
601
|
+
})
|
|
602
|
+
|
|
603
|
+
const { role: unauthRole, logicalId: unauthRoleId } = Auth.createUnauthenticatedRole({
|
|
604
|
+
slug,
|
|
605
|
+
environment,
|
|
606
|
+
identityPoolLogicalId: identityPoolId,
|
|
607
|
+
})
|
|
608
|
+
|
|
609
|
+
const { attachment, logicalId: attachmentId } = Auth.createIdentityPoolRoleAttachment(
|
|
610
|
+
identityPoolId,
|
|
611
|
+
{
|
|
612
|
+
slug,
|
|
613
|
+
environment,
|
|
614
|
+
authenticatedRole: `\${${authRoleId}.Arn}`,
|
|
615
|
+
unauthenticatedRole: `\${${unauthRoleId}.Arn}`,
|
|
616
|
+
},
|
|
617
|
+
)
|
|
618
|
+
|
|
619
|
+
builder.addResource(identityPoolId, identityPool)
|
|
620
|
+
builder.addResource(authRoleId, authRole)
|
|
621
|
+
builder.addResource(unauthRoleId, unauthRole)
|
|
622
|
+
builder.addResource(attachmentId, attachment)
|
|
623
|
+
|
|
624
|
+
const template = builder.build()
|
|
625
|
+
|
|
626
|
+
expect(Object.keys(template.Resources)).toHaveLength(4)
|
|
627
|
+
expect(template.Resources[identityPoolId].Type).toBe('AWS::Cognito::IdentityPool')
|
|
628
|
+
expect(template.Resources[authRoleId].Type).toBe('AWS::IAM::Role')
|
|
629
|
+
expect(template.Resources[unauthRoleId].Type).toBe('AWS::IAM::Role')
|
|
630
|
+
expect(template.Resources[attachmentId].Type).toBe('AWS::Cognito::IdentityPoolRoleAttachment')
|
|
631
|
+
})
|
|
632
|
+
})
|