From 5da742036e296815034bb1e9f47737645687114d Mon Sep 17 00:00:00 2001 From: Abhishek Lekshmanan Date: Mon, 6 Nov 2017 16:47:05 +0100 Subject: [PATCH] policy: refactor make_json_policy to use the new Policy classes since make_json_policy is redundantly doing most of the same work, refactor to use the new policy classes instead Signed-off-by: Abhishek Lekshmanan --- s3tests/functional/policy.py | 8 ++++++++ s3tests/functional/test_s3.py | 24 +----------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/s3tests/functional/policy.py b/s3tests/functional/policy.py index 910461a..aae5454 100644 --- a/s3tests/functional/policy.py +++ b/s3tests/functional/policy.py @@ -36,3 +36,11 @@ class Policy(object): } return json.dumps(policy_dict) + +def make_json_policy(action, resource, principal={"AWS": "*"}, conditions=None): + """ + Helper function to make single statement policies + """ + s = Statement(action, resource, principal, condition=conditions) + p = Policy() + return p.add_statement(s).to_json() diff --git a/s3tests/functional/test_s3.py b/s3tests/functional/test_s3.py index 728766c..12b065a 100644 --- a/s3tests/functional/test_s3.py +++ b/s3tests/functional/test_s3.py @@ -44,7 +44,7 @@ from .utils import assert_raises from .utils import generate_random from .utils import region_sync_meta -from .policy import Policy, Statement +from .policy import Policy, Statement, make_json_policy import AnonymousAuth @@ -8744,28 +8744,6 @@ def test_sse_kms_read_declare(): def _make_arn_resource(path="*"): return "arn:aws:s3:::{}".format(path) -def make_json_policy(action, resource, principal={"AWS": "*"}, conditions=None): - - policy = { - "Version": "2012-10-17", - "Statement": [{ - "Effect": "Allow", - "Principal": principal, - "Action": action, - "Resource": [ - resource - ], - }] - } - - # Currently lets only support adding a common conditional to every - # statement in this function - for statement in policy["Statement"]: - if conditions is not None: - statement["Condition"] = conditions - - return json.dumps(policy) - @attr(resource='bucket') @attr(method='get') @attr(operation='Test Bucket Policy')