Merge pull request #2703 from brady-gsa/fix_lambda_config
Fixes awslambda policy management
This commit is contained in:
commit
da40c7125a
7 changed files with 244 additions and 18 deletions
|
|
@ -305,6 +305,7 @@ def test_create_function_from_aws_bucket():
|
|||
"VpcId": "vpc-123abc",
|
||||
},
|
||||
"ResponseMetadata": {"HTTPStatusCode": 201},
|
||||
"State": "Active",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -348,6 +349,7 @@ def test_create_function_from_zipfile():
|
|||
"Version": "1",
|
||||
"VpcConfig": {"SecurityGroupIds": [], "SubnetIds": []},
|
||||
"ResponseMetadata": {"HTTPStatusCode": 201},
|
||||
"State": "Active",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -612,6 +614,7 @@ def test_list_create_list_get_delete_list():
|
|||
"Timeout": 3,
|
||||
"Version": "$LATEST",
|
||||
"VpcConfig": {"SecurityGroupIds": [], "SubnetIds": []},
|
||||
"State": "Active",
|
||||
},
|
||||
"ResponseMetadata": {"HTTPStatusCode": 200},
|
||||
}
|
||||
|
|
@ -808,6 +811,7 @@ def test_get_function_created_with_zipfile():
|
|||
"Timeout": 3,
|
||||
"Version": "$LATEST",
|
||||
"VpcConfig": {"SecurityGroupIds": [], "SubnetIds": []},
|
||||
"State": "Active",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -1417,6 +1421,7 @@ def test_update_function_zip():
|
|||
"Timeout": 3,
|
||||
"Version": "2",
|
||||
"VpcConfig": {"SecurityGroupIds": [], "SubnetIds": []},
|
||||
"State": "Active",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -1479,6 +1484,7 @@ def test_update_function_s3():
|
|||
"Timeout": 3,
|
||||
"Version": "2",
|
||||
"VpcConfig": {"SecurityGroupIds": [], "SubnetIds": []},
|
||||
"State": "Active",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
49
tests/test_awslambda/test_policy.py
Normal file
49
tests/test_awslambda/test_policy.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import sure
|
||||
|
||||
from moto.awslambda.policy import Policy
|
||||
|
||||
|
||||
class MockLambdaFunction:
|
||||
def __init__(self, arn):
|
||||
self.function_arn = arn
|
||||
self.policy = None
|
||||
|
||||
|
||||
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:$LATEST",
|
||||
"Sid": "statement0",
|
||||
"Condition": {
|
||||
"ArnLike": {
|
||||
"AWS:SourceArn": "arn:aws:events:us-east-1:111111111111:rule/rule_name",
|
||||
},
|
||||
"StringEquals": {"AWS:SourceAccount": "111111111111"},
|
||||
},
|
||||
}
|
||||
|
||||
policy.add_statement(json.dumps(statement))
|
||||
expected.should.be.equal(policy.statements[0])
|
||||
|
||||
sid = statement.get("StatementId", None)
|
||||
if sid == None:
|
||||
raise "TestCase.statement does not contain StatementId"
|
||||
|
||||
policy.del_statement(sid)
|
||||
[].should.be.equal(policy.statements)
|
||||
Loading…
Add table
Add a link
Reference in a new issue