@@ -283,26 +283,34 @@ def test_ensure_default_build_image_stack_cleanup_role_permission_denied(self, a
283283 aws_api_mock .iam .tag_role .assert_not_called ()
284284
285285 @pytest .mark .parametrize (
286- "account_id, partition" ,
286+ "account_id, partition, actions " ,
287287 [
288- ("123456789012" , "aws" ),
289- ("000000000000" , "aws-us-gov" ),
288+ ("123456789012" , "aws" , [ "lambda:DeleteFunction" , "lambda:RemovePermission" , "lambda:GetFunction" , "lambda:GetPolicy" ] ),
289+ ("000000000000" , "aws-us-gov" , [ "lambda:DeleteFunction" , "lambda:RemovePermission" , "lambda:GetFunction" , "lambda:GetPolicy" ] ),
290290 ],
291291 )
292- def test_expected_inline_policy_dynamic_fields (self , account_id , partition ):
292+ def test_expected_inline_policy_dynamic_fields (self , account_id , partition , actions ):
293293 raw = _expected_inline_policy (account_id , partition )
294294 policy = json .loads (raw )
295295 assert policy ["Version" ] == "2012-10-17"
296296 assert len (policy ["Statement" ]) == 13
297297 for statement in policy ["Statement" ]:
298298 resources = statement ["Resource" ]
299+ action = statement ["Action" ]
300+ action = action if isinstance (action , list ) else [action ]
301+ for act in action :
302+ if act in actions :
303+ actions .remove (act )
304+
299305 resources = resources if isinstance (resources , list ) else [resources ]
300306 for res in resources :
301307 if res == "*" :
302308 continue
303309 assert f"arn:{ partition } " in res
304310 if not res == f"arn:{ partition } :ec2:*::image/*" :
305311 assert f":{ account_id } :" in res
312+ if len (actions ) != 0 :
313+ assert False , f"Actions { actions } are not in the policy"
306314
307315 def _build_args (self , args ):
308316 args = [[k , v ] if v is not None else [k ] for k , v in args .items ()]
0 commit comments