1
- import { Template } from '@aws-cdk/assertions' ;
1
+ import { Match , Template } from '@aws-cdk/assertions' ;
2
2
import * as events from '@aws-cdk/aws-events' ;
3
3
import * as kms from '@aws-cdk/aws-kms' ;
4
4
import * as sqs from '@aws-cdk/aws-sqs' ;
5
- import { Duration , Stack } from '@aws-cdk/core' ;
5
+ import { App , Duration , Stack } from '@aws-cdk/core' ;
6
6
import * as cxapi from '@aws-cdk/cx-api' ;
7
7
import * as targets from '../../lib' ;
8
8
@@ -144,24 +144,38 @@ test('multiple uses of a queue as a target results in multi policy statement bec
144
144
} ) ;
145
145
146
146
test ( 'Encrypted queues result in a policy statement with aws:sourceAccount condition when the feature flag is on' , ( ) => {
147
+ const app = new App ( ) ;
147
148
// GIVEN
148
- const stack = new Stack ( ) ;
149
- stack . node . setContext ( cxapi . EVENTS_TARGET_QUEUE_SAME_ACCOUNT , true ) ;
150
- const queue = new sqs . Queue ( stack , 'MyQueue' , {
151
- encryptionMasterKey : kms . Key . fromKeyArn ( stack , 'key' , 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' ) ,
149
+ const ruleStack = new Stack ( app , 'ruleStack' , {
150
+ env : {
151
+ account : '111111111111' ,
152
+ region : 'us-east-1' ,
153
+ } ,
152
154
} ) ;
155
+ ruleStack . node . setContext ( cxapi . EVENTS_TARGET_QUEUE_SAME_ACCOUNT , true ) ;
153
156
154
- const rule = new events . Rule ( stack , 'MyRule' , {
157
+ const rule = new events . Rule ( ruleStack , 'MyRule' , {
155
158
schedule : events . Schedule . rate ( Duration . hours ( 1 ) ) ,
156
159
} ) ;
157
160
161
+ const queueStack = new Stack ( app , 'queueStack' , {
162
+ env : {
163
+ account : '222222222222' ,
164
+ region : 'us-east-1' ,
165
+ } ,
166
+ } ) ;
167
+ const queue = new sqs . Queue ( queueStack , 'MyQueue' , {
168
+ encryptionMasterKey : kms . Key . fromKeyArn ( queueStack , 'key' , 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' ) ,
169
+ } ) ;
170
+
171
+
158
172
// WHEN
159
173
rule . addTarget ( new targets . SqsQueue ( queue ) ) ;
160
174
161
175
// THEN
162
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::SQS::QueuePolicy' , {
176
+ Template . fromStack ( queueStack ) . hasResourceProperties ( 'AWS::SQS::QueuePolicy' , {
163
177
PolicyDocument : {
164
- Statement : [
178
+ Statement : Match . arrayWith ( [
165
179
{
166
180
Action : [
167
181
'sqs:SendMessage' ,
@@ -170,7 +184,7 @@ test('Encrypted queues result in a policy statement with aws:sourceAccount condi
170
184
] ,
171
185
Condition : {
172
186
StringEquals : {
173
- 'aws:SourceAccount' : { Ref : 'AWS::AccountId' } ,
187
+ 'aws:SourceAccount' : '111111111111' ,
174
188
} ,
175
189
} ,
176
190
Effect : 'Allow' ,
@@ -182,27 +196,11 @@ test('Encrypted queues result in a policy statement with aws:sourceAccount condi
182
196
] ,
183
197
} ,
184
198
} ,
185
- ] ,
199
+ ] ) ,
186
200
Version : '2012-10-17' ,
187
201
} ,
188
202
Queues : [ { Ref : 'MyQueueE6CA6235' } ] ,
189
203
} ) ;
190
-
191
- Template . fromStack ( stack ) . hasResourceProperties ( 'AWS::Events::Rule' , {
192
- ScheduleExpression : 'rate(1 hour)' ,
193
- State : 'ENABLED' ,
194
- Targets : [
195
- {
196
- Arn : {
197
- 'Fn::GetAtt' : [
198
- 'MyQueueE6CA6235' ,
199
- 'Arn' ,
200
- ] ,
201
- } ,
202
- Id : 'Target0' ,
203
- } ,
204
- ] ,
205
- } ) ;
206
204
} ) ;
207
205
208
206
test ( 'Encrypted queues result in a permissive policy statement when the feature flag is off' , ( ) => {
0 commit comments