]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
BucketPublicAccessBlock: add tests for RestrictPublicBuckets 563/head
authorSeena Fallah <seenafallah@gmail.com>
Wed, 1 May 2024 16:47:58 +0000 (18:47 +0200)
committerSeena Fallah <seenafallah@gmail.com>
Thu, 17 Oct 2024 17:40:23 +0000 (19:40 +0200)
Ref. https://github.com/ceph/ceph/pull/57206
Signed-off-by: Seena Fallah <seenafallah@gmail.com>
s3tests_boto3/functional/test_s3.py

index 76fa585101e73bbbf73acce6e0901b67122c7ea7..cf214ad866e7d0eaf38e0bdcb7cd411ebf3f5747 100644 (file)
@@ -13218,6 +13218,46 @@ def test_block_public_policy_with_principal():
     client.put_bucket_policy(Bucket=bucket_name, Policy=policy_document)
 
 
+def test_block_public_restrict_public_buckets():
+    bucket_name = get_new_bucket()
+    client = get_client()
+
+    # remove any existing public access block configuration
+    resp = client.delete_public_access_block(Bucket=bucket_name)
+    assert resp['ResponseMetadata']['HTTPStatusCode'] == 204
+
+    # upload an object
+    response = client.put_object(Bucket=bucket_name, Key='foo', Body='bar')
+    assert response['ResponseMetadata']['HTTPStatusCode'] == 200
+
+    # upload a bucket policy that allows public access
+    resource = _make_arn_resource("{}/{}".format(bucket_name, "*"))
+    policy_document = make_json_policy("s3:GetObject",
+                                        resource)
+    resp = client.put_bucket_policy(Bucket=bucket_name, Policy=policy_document)
+    assert resp['ResponseMetadata']['HTTPStatusCode'] == 204
+
+    # check if the object is accessible publicly
+    unauthenticated_client = get_unauthenticated_client()
+    response = unauthenticated_client.get_object(Bucket=bucket_name, Key='foo')
+    assert _get_body(response) == 'bar'
+
+    # put a public access block configuration that restricts public buckets
+    access_conf = {'BlockPublicAcls': False,
+                   'IgnorePublicAcls': False,
+                   'BlockPublicPolicy': False,
+                   'RestrictPublicBuckets': True}
+    resp = client.put_public_access_block(Bucket=bucket_name, PublicAccessBlockConfiguration=access_conf)
+    assert resp['ResponseMetadata']['HTTPStatusCode'] == 200
+
+    # check if the object is no longer accessible publicly
+    check_access_denied(unauthenticated_client.get_object, Bucket=bucket_name, Key='foo')
+
+    # check if the object is still accessible by the owner
+    response = client.get_object(Bucket=bucket_name, Key='foo')
+    assert _get_body(response) == 'bar'
+
+
 def test_ignore_public_acls():
     bucket_name = get_new_bucket()
     client = get_client()