@@ -169,16 +169,16 @@ describe('Utils', function() {
169
169
expect ( Utils . findAllReferences ( testRoot ) )
170
170
. to . deep . equal ( [
171
171
{
172
- " path" : " other" ,
173
- " ref" : " Ref#4"
172
+ ' path' : ' other' ,
173
+ ' ref' : ' Ref#4'
174
174
} ,
175
175
{
176
- " path" : " items[1].otherTestItem.prop2" ,
177
- " ref" : " Ref#3"
176
+ ' path' : ' items[1].otherTestItem.prop2' ,
177
+ ' ref' : ' Ref#3'
178
178
} ,
179
179
{
180
- " path" : " items[1].otherTestItem.prop1.arrayTest[0]" ,
181
- " ref" : " Ref#2"
180
+ ' path' : ' items[1].otherTestItem.prop1.arrayTest[0]' ,
181
+ ' ref' : ' Ref#2'
182
182
}
183
183
] ) ;
184
184
} ) ;
@@ -225,20 +225,20 @@ describe('Utils', function() {
225
225
expect ( Utils . findAllReferences ( testRoot ) )
226
226
. to . deep . equal ( [
227
227
{
228
- " path" : " other" ,
229
- " ref" : " Ref#4"
228
+ ' path' : ' other' ,
229
+ ' ref' : ' Ref#4'
230
230
} ,
231
231
{
232
- " path" : " items[1].otherTestItem.prop2" ,
233
- " ref" : " Ref#3"
232
+ ' path' : ' items[1].otherTestItem.prop2' ,
233
+ ' ref' : ' Ref#3'
234
234
} ,
235
235
{
236
- " path" : " items[1].otherTestItem.prop1.arrayTest[0]" ,
237
- " ref" : " Ref#2"
236
+ ' path' : ' items[1].otherTestItem.prop1.arrayTest[0]' ,
237
+ ' ref' : ' Ref#2'
238
238
} ,
239
239
{
240
- " path" : " items[0].testItem" ,
241
- " ref" : " Ref"
240
+ ' path' : ' items[0].testItem' ,
241
+ ' ref' : ' Ref'
242
242
}
243
243
] ) ;
244
244
} ) ;
@@ -281,4 +281,152 @@ describe('Utils', function() {
281
281
} ) ;
282
282
} ) ;
283
283
} ) ;
284
+
285
+ describe ( '#hasPermissionPrincipal()' , ( ) => {
286
+ it ( 'should work with string principals' , ( ) => {
287
+ const permission = {
288
+ 'Type' : 'AWS::Lambda::Permission' ,
289
+ 'Properties' : {
290
+ 'FunctionName' : {
291
+ 'Fn::GetAtt' : [
292
+ 'MyLambdaLambdaFunction' ,
293
+ 'Arn'
294
+ ]
295
+ } ,
296
+ 'Action' : 'lambda:InvokeFunction' ,
297
+ 'Principal' : 'apigateway.amazonaws.com' ,
298
+ 'SourceArn' : {
299
+ 'Fn::Join' : [
300
+ '' ,
301
+ [
302
+ 'arn:' ,
303
+ {
304
+ 'Ref' : 'AWS::Partition'
305
+ } ,
306
+ ':execute-api:' ,
307
+ {
308
+ 'Ref' : 'AWS::Region'
309
+ } ,
310
+ ':' ,
311
+ {
312
+ 'Ref' : 'AWS::AccountId'
313
+ } ,
314
+ ':' ,
315
+ {
316
+ 'Ref' : 'ApiGatewayRestApi'
317
+ } ,
318
+ '/*/*'
319
+ ]
320
+ ]
321
+ }
322
+ }
323
+ } ;
324
+
325
+ expect ( Utils . hasPermissionPrincipal ( permission , 'apigateway' ) ) . to . be . true ;
326
+ } ) ;
327
+
328
+ it ( 'should work with constructed principals' , ( ) => {
329
+ const permission = {
330
+ 'Type' : 'AWS::Lambda::Permission' ,
331
+ 'Properties' : {
332
+ 'FunctionName' : {
333
+ 'Fn::GetAtt' : [
334
+ 'MyLambdaLambdaFunction' ,
335
+ 'Arn'
336
+ ]
337
+ } ,
338
+ 'Action' : 'lambda:InvokeFunction' ,
339
+ 'Principal' : {
340
+ 'Fn::Join' : [
341
+ '' ,
342
+ [
343
+ 'apigateway.' ,
344
+ {
345
+ 'Ref' : 'AWS::URLSuffix'
346
+ }
347
+ ]
348
+ ]
349
+ } ,
350
+ 'SourceArn' : {
351
+ 'Fn::Join' : [
352
+ '' ,
353
+ [
354
+ 'arn:' ,
355
+ {
356
+ 'Ref' : 'AWS::Partition'
357
+ } ,
358
+ ':execute-api:' ,
359
+ {
360
+ 'Ref' : 'AWS::Region'
361
+ } ,
362
+ ':' ,
363
+ {
364
+ 'Ref' : 'AWS::AccountId'
365
+ } ,
366
+ ':' ,
367
+ {
368
+ 'Ref' : 'ApiGatewayRestApi'
369
+ } ,
370
+ '/*/*'
371
+ ]
372
+ ]
373
+ }
374
+ }
375
+ } ;
376
+
377
+ expect ( Utils . hasPermissionPrincipal ( permission , 'apigateway' ) ) . to . be . true ;
378
+ } ) ;
379
+
380
+ it ( 'should return false if the service is not matched' , ( ) => {
381
+ const permission = {
382
+ 'Type' : 'AWS::Lambda::Permission' ,
383
+ 'Properties' : {
384
+ 'FunctionName' : {
385
+ 'Fn::GetAtt' : [
386
+ 'MyLambdaLambdaFunction' ,
387
+ 'Arn'
388
+ ]
389
+ } ,
390
+ 'Action' : 'lambda:InvokeFunction' ,
391
+ 'Principal' : {
392
+ 'Fn::Join' : [
393
+ '' ,
394
+ [
395
+ 'apigateway.' ,
396
+ {
397
+ 'Ref' : 'AWS::URLSuffix'
398
+ }
399
+ ]
400
+ ]
401
+ } ,
402
+ 'SourceArn' : {
403
+ 'Fn::Join' : [
404
+ '' ,
405
+ [
406
+ 'arn:' ,
407
+ {
408
+ 'Ref' : 'AWS::Partition'
409
+ } ,
410
+ ':execute-api:' ,
411
+ {
412
+ 'Ref' : 'AWS::Region'
413
+ } ,
414
+ ':' ,
415
+ {
416
+ 'Ref' : 'AWS::AccountId'
417
+ } ,
418
+ ':' ,
419
+ {
420
+ 'Ref' : 'ApiGatewayRestApi'
421
+ } ,
422
+ '/*/*'
423
+ ]
424
+ ]
425
+ }
426
+ }
427
+ } ;
428
+
429
+ expect ( Utils . hasPermissionPrincipal ( permission , 'events' ) ) . to . be . false ;
430
+ } ) ;
431
+ } ) ;
284
432
} ) ;
0 commit comments