@@ -24,6 +24,14 @@ describe('#compileIamRole', () => {
2424 serverlessStepFunctions = new ServerlessStepFunctions ( serverless , options ) ;
2525 } ) ;
2626
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+
2735 it ( 'should do nothing when role property exists in all statmachine properties' , ( ) => {
2836 serverless . service . stepFunctions = {
2937 stateMachines : {
@@ -243,7 +251,7 @@ describe('#compileIamRole', () => {
243251 const policy = serverlessStepFunctions . serverless . service
244252 . provider . compiledCloudFormationTemplate . Resources . IamRoleStateMachineExecution
245253 . Properties . Policies [ 0 ] ;
246- expect ( policy . PolicyDocument . Statement ) . to . have . lengthOf ( 0 ) ;
254+ expectDenyAllPolicy ( policy ) ;
247255 } ) ;
248256
249257 it ( 'should give sqs:SendMessage permission for only SQS referenced by state machine' , ( ) => {
@@ -362,7 +370,7 @@ describe('#compileIamRole', () => {
362370 const policy = serverlessStepFunctions . serverless . service
363371 . provider . compiledCloudFormationTemplate . Resources . IamRoleStateMachineExecution
364372 . Properties . Policies [ 0 ] ;
365- expect ( policy . PolicyDocument . Statement ) . to . have . lengthOf ( 0 ) ;
373+ expectDenyAllPolicy ( policy ) ;
366374 } ) ;
367375
368376 it ( 'should not give sqs:SendMessage permission if QueueUrl is invalid' , ( ) => {
@@ -789,10 +797,10 @@ describe('#compileIamRole', () => {
789797 } ;
790798
791799 serverlessStepFunctions . compileIamRole ( ) ;
792- const statements = serverlessStepFunctions . serverless . service
800+ const policy = serverlessStepFunctions . serverless . service
793801 . provider . compiledCloudFormationTemplate . Resources . IamRoleStateMachineExecution
794- . Properties . Policies [ 0 ] . PolicyDocument . Statement ;
795- expect ( statements ) . to . have . lengthOf ( 0 ) ;
802+ . Properties . Policies [ 0 ] ;
803+ expectDenyAllPolicy ( policy ) ;
796804 } ) ;
797805
798806 it ( 'should not generate any permissions for Task states not yet supported' , ( ) => {
@@ -818,9 +826,37 @@ describe('#compileIamRole', () => {
818826 } ;
819827
820828 serverlessStepFunctions . compileIamRole ( ) ;
821- const statements = serverlessStepFunctions . serverless . service
829+ const policy = serverlessStepFunctions . serverless . service
822830 . 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 ) ;
825861 } ) ;
826862} ) ;
0 commit comments