]> git.apps.os.sepia.ceph.com Git - s3-tests.git/commitdiff
rgw/s3-test: adding test to set, get, delete and then get
authorPritha Srivastava <prsrivas@redhat.com>
Tue, 12 Nov 2024 04:34:25 +0000 (10:04 +0530)
committerPritha Srivastava <prsrivas@redhat.com>
Tue, 12 Nov 2024 05:45:21 +0000 (11:15 +0530)
a bucket policy to ensure that delete correctly removes
the bucket policy

Signed-off-by: Pritha Srivastava <prsrivas@redhat.com>
s3tests_boto3/functional/test_s3.py

index 85dfba16dea688a3c1a976592f775934dcc64090..1abf5c50f3e6508b37a21f22c07d856f4b5fb0f4 100644 (file)
@@ -10912,6 +10912,43 @@ def test_bucket_policy_set_condition_operator_end_with_IfExists():
     response =  client.get_bucket_policy(Bucket=bucket_name)
     print(response)
 
+@pytest.mark.bucket_policy
+def test_set_get_del_bucket_policy():
+    bucket_name = get_new_bucket()
+    client = get_client()
+    key = 'asdf'
+    client.put_object(Bucket=bucket_name, Key=key, Body='asdf')
+
+    resource1 = "arn:aws:s3:::" + bucket_name
+    resource2 = "arn:aws:s3:::" + bucket_name + "/*"
+    policy_document = json.dumps(
+    {
+        "Version": "2012-10-17",
+        "Statement": [{
+        "Effect": "Allow",
+        "Principal": {"AWS": "*"},
+        "Action": "s3:ListBucket",
+        "Resource": [
+            "{}".format(resource1),
+            "{}".format(resource2)
+          ]
+        }]
+     })
+
+    client.put_bucket_policy(Bucket=bucket_name, Policy=policy_document)
+
+    response = client.get_bucket_policy(Bucket=bucket_name)
+    response_policy = response['Policy']
+    assert policy_document == response_policy
+
+    client.delete_bucket_policy(Bucket=bucket_name)
+
+    try:
+        response = client.get_bucket_policy(Bucket=bucket_name)
+    except botocore.exceptions.ClientError as e:
+        print (e)
+        assert e.response['Error']['Code'] == 'NoSuchBucketPolicy'
+
 def _create_simple_tagset(count):
     tagset = []
     for i in range(count):