@@ -24,6 +24,14 @@ describe('#compileIamRole', () => {
24
24
serverlessStepFunctions = new ServerlessStepFunctions ( serverless , options ) ;
25
25
} ) ;
26
26
27
+ const expectDenyAllPolicy = ( policy ) => {
28
+ const statements = policy . PolicyDocument . Statement ;
29
+ expect ( statements ) . to . have . lengthOf ( 1 ) ;
30
+ expect ( statements [ 0 ] . Effect ) . to . equal ( 'Deny' ) ;
31
+ expect ( statements [ 0 ] . Action ) . to . equal ( '*' ) ;
32
+ expect ( statements [ 0 ] . Resource ) . to . equal ( '*' ) ;
33
+ } ;
34
+
27
35
it ( 'should do nothing when role property exists in all statmachine properties' , ( ) => {
28
36
serverless . service . stepFunctions = {
29
37
stateMachines : {
@@ -243,7 +251,7 @@ describe('#compileIamRole', () => {
243
251
const policy = serverlessStepFunctions . serverless . service
244
252
. provider . compiledCloudFormationTemplate . Resources . IamRoleStateMachineExecution
245
253
. Properties . Policies [ 0 ] ;
246
- expect ( policy . PolicyDocument . Statement ) . to . have . lengthOf ( 0 ) ;
254
+ expectDenyAllPolicy ( policy ) ;
247
255
} ) ;
248
256
249
257
it ( 'should give sqs:SendMessage permission for only SQS referenced by state machine' , ( ) => {
@@ -362,7 +370,7 @@ describe('#compileIamRole', () => {
362
370
const policy = serverlessStepFunctions . serverless . service
363
371
. provider . compiledCloudFormationTemplate . Resources . IamRoleStateMachineExecution
364
372
. Properties . Policies [ 0 ] ;
365
- expect ( policy . PolicyDocument . Statement ) . to . have . lengthOf ( 0 ) ;
373
+ expectDenyAllPolicy ( policy ) ;
366
374
} ) ;
367
375
368
376
it ( 'should not give sqs:SendMessage permission if QueueUrl is invalid' , ( ) => {
@@ -789,10 +797,10 @@ describe('#compileIamRole', () => {
789
797
} ;
790
798
791
799
serverlessStepFunctions . compileIamRole ( ) ;
792
- const statements = serverlessStepFunctions . serverless . service
800
+ const policy = serverlessStepFunctions . serverless . service
793
801
. provider . compiledCloudFormationTemplate . Resources . IamRoleStateMachineExecution
794
- . Properties . Policies [ 0 ] . PolicyDocument . Statement ;
795
- expect ( statements ) . to . have . lengthOf ( 0 ) ;
802
+ . Properties . Policies [ 0 ] ;
803
+ expectDenyAllPolicy ( policy ) ;
796
804
} ) ;
797
805
798
806
it ( 'should not generate any permissions for Task states not yet supported' , ( ) => {
@@ -818,9 +826,37 @@ describe('#compileIamRole', () => {
818
826
} ;
819
827
820
828
serverlessStepFunctions . compileIamRole ( ) ;
821
- const statements = serverlessStepFunctions . serverless . service
829
+ const policy = serverlessStepFunctions . serverless . service
822
830
. provider . compiledCloudFormationTemplate . Resources . IamRoleStateMachineExecution
823
- . Properties . Policies [ 0 ] . PolicyDocument . Statement ;
824
- expect ( statements ) . to . have . lengthOf ( 0 ) ;
831
+ . Properties . Policies [ 0 ] ;
832
+ expectDenyAllPolicy ( policy ) ;
833
+ } ) ;
834
+
835
+ it ( 'should generate a Deny all statement if state machine has no tasks' , ( ) => {
836
+ const genStateMachine = ( name ) => ( {
837
+ name,
838
+ definition : {
839
+ StartAt : 'A' ,
840
+ States : {
841
+ A : {
842
+ Type : 'Pass' ,
843
+ End : true ,
844
+ } ,
845
+ } ,
846
+ } ,
847
+ } ) ;
848
+
849
+ serverless . service . stepFunctions = {
850
+ stateMachines : {
851
+ myStateMachine1 : genStateMachine ( 'stateMachineBeta1' ) ,
852
+ myStateMachine2 : genStateMachine ( 'stateMachineBeta2' ) ,
853
+ } ,
854
+ } ;
855
+
856
+ serverlessStepFunctions . compileIamRole ( ) ;
857
+ const policy = serverlessStepFunctions . serverless . service
858
+ . provider . compiledCloudFormationTemplate . Resources . IamRoleStateMachineExecution
859
+ . Properties . Policies [ 0 ] ;
860
+ expectDenyAllPolicy ( policy ) ;
825
861
} ) ;
826
862
} ) ;
0 commit comments