@@ -2107,4 +2107,104 @@ describe('#compileIamRole', () => {
2107
2107
] ,
2108
2108
} ] ) ;
2109
2109
} ) ;
2110
+
2111
+ it ( 'should give event bridge putEvents permissions' , ( ) => {
2112
+ const genStateMachine = id => ( {
2113
+ id,
2114
+ definition : {
2115
+ StartAt : 'A' ,
2116
+ States : {
2117
+ A : {
2118
+ Type : 'Task' ,
2119
+ Resource : 'arn:aws:states:::events:putEvents' ,
2120
+ Parameters : {
2121
+ Entries : [ {
2122
+ Source : 'source' ,
2123
+ DetailType : 'DetailType' ,
2124
+ } ] ,
2125
+ } ,
2126
+ End : true ,
2127
+ } ,
2128
+ } ,
2129
+ } ,
2130
+ } ) ;
2131
+
2132
+ serverless . service . stepFunctions = {
2133
+ stateMachines : {
2134
+ myStateMachine1 : genStateMachine ( 'StateMachine1' ) ,
2135
+ } ,
2136
+ } ;
2137
+
2138
+ serverlessStepFunctions . compileIamRole ( ) ;
2139
+ const statements = serverlessStepFunctions . serverless . service
2140
+ . provider . compiledCloudFormationTemplate . Resources . StateMachine1Role
2141
+ . Properties . Policies [ 0 ] . PolicyDocument . Statement ;
2142
+
2143
+ const eventPermissions = statements . filter ( s => _ . isEqual ( s . Action , [ 'events:PutEvents' ] ) ) ;
2144
+ expect ( eventPermissions ) . to . has . lengthOf ( 1 ) ;
2145
+ expect ( eventPermissions [ 0 ] . Resource ) . to . deep . eq ( [ {
2146
+ 'Fn::Sub' : [
2147
+ 'arn:aws:events:${AWS::Region}:${AWS::AccountId}:event-bus/${eventBus}' ,
2148
+ { eventBus : 'default' } ,
2149
+ ] ,
2150
+ } ] ) ;
2151
+ } ) ;
2152
+
2153
+ it ( 'should give event bridge putEvents multiple permissions' , ( ) => {
2154
+ const genStateMachine = id => ( {
2155
+ id,
2156
+ definition : {
2157
+ StartAt : 'A' ,
2158
+ States : {
2159
+ A : {
2160
+ Type : 'Task' ,
2161
+ Resource : 'arn:aws:states:::events:putEvents' ,
2162
+ Parameters : {
2163
+ Entries : [
2164
+ {
2165
+ Source : 'source' ,
2166
+ DetailType : 'DetailType' ,
2167
+ EventBusName : 'default' ,
2168
+ } ,
2169
+ {
2170
+ Source : 'source' ,
2171
+ DetailType : 'DetailType' ,
2172
+ EventBusName : 'custom' ,
2173
+ } ,
2174
+ ] ,
2175
+ } ,
2176
+ End : true ,
2177
+ } ,
2178
+ } ,
2179
+ } ,
2180
+ } ) ;
2181
+
2182
+ serverless . service . stepFunctions = {
2183
+ stateMachines : {
2184
+ myStateMachine1 : genStateMachine ( 'StateMachine1' ) ,
2185
+ } ,
2186
+ } ;
2187
+
2188
+ serverlessStepFunctions . compileIamRole ( ) ;
2189
+ const statements = serverlessStepFunctions . serverless . service
2190
+ . provider . compiledCloudFormationTemplate . Resources . StateMachine1Role
2191
+ . Properties . Policies [ 0 ] . PolicyDocument . Statement ;
2192
+
2193
+ const eventPermissions = statements . filter ( s => _ . isEqual ( s . Action , [ 'events:PutEvents' ] ) ) ;
2194
+ expect ( eventPermissions [ 0 ] . Resource ) . to . has . lengthOf ( 2 ) ;
2195
+ expect ( eventPermissions [ 0 ] . Resource ) . to . deep . eq ( [
2196
+ {
2197
+ 'Fn::Sub' : [
2198
+ 'arn:aws:events:${AWS::Region}:${AWS::AccountId}:event-bus/${eventBus}' ,
2199
+ { eventBus : 'default' } ,
2200
+ ] ,
2201
+ } ,
2202
+ {
2203
+ 'Fn::Sub' : [
2204
+ 'arn:aws:events:${AWS::Region}:${AWS::AccountId}:event-bus/${eventBus}' ,
2205
+ { eventBus : 'custom' } ,
2206
+ ] ,
2207
+ } ,
2208
+ ] ) ;
2209
+ } ) ;
2110
2210
} ) ;
0 commit comments