moto/tests/test_awslambda/test_policy.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.3 KiB
Python
Raw Permalink Normal View History

import json
from moto.awslambda.policy import Policy
class MockLambdaFunction:
def __init__(self, arn):
self.function_arn = arn
self.policy = None
2020-01-29 14:46:09 +00:00
def test_policy():
policy = Policy(MockLambdaFunction("arn"))
statement = {
"StatementId": "statement0",
"Action": "lambda:InvokeFunction",
"FunctionName": "function_name",
"Principal": "events.amazonaws.com",
"SourceArn": "arn:aws:events:us-east-1:111111111111:rule/rule_name",
"SourceAccount": "111111111111",
}
expected = {
"Action": "lambda:InvokeFunction",
"FunctionName": "function_name",
"Principal": {"Service": "events.amazonaws.com"},
"Effect": "Allow",
"Resource": "arn",
2020-01-29 14:46:09 +00:00
"Sid": "statement0",
"Condition": {
"ArnLike": {
"AWS:SourceArn": "arn:aws:events:us-east-1:111111111111:rule/rule_name",
},
2020-01-29 14:46:09 +00:00
"StringEquals": {"AWS:SourceAccount": "111111111111"},
},
}
2020-01-29 14:46:09 +00:00
policy.add_statement(json.dumps(statement))
assert expected == policy.statements[0]
2020-01-29 14:46:09 +00:00
sid = statement.get("StatementId", None)
if sid is None:
2020-01-29 14:46:09 +00:00
raise "TestCase.statement does not contain StatementId"
2020-01-29 14:46:09 +00:00
policy.del_statement(sid)
assert [] == policy.statements