-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Expand file tree
/
Copy pathevents.test.ts
More file actions
144 lines (126 loc) · 4.11 KB
/
events.test.ts
File metadata and controls
144 lines (126 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { Stack } from 'aws-cdk-lib';
import { CfnRule, Rule } from 'aws-cdk-lib/aws-events';
import { Template } from 'aws-cdk-lib/assertions';
import { AWSAPICallViaCloudTrail, ObjectCreated, ObjectDeleted } from '../../../lib/services/aws-s3/events.generated';
describe('with L2 Rule', () => {
let stack: Stack;
beforeEach(() => {
stack = new Stack();
});
test('awsAPICallViaCloudTrailPattern with tlsDetails and eventMetadata', () => {
new Rule(stack, 'Rule', {
eventPattern: AWSAPICallViaCloudTrail.eventPattern({
tlsDetails: { tlsVersion: ['TLSv1.3'] },
eventMetadata: { region: ['us-east-1'] },
}),
});
Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'detail-type': ['AWS API Call via CloudTrail'],
'source': ['aws.s3'],
'detail': {
tlsDetails: { tlsVersion: ['TLSv1.3'] },
},
'region': ['us-east-1'],
},
});
});
test('awsAPICallViaCloudTrailPattern bare call', () => {
new Rule(stack, 'Rule', {
eventPattern: AWSAPICallViaCloudTrail.eventPattern(),
});
Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'detail-type': ['AWS API Call via CloudTrail'],
'source': ['aws.s3'],
},
});
});
test('objectCreatedPattern with reason filter', () => {
new Rule(stack, 'Rule', {
eventPattern: ObjectCreated.eventPattern({ reason: ['PutObject'] }),
});
Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'detail-type': ['Object Created'],
'source': ['aws.s3'],
'detail': { reason: ['PutObject'] },
},
});
});
test('objectDeletedPattern with reason filter', () => {
new Rule(stack, 'Rule', {
eventPattern: ObjectDeleted.eventPattern({ reason: ['DeleteObject'] }),
});
Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'detail-type': ['Object Deleted'],
'source': ['aws.s3'],
'detail': { reason: ['DeleteObject'] },
},
});
});
});
describe('with L1 CfnRule', () => {
let stack: Stack;
beforeEach(() => {
stack = new Stack();
});
test('awsAPICallViaCloudTrailPattern with tlsDetails and eventMetadata', () => {
new CfnRule(stack, 'Rule', {
state: 'ENABLED',
eventPattern: AWSAPICallViaCloudTrail.eventPattern({
tlsDetails: { tlsVersion: ['TLSv1.3'] },
eventMetadata: { region: ['us-east-1'] },
}),
});
Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'detail-type': ['AWS API Call via CloudTrail'],
'source': ['aws.s3'],
'detail': {
tlsDetails: { tlsVersion: ['TLSv1.3'] },
},
'region': ['us-east-1'],
},
});
});
test('awsAPICallViaCloudTrailPattern bare call', () => {
new CfnRule(stack, 'Rule', {
state: 'ENABLED',
eventPattern: AWSAPICallViaCloudTrail.eventPattern(),
});
Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'detail-type': ['AWS API Call via CloudTrail'],
'source': ['aws.s3'],
},
});
});
test('objectCreatedPattern with reason filter', () => {
new CfnRule(stack, 'Rule', {
state: 'ENABLED',
eventPattern: ObjectCreated.eventPattern({ reason: ['PutObject'] }),
});
Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'detail-type': ['Object Created'],
'source': ['aws.s3'],
'detail': { reason: ['PutObject'] },
},
});
});
test('objectDeletedPattern with reason filter', () => {
new CfnRule(stack, 'Rule', {
state: 'ENABLED',
eventPattern: ObjectDeleted.eventPattern({ reason: ['DeleteObject'] }),
});
Template.fromStack(stack).hasResourceProperties('AWS::Events::Rule', {
EventPattern: {
'detail-type': ['Object Deleted'],
'source': ['aws.s3'],
'detail': { reason: ['DeleteObject'] },
},
});
});
});