@stacksjs/ts-cloud-core 0.1.2 → 0.1.6
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/README.md +98 -13
- package/package.json +12 -3
- package/src/advanced-features.test.ts +0 -465
- package/src/aws/cloudformation.ts +0 -421
- package/src/aws/cloudfront.ts +0 -158
- package/src/aws/credentials.test.ts +0 -132
- package/src/aws/credentials.ts +0 -545
- package/src/aws/index.ts +0 -87
- package/src/aws/s3.test.ts +0 -188
- package/src/aws/s3.ts +0 -1088
- package/src/aws/signature.test.ts +0 -670
- package/src/aws/signature.ts +0 -1155
- package/src/backup/disaster-recovery.test.ts +0 -726
- package/src/backup/disaster-recovery.ts +0 -500
- package/src/backup/index.ts +0 -34
- package/src/backup/manager.test.ts +0 -498
- package/src/backup/manager.ts +0 -432
- package/src/cicd/circleci.ts +0 -430
- package/src/cicd/github-actions.ts +0 -424
- package/src/cicd/gitlab-ci.ts +0 -255
- package/src/cicd/index.ts +0 -8
- package/src/cli/history.ts +0 -396
- package/src/cli/index.ts +0 -10
- package/src/cli/progress.ts +0 -458
- package/src/cli/repl.ts +0 -454
- package/src/cli/suggestions.ts +0 -327
- package/src/cli/table.test.ts +0 -319
- package/src/cli/table.ts +0 -332
- package/src/cloudformation/builder.test.ts +0 -327
- package/src/cloudformation/builder.ts +0 -378
- package/src/cloudformation/builders/api-gateway.ts +0 -449
- package/src/cloudformation/builders/cache.ts +0 -334
- package/src/cloudformation/builders/cdn.ts +0 -278
- package/src/cloudformation/builders/compute.ts +0 -485
- package/src/cloudformation/builders/database.ts +0 -392
- package/src/cloudformation/builders/functions.ts +0 -343
- package/src/cloudformation/builders/messaging.ts +0 -140
- package/src/cloudformation/builders/monitoring.ts +0 -300
- package/src/cloudformation/builders/network.ts +0 -264
- package/src/cloudformation/builders/queue.ts +0 -147
- package/src/cloudformation/builders/security.ts +0 -399
- package/src/cloudformation/builders/storage.ts +0 -285
- package/src/cloudformation/index.ts +0 -30
- package/src/cloudformation/types.ts +0 -173
- package/src/compliance/aws-config.ts +0 -543
- package/src/compliance/cloudtrail.ts +0 -376
- package/src/compliance/compliance.test.ts +0 -423
- package/src/compliance/guardduty.ts +0 -446
- package/src/compliance/index.ts +0 -66
- package/src/compliance/security-hub.ts +0 -456
- package/src/containers/build-optimization.ts +0 -416
- package/src/containers/containers.test.ts +0 -508
- package/src/containers/image-scanning.ts +0 -360
- package/src/containers/index.ts +0 -9
- package/src/containers/registry.ts +0 -293
- package/src/containers/service-mesh.ts +0 -520
- package/src/database/database.test.ts +0 -762
- package/src/database/index.ts +0 -9
- package/src/database/migrations.ts +0 -444
- package/src/database/performance.ts +0 -528
- package/src/database/replicas.ts +0 -534
- package/src/database/users.ts +0 -494
- package/src/dependency-graph.ts +0 -143
- package/src/deployment/ab-testing.ts +0 -582
- package/src/deployment/blue-green.ts +0 -452
- package/src/deployment/canary.ts +0 -500
- package/src/deployment/deployment.test.ts +0 -526
- package/src/deployment/index.ts +0 -61
- package/src/deployment/progressive.ts +0 -62
- package/src/dns/dns.test.ts +0 -641
- package/src/dns/dnssec.ts +0 -315
- package/src/dns/index.ts +0 -8
- package/src/dns/resolver.ts +0 -496
- package/src/dns/routing.ts +0 -593
- package/src/email/advanced/analytics.ts +0 -445
- package/src/email/advanced/index.ts +0 -11
- package/src/email/advanced/rules.ts +0 -465
- package/src/email/advanced/scheduling.ts +0 -352
- package/src/email/advanced/search.ts +0 -412
- package/src/email/advanced/shared-mailboxes.ts +0 -404
- package/src/email/advanced/templates.ts +0 -455
- package/src/email/advanced/threading.ts +0 -281
- package/src/email/analytics.ts +0 -467
- package/src/email/bounce-handling.ts +0 -425
- package/src/email/email.test.ts +0 -431
- package/src/email/handlers/__tests__/inbound.test.ts +0 -38
- package/src/email/handlers/__tests__/outbound.test.ts +0 -37
- package/src/email/handlers/converter.ts +0 -227
- package/src/email/handlers/feedback.ts +0 -228
- package/src/email/handlers/inbound.ts +0 -169
- package/src/email/handlers/outbound.ts +0 -178
- package/src/email/index.ts +0 -15
- package/src/email/reputation.ts +0 -303
- package/src/email/templates.ts +0 -352
- package/src/errors/index.test.ts +0 -434
- package/src/errors/index.ts +0 -416
- package/src/health-checks/index.ts +0 -40
- package/src/index.ts +0 -360
- package/src/intrinsic-functions.ts +0 -118
- package/src/lambda/concurrency.ts +0 -330
- package/src/lambda/destinations.ts +0 -345
- package/src/lambda/dlq.ts +0 -425
- package/src/lambda/index.ts +0 -11
- package/src/lambda/lambda.test.ts +0 -840
- package/src/lambda/layers.ts +0 -263
- package/src/lambda/versions.ts +0 -376
- package/src/lambda/vpc.ts +0 -399
- package/src/local/config.ts +0 -114
- package/src/local/index.ts +0 -6
- package/src/local/mock-aws.ts +0 -351
- package/src/modules/ai.ts +0 -340
- package/src/modules/api.ts +0 -478
- package/src/modules/auth.ts +0 -805
- package/src/modules/cache.ts +0 -417
- package/src/modules/cdn.ts +0 -1062
- package/src/modules/communication.ts +0 -1094
- package/src/modules/compute.ts +0 -3348
- package/src/modules/database.ts +0 -554
- package/src/modules/deployment.ts +0 -1079
- package/src/modules/dns.ts +0 -337
- package/src/modules/email.ts +0 -1538
- package/src/modules/filesystem.ts +0 -515
- package/src/modules/index.ts +0 -32
- package/src/modules/messaging.ts +0 -486
- package/src/modules/monitoring.ts +0 -2086
- package/src/modules/network.ts +0 -664
- package/src/modules/parameter-store.ts +0 -325
- package/src/modules/permissions.ts +0 -1081
- package/src/modules/phone.ts +0 -494
- package/src/modules/queue.ts +0 -1260
- package/src/modules/redirects.ts +0 -464
- package/src/modules/registry.ts +0 -699
- package/src/modules/search.ts +0 -401
- package/src/modules/secrets.ts +0 -416
- package/src/modules/security.ts +0 -731
- package/src/modules/sms.ts +0 -389
- package/src/modules/storage.ts +0 -1120
- package/src/modules/workflow.ts +0 -680
- package/src/multi-account/config.ts +0 -521
- package/src/multi-account/index.ts +0 -7
- package/src/multi-account/manager.ts +0 -427
- package/src/multi-region/cross-region.ts +0 -410
- package/src/multi-region/index.ts +0 -8
- package/src/multi-region/manager.ts +0 -483
- package/src/multi-region/regions.ts +0 -435
- package/src/network-security/index.ts +0 -48
- package/src/observability/index.ts +0 -9
- package/src/observability/logs.ts +0 -522
- package/src/observability/metrics.ts +0 -460
- package/src/observability/observability.test.ts +0 -782
- package/src/observability/synthetics.ts +0 -568
- package/src/observability/xray.ts +0 -358
- package/src/phone/advanced/analytics.ts +0 -349
- package/src/phone/advanced/callbacks.ts +0 -428
- package/src/phone/advanced/index.ts +0 -8
- package/src/phone/advanced/ivr-builder.ts +0 -504
- package/src/phone/advanced/recording.ts +0 -310
- package/src/phone/handlers/__tests__/incoming-call.test.ts +0 -40
- package/src/phone/handlers/incoming-call.ts +0 -117
- package/src/phone/handlers/missed-call.ts +0 -116
- package/src/phone/handlers/voicemail.ts +0 -179
- package/src/phone/index.ts +0 -9
- package/src/presets/api-backend.ts +0 -134
- package/src/presets/data-pipeline.ts +0 -204
- package/src/presets/extend.test.ts +0 -295
- package/src/presets/extend.ts +0 -297
- package/src/presets/fullstack-app.ts +0 -144
- package/src/presets/index.ts +0 -27
- package/src/presets/jamstack.ts +0 -135
- package/src/presets/microservices.ts +0 -167
- package/src/presets/ml-api.ts +0 -208
- package/src/presets/nodejs-server.ts +0 -104
- package/src/presets/nodejs-serverless.ts +0 -114
- package/src/presets/realtime-app.ts +0 -184
- package/src/presets/static-site.ts +0 -64
- package/src/presets/traditional-web-app.ts +0 -339
- package/src/presets/wordpress.ts +0 -138
- package/src/preview/github.test.ts +0 -249
- package/src/preview/github.ts +0 -297
- package/src/preview/index.ts +0 -37
- package/src/preview/manager.test.ts +0 -440
- package/src/preview/manager.ts +0 -326
- package/src/preview/notifications.test.ts +0 -582
- package/src/preview/notifications.ts +0 -341
- package/src/queue/batch-processing.ts +0 -402
- package/src/queue/dlq-monitoring.ts +0 -402
- package/src/queue/fifo.ts +0 -342
- package/src/queue/index.ts +0 -9
- package/src/queue/management.ts +0 -428
- package/src/queue/queue.test.ts +0 -429
- package/src/resource-mgmt/index.ts +0 -39
- package/src/resource-naming.ts +0 -62
- package/src/s3/index.ts +0 -523
- package/src/schema/cloud-config.schema.json +0 -554
- package/src/schema/index.ts +0 -68
- package/src/security/certificate-manager.ts +0 -492
- package/src/security/index.ts +0 -9
- package/src/security/scanning.ts +0 -545
- package/src/security/secrets-manager.ts +0 -476
- package/src/security/secrets-rotation.ts +0 -456
- package/src/security/security.test.ts +0 -738
- package/src/sms/advanced/ab-testing.ts +0 -389
- package/src/sms/advanced/analytics.ts +0 -336
- package/src/sms/advanced/campaigns.ts +0 -523
- package/src/sms/advanced/chatbot.ts +0 -224
- package/src/sms/advanced/index.ts +0 -10
- package/src/sms/advanced/link-tracking.ts +0 -248
- package/src/sms/advanced/mms.ts +0 -308
- package/src/sms/handlers/__tests__/send.test.ts +0 -40
- package/src/sms/handlers/delivery-status.ts +0 -133
- package/src/sms/handlers/receive.ts +0 -162
- package/src/sms/handlers/send.ts +0 -174
- package/src/sms/index.ts +0 -9
- package/src/stack-diff.ts +0 -389
- package/src/static-site/index.ts +0 -85
- package/src/template-builder.ts +0 -110
- package/src/template-validator.ts +0 -574
- package/src/utils/cache.ts +0 -291
- package/src/utils/diff.ts +0 -269
- package/src/utils/hash.ts +0 -227
- package/src/utils/index.ts +0 -8
- package/src/utils/parallel.ts +0 -294
- package/src/validators/credentials.test.ts +0 -274
- package/src/validators/credentials.ts +0 -233
- package/src/validators/quotas.test.ts +0 -434
- package/src/validators/quotas.ts +0 -217
- package/test/ai.test.ts +0 -327
- package/test/api.test.ts +0 -511
- package/test/auth.test.ts +0 -632
- package/test/cache.test.ts +0 -406
- package/test/cdn.test.ts +0 -247
- package/test/compute.test.ts +0 -861
- package/test/database.test.ts +0 -523
- package/test/deployment.test.ts +0 -499
- package/test/dns.test.ts +0 -270
- package/test/email.test.ts +0 -439
- package/test/filesystem.test.ts +0 -382
- package/test/integration.test.ts +0 -350
- package/test/messaging.test.ts +0 -514
- package/test/monitoring.test.ts +0 -634
- package/test/network.test.ts +0 -425
- package/test/permissions.test.ts +0 -488
- package/test/queue.test.ts +0 -484
- package/test/registry.test.ts +0 -306
- package/test/security.test.ts +0 -462
- package/test/storage.test.ts +0 -463
- package/test/template-validator.test.ts +0 -559
- package/test/workflow.test.ts +0 -592
- package/tsconfig.json +0 -16
- package/tsconfig.tsbuildinfo +0 -1
package/test/security.test.ts
DELETED
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'bun:test'
|
|
2
|
-
import { Security } from '../src/modules/security'
|
|
3
|
-
import { TemplateBuilder } from '../src/template-builder'
|
|
4
|
-
|
|
5
|
-
describe('Security Module', () => {
|
|
6
|
-
describe('createCertificate', () => {
|
|
7
|
-
it('should create a basic SSL certificate', () => {
|
|
8
|
-
const { certificate, logicalId } = Security.createCertificate({
|
|
9
|
-
domain: 'example.com',
|
|
10
|
-
slug: 'my-app',
|
|
11
|
-
environment: 'production',
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
expect(certificate.Type).toBe('AWS::CertificateManager::Certificate')
|
|
15
|
-
expect(certificate.Properties.DomainName).toBe('example.com')
|
|
16
|
-
expect(certificate.Properties.ValidationMethod).toBe('DNS')
|
|
17
|
-
expect(certificate.Properties.SubjectAlternativeNames).toContain('example.com')
|
|
18
|
-
expect(logicalId).toBeDefined()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('should create certificate with wildcard subdomain', () => {
|
|
22
|
-
const { certificate } = Security.createCertificate({
|
|
23
|
-
domain: 'example.com',
|
|
24
|
-
subdomains: ['*'],
|
|
25
|
-
slug: 'my-app',
|
|
26
|
-
environment: 'production',
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
expect(certificate.Properties.SubjectAlternativeNames).toContain('example.com')
|
|
30
|
-
expect(certificate.Properties.SubjectAlternativeNames).toContain('*.example.com')
|
|
31
|
-
expect(certificate.Properties.SubjectAlternativeNames).toHaveLength(2)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it('should create certificate with specific subdomains', () => {
|
|
35
|
-
const { certificate } = Security.createCertificate({
|
|
36
|
-
domain: 'example.com',
|
|
37
|
-
subdomains: ['www', 'api', 'cdn'],
|
|
38
|
-
slug: 'my-app',
|
|
39
|
-
environment: 'production',
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
expect(certificate.Properties.SubjectAlternativeNames).toContain('example.com')
|
|
43
|
-
expect(certificate.Properties.SubjectAlternativeNames).toContain('www.example.com')
|
|
44
|
-
expect(certificate.Properties.SubjectAlternativeNames).toContain('api.example.com')
|
|
45
|
-
expect(certificate.Properties.SubjectAlternativeNames).toContain('cdn.example.com')
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('should support email validation', () => {
|
|
49
|
-
const { certificate } = Security.createCertificate({
|
|
50
|
-
domain: 'example.com',
|
|
51
|
-
slug: 'my-app',
|
|
52
|
-
environment: 'production',
|
|
53
|
-
validationMethod: 'EMAIL',
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
expect(certificate.Properties.ValidationMethod).toBe('EMAIL')
|
|
57
|
-
expect(certificate.Properties.DomainValidationOptions).toBeUndefined()
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('should add DNS validation with Route53 when hostedZoneId provided', () => {
|
|
61
|
-
const { certificate } = Security.createCertificate({
|
|
62
|
-
domain: 'example.com',
|
|
63
|
-
subdomains: ['www'],
|
|
64
|
-
slug: 'my-app',
|
|
65
|
-
environment: 'production',
|
|
66
|
-
validationMethod: 'DNS',
|
|
67
|
-
hostedZoneId: 'Z1234567890ABC',
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
expect(certificate.Properties.DomainValidationOptions).toBeDefined()
|
|
71
|
-
expect(certificate.Properties.DomainValidationOptions).toHaveLength(2)
|
|
72
|
-
expect(certificate.Properties.DomainValidationOptions?.[0]).toEqual({
|
|
73
|
-
DomainName: 'example.com',
|
|
74
|
-
HostedZoneId: 'Z1234567890ABC',
|
|
75
|
-
})
|
|
76
|
-
expect(certificate.Properties.DomainValidationOptions?.[1]).toEqual({
|
|
77
|
-
DomainName: 'www.example.com',
|
|
78
|
-
HostedZoneId: 'Z1234567890ABC',
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
describe('createKmsKey', () => {
|
|
84
|
-
it('should create a KMS key with default settings', () => {
|
|
85
|
-
const { key, alias, logicalId, aliasId } = Security.createKmsKey({
|
|
86
|
-
description: 'Encryption key for user data',
|
|
87
|
-
slug: 'my-app',
|
|
88
|
-
environment: 'production',
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
expect(key.Type).toBe('AWS::KMS::Key')
|
|
92
|
-
expect(key.Properties.Description).toBe('Encryption key for user data')
|
|
93
|
-
expect(key.Properties.Enabled).toBe(true)
|
|
94
|
-
expect(key.Properties.EnableKeyRotation).toBe(true)
|
|
95
|
-
expect(key.Properties.KeySpec).toBe('SYMMETRIC_DEFAULT')
|
|
96
|
-
expect(key.Properties.KeyUsage).toBe('ENCRYPT_DECRYPT')
|
|
97
|
-
expect(key.Properties.MultiRegion).toBe(false)
|
|
98
|
-
|
|
99
|
-
expect(alias?.Type).toBe('AWS::KMS::Alias')
|
|
100
|
-
expect(alias?.Properties.AliasName).toBe('alias/my-app-production')
|
|
101
|
-
expect(logicalId).toBeDefined()
|
|
102
|
-
expect(aliasId).toBeDefined()
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('should create multi-region KMS key', () => {
|
|
106
|
-
const { key } = Security.createKmsKey({
|
|
107
|
-
description: 'Multi-region key',
|
|
108
|
-
slug: 'my-app',
|
|
109
|
-
environment: 'production',
|
|
110
|
-
multiRegion: true,
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
expect(key.Properties.MultiRegion).toBe(true)
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('should disable rotation when requested', () => {
|
|
117
|
-
const { key } = Security.createKmsKey({
|
|
118
|
-
description: 'No rotation key',
|
|
119
|
-
slug: 'my-app',
|
|
120
|
-
environment: 'production',
|
|
121
|
-
enableRotation: false,
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
expect(key.Properties.EnableKeyRotation).toBe(false)
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
it('should have valid key policy', () => {
|
|
128
|
-
const { key } = Security.createKmsKey({
|
|
129
|
-
description: 'Test key',
|
|
130
|
-
slug: 'my-app',
|
|
131
|
-
environment: 'production',
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
expect(key.Properties.KeyPolicy.Version).toBe('2012-10-17')
|
|
135
|
-
expect(key.Properties.KeyPolicy.Statement).toBeArray()
|
|
136
|
-
expect(key.Properties.KeyPolicy.Statement.length).toBeGreaterThan(0)
|
|
137
|
-
|
|
138
|
-
// Check root account permissions
|
|
139
|
-
const rootStatement = key.Properties.KeyPolicy.Statement[0]
|
|
140
|
-
expect(rootStatement.Effect).toBe('Allow')
|
|
141
|
-
expect(rootStatement.Action).toBe('kms:*')
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
describe('createFirewall', () => {
|
|
146
|
-
it('should create a WAF Web ACL with default settings', () => {
|
|
147
|
-
const { webAcl, logicalId } = Security.createFirewall({
|
|
148
|
-
slug: 'my-app',
|
|
149
|
-
environment: 'production',
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
expect(webAcl.Type).toBe('AWS::WAFv2::WebACL')
|
|
153
|
-
expect(webAcl.Properties.Scope).toBe('CLOUDFRONT')
|
|
154
|
-
expect(webAcl.Properties.DefaultAction.Allow).toBeDefined()
|
|
155
|
-
expect(webAcl.Properties.DefaultAction.Block).toBeUndefined()
|
|
156
|
-
expect(webAcl.Properties.VisibilityConfig.CloudWatchMetricsEnabled).toBe(true)
|
|
157
|
-
expect(logicalId).toBeDefined()
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
it('should create regional WAF', () => {
|
|
161
|
-
const { webAcl } = Security.createFirewall({
|
|
162
|
-
slug: 'my-app',
|
|
163
|
-
environment: 'production',
|
|
164
|
-
scope: 'REGIONAL',
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
expect(webAcl.Properties.Scope).toBe('REGIONAL')
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it('should support block as default action', () => {
|
|
171
|
-
const { webAcl } = Security.createFirewall({
|
|
172
|
-
slug: 'my-app',
|
|
173
|
-
environment: 'production',
|
|
174
|
-
defaultAction: 'block',
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
expect(webAcl.Properties.DefaultAction.Block).toBeDefined()
|
|
178
|
-
expect(webAcl.Properties.DefaultAction.Allow).toBeUndefined()
|
|
179
|
-
})
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
describe('setRateLimit', () => {
|
|
183
|
-
it('should add rate limit rule', () => {
|
|
184
|
-
const { webAcl } = Security.createFirewall({
|
|
185
|
-
slug: 'my-app',
|
|
186
|
-
environment: 'production',
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
const updated = Security.setRateLimit(webAcl, {
|
|
190
|
-
name: 'RateLimit',
|
|
191
|
-
priority: 1,
|
|
192
|
-
requestsPerWindow: 2000,
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
expect(updated.Properties.Rules).toHaveLength(1)
|
|
196
|
-
expect(updated.Properties.Rules?.[0].Name).toBe('RateLimit')
|
|
197
|
-
expect(updated.Properties.Rules?.[0].Priority).toBe(1)
|
|
198
|
-
expect(updated.Properties.Rules?.[0].Statement.RateBasedStatement?.Limit).toBe(2000)
|
|
199
|
-
expect(updated.Properties.Rules?.[0].Statement.RateBasedStatement?.AggregateKeyType).toBe('IP')
|
|
200
|
-
expect(updated.Properties.Rules?.[0].Action?.Block).toBeDefined()
|
|
201
|
-
})
|
|
202
|
-
|
|
203
|
-
it('should support FORWARDED_IP aggregation', () => {
|
|
204
|
-
const { webAcl } = Security.createFirewall({
|
|
205
|
-
slug: 'my-app',
|
|
206
|
-
environment: 'production',
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
const updated = Security.setRateLimit(webAcl, {
|
|
210
|
-
name: 'RateLimit',
|
|
211
|
-
priority: 1,
|
|
212
|
-
requestsPerWindow: 1000,
|
|
213
|
-
aggregateKeyType: 'FORWARDED_IP',
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
expect(updated.Properties.Rules?.[0].Statement.RateBasedStatement?.AggregateKeyType).toBe('FORWARDED_IP')
|
|
217
|
-
})
|
|
218
|
-
})
|
|
219
|
-
|
|
220
|
-
describe('blockCountries', () => {
|
|
221
|
-
it('should add geo-blocking rule', () => {
|
|
222
|
-
const { webAcl } = Security.createFirewall({
|
|
223
|
-
slug: 'my-app',
|
|
224
|
-
environment: 'production',
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
const updated = Security.blockCountries(webAcl, {
|
|
228
|
-
name: 'BlockRiskyCountries',
|
|
229
|
-
priority: 2,
|
|
230
|
-
countryCodes: ['CN', 'RU', 'KP'],
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
expect(updated.Properties.Rules).toHaveLength(1)
|
|
234
|
-
expect(updated.Properties.Rules?.[0].Statement.GeoMatchStatement?.CountryCodes).toEqual(['CN', 'RU', 'KP'])
|
|
235
|
-
expect(updated.Properties.Rules?.[0].Action?.Block).toBeDefined()
|
|
236
|
-
})
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
describe('blockIpAddresses', () => {
|
|
240
|
-
it('should create IP set and add blocking rule', () => {
|
|
241
|
-
const { webAcl } = Security.createFirewall({
|
|
242
|
-
slug: 'my-app',
|
|
243
|
-
environment: 'production',
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
const { webAcl: updated, ipSet, ipSetLogicalId } = Security.blockIpAddresses(
|
|
247
|
-
webAcl,
|
|
248
|
-
{
|
|
249
|
-
name: 'BlockedIPs',
|
|
250
|
-
priority: 3,
|
|
251
|
-
ipAddresses: ['192.0.2.0/24', '198.51.100.42/32'],
|
|
252
|
-
},
|
|
253
|
-
'my-app',
|
|
254
|
-
'production',
|
|
255
|
-
)
|
|
256
|
-
|
|
257
|
-
expect(ipSet.Type).toBe('AWS::WAFv2::IPSet')
|
|
258
|
-
expect(ipSet.Properties.IPAddressVersion).toBe('IPV4')
|
|
259
|
-
expect(ipSet.Properties.Addresses).toEqual(['192.0.2.0/24', '198.51.100.42/32'])
|
|
260
|
-
expect(ipSetLogicalId).toBeDefined()
|
|
261
|
-
|
|
262
|
-
expect(updated.Properties.Rules).toHaveLength(1)
|
|
263
|
-
expect(updated.Properties.Rules?.[0].Statement.IPSetReferenceStatement).toBeDefined()
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
it('should support IPv6 addresses', () => {
|
|
267
|
-
const { webAcl } = Security.createFirewall({
|
|
268
|
-
slug: 'my-app',
|
|
269
|
-
environment: 'production',
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
const { ipSet } = Security.blockIpAddresses(
|
|
273
|
-
webAcl,
|
|
274
|
-
{
|
|
275
|
-
name: 'BlockedIPv6',
|
|
276
|
-
priority: 4,
|
|
277
|
-
ipAddresses: ['2001:0db8::/32'],
|
|
278
|
-
ipVersion: 'IPV6',
|
|
279
|
-
},
|
|
280
|
-
'my-app',
|
|
281
|
-
'production',
|
|
282
|
-
)
|
|
283
|
-
|
|
284
|
-
expect(ipSet.Properties.IPAddressVersion).toBe('IPV6')
|
|
285
|
-
expect(ipSet.Properties.Addresses).toContain('2001:0db8::/32')
|
|
286
|
-
})
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
describe('addManagedRules', () => {
|
|
290
|
-
it('should add AWS managed rule group', () => {
|
|
291
|
-
const { webAcl } = Security.createFirewall({
|
|
292
|
-
slug: 'my-app',
|
|
293
|
-
environment: 'production',
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
const updated = Security.addManagedRules(webAcl, {
|
|
297
|
-
name: 'AWSCoreRuleSet',
|
|
298
|
-
priority: 5,
|
|
299
|
-
vendorName: 'AWS',
|
|
300
|
-
ruleName: 'AWSManagedRulesCommonRuleSet',
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
expect(updated.Properties.Rules).toHaveLength(1)
|
|
304
|
-
expect(updated.Properties.Rules?.[0].Statement.ManagedRuleGroupStatement?.VendorName).toBe('AWS')
|
|
305
|
-
expect(updated.Properties.Rules?.[0].Statement.ManagedRuleGroupStatement?.Name).toBe('AWSManagedRulesCommonRuleSet')
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
it('should support excluding rules from managed rule group', () => {
|
|
309
|
-
const { webAcl } = Security.createFirewall({
|
|
310
|
-
slug: 'my-app',
|
|
311
|
-
environment: 'production',
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
const updated = Security.addManagedRules(webAcl, {
|
|
315
|
-
name: 'CoreRuleSet',
|
|
316
|
-
priority: 6,
|
|
317
|
-
vendorName: 'AWS',
|
|
318
|
-
ruleName: 'AWSManagedRulesCommonRuleSet',
|
|
319
|
-
excludedRules: ['SizeRestrictions_BODY', 'GenericRFI_BODY'],
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
expect(updated.Properties.Rules?.[0].Statement.ManagedRuleGroupStatement?.ExcludedRules).toHaveLength(2)
|
|
323
|
-
expect(updated.Properties.Rules?.[0].Statement.ManagedRuleGroupStatement?.ExcludedRules?.[0].Name).toBe('SizeRestrictions_BODY')
|
|
324
|
-
})
|
|
325
|
-
|
|
326
|
-
it('should have predefined managed rule groups', () => {
|
|
327
|
-
expect(Security.ManagedRuleGroups.CoreRuleSet.vendorName).toBe('AWS')
|
|
328
|
-
expect(Security.ManagedRuleGroups.CoreRuleSet.ruleName).toBe('AWSManagedRulesCommonRuleSet')
|
|
329
|
-
expect(Security.ManagedRuleGroups.SqlDatabase.ruleName).toBe('AWSManagedRulesSQLiRuleSet')
|
|
330
|
-
expect(Security.ManagedRuleGroups.AmazonIpReputation.ruleName).toBe('AWSManagedRulesAmazonIpReputationList')
|
|
331
|
-
})
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
describe('Integration with TemplateBuilder', () => {
|
|
335
|
-
it('should create complete security infrastructure', () => {
|
|
336
|
-
const template = new TemplateBuilder('Security Infrastructure')
|
|
337
|
-
|
|
338
|
-
// 1. Create SSL certificate
|
|
339
|
-
const { certificate, logicalId: certId } = Security.createCertificate({
|
|
340
|
-
domain: 'example.com',
|
|
341
|
-
subdomains: ['*'],
|
|
342
|
-
slug: 'my-app',
|
|
343
|
-
environment: 'production',
|
|
344
|
-
hostedZoneId: 'Z1234567890ABC',
|
|
345
|
-
})
|
|
346
|
-
template.addResource(certId, certificate)
|
|
347
|
-
|
|
348
|
-
// 2. Create KMS key
|
|
349
|
-
const { key, alias, logicalId: keyId, aliasId } = Security.createKmsKey({
|
|
350
|
-
description: 'Application encryption key',
|
|
351
|
-
slug: 'my-app',
|
|
352
|
-
environment: 'production',
|
|
353
|
-
})
|
|
354
|
-
template.addResource(keyId, key)
|
|
355
|
-
if (alias && aliasId) {
|
|
356
|
-
template.addResource(aliasId, alias)
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// 3. Create WAF with multiple rules
|
|
360
|
-
const { webAcl, logicalId: wafId } = Security.createFirewall({
|
|
361
|
-
slug: 'my-app',
|
|
362
|
-
environment: 'production',
|
|
363
|
-
scope: 'CLOUDFRONT',
|
|
364
|
-
})
|
|
365
|
-
|
|
366
|
-
// Add rate limiting
|
|
367
|
-
Security.setRateLimit(webAcl, {
|
|
368
|
-
name: 'RateLimit',
|
|
369
|
-
priority: 1,
|
|
370
|
-
requestsPerWindow: 2000,
|
|
371
|
-
})
|
|
372
|
-
|
|
373
|
-
// Add managed rules
|
|
374
|
-
Security.addManagedRules(webAcl, {
|
|
375
|
-
name: 'CoreRules',
|
|
376
|
-
priority: 2,
|
|
377
|
-
...Security.ManagedRuleGroups.CoreRuleSet,
|
|
378
|
-
})
|
|
379
|
-
|
|
380
|
-
// Add geo-blocking
|
|
381
|
-
Security.blockCountries(webAcl, {
|
|
382
|
-
name: 'GeoBlock',
|
|
383
|
-
priority: 3,
|
|
384
|
-
countryCodes: ['CN', 'RU'],
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
// Add IP blocking
|
|
388
|
-
const { webAcl: finalWebAcl, ipSet, ipSetLogicalId } = Security.blockIpAddresses(
|
|
389
|
-
webAcl,
|
|
390
|
-
{
|
|
391
|
-
name: 'IPBlock',
|
|
392
|
-
priority: 4,
|
|
393
|
-
ipAddresses: ['192.0.2.0/24'],
|
|
394
|
-
},
|
|
395
|
-
'my-app',
|
|
396
|
-
'production',
|
|
397
|
-
)
|
|
398
|
-
|
|
399
|
-
template.addResource(wafId, finalWebAcl)
|
|
400
|
-
template.addResource(ipSetLogicalId, ipSet)
|
|
401
|
-
|
|
402
|
-
const result = template.build()
|
|
403
|
-
|
|
404
|
-
// Certificate + Key + Alias + WebACL + IPSet = 5 resources
|
|
405
|
-
expect(Object.keys(result.Resources)).toHaveLength(5)
|
|
406
|
-
expect(result.Resources[certId].Type).toBe('AWS::CertificateManager::Certificate')
|
|
407
|
-
expect(result.Resources[keyId].Type).toBe('AWS::KMS::Key')
|
|
408
|
-
expect(result.Resources[wafId].Type).toBe('AWS::WAFv2::WebACL')
|
|
409
|
-
expect(result.Resources[wafId]!.Properties!.Rules).toHaveLength(4)
|
|
410
|
-
})
|
|
411
|
-
|
|
412
|
-
it('should generate valid JSON template', () => {
|
|
413
|
-
const template = new TemplateBuilder('Security Test')
|
|
414
|
-
|
|
415
|
-
const { certificate, logicalId } = Security.createCertificate({
|
|
416
|
-
domain: 'test.com',
|
|
417
|
-
slug: 'test',
|
|
418
|
-
environment: 'development',
|
|
419
|
-
})
|
|
420
|
-
|
|
421
|
-
template.addResource(logicalId, certificate)
|
|
422
|
-
|
|
423
|
-
const json = template.toJSON()
|
|
424
|
-
const parsed = JSON.parse(json)
|
|
425
|
-
|
|
426
|
-
expect(parsed.Resources[logicalId].Type).toBe('AWS::CertificateManager::Certificate')
|
|
427
|
-
expect(parsed.Resources[logicalId].Properties.DomainName).toBe('test.com')
|
|
428
|
-
})
|
|
429
|
-
})
|
|
430
|
-
|
|
431
|
-
describe('Multiple rules in WAF', () => {
|
|
432
|
-
it('should handle multiple rules with correct priorities', () => {
|
|
433
|
-
const { webAcl } = Security.createFirewall({
|
|
434
|
-
slug: 'my-app',
|
|
435
|
-
environment: 'production',
|
|
436
|
-
})
|
|
437
|
-
|
|
438
|
-
Security.setRateLimit(webAcl, {
|
|
439
|
-
name: 'RateLimit',
|
|
440
|
-
priority: 1,
|
|
441
|
-
requestsPerWindow: 2000,
|
|
442
|
-
})
|
|
443
|
-
|
|
444
|
-
Security.blockCountries(webAcl, {
|
|
445
|
-
name: 'GeoBlock',
|
|
446
|
-
priority: 2,
|
|
447
|
-
countryCodes: ['XX'],
|
|
448
|
-
})
|
|
449
|
-
|
|
450
|
-
Security.addManagedRules(webAcl, {
|
|
451
|
-
name: 'CoreRules',
|
|
452
|
-
priority: 3,
|
|
453
|
-
...Security.ManagedRuleGroups.CoreRuleSet,
|
|
454
|
-
})
|
|
455
|
-
|
|
456
|
-
expect(webAcl.Properties.Rules).toHaveLength(3)
|
|
457
|
-
expect(webAcl.Properties.Rules?.[0].Priority).toBe(1)
|
|
458
|
-
expect(webAcl.Properties.Rules?.[1].Priority).toBe(2)
|
|
459
|
-
expect(webAcl.Properties.Rules?.[2].Priority).toBe(3)
|
|
460
|
-
})
|
|
461
|
-
})
|
|
462
|
-
})
|