2022-09-23 11:09:41 +00:00
|
|
|
import allure
|
|
|
|
import pytest
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib import reporter
|
2024-06-05 10:07:07 +00:00
|
|
|
from frostfs_testlib.resources.error_patterns import S3_BUCKET_DOES_NOT_ALLOW_ACL
|
|
|
|
from frostfs_testlib.resources.s3_acl_grants import PRIVATE_GRANTS, PUBLIC_READ_GRANTS, PUBLIC_READ_WRITE_GRANTS
|
2024-06-24 23:27:54 +00:00
|
|
|
from frostfs_testlib.s3 import S3ClientWrapper
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.steps.s3 import s3_helper
|
2023-08-02 11:54:03 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.object_size import ObjectSize
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.utils.file_utils import generate_file
|
2022-09-23 11:09:41 +00:00
|
|
|
|
|
|
|
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.acl
|
2022-09-23 11:09:41 +00:00
|
|
|
@pytest.mark.s3_gate
|
2023-05-15 09:59:33 +00:00
|
|
|
class TestS3GateACL:
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Object ACL (s3_client={s3_client})")
|
2023-11-01 16:20:15 +00:00
|
|
|
def test_s3_object_ACL(self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(simple_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
2022-09-23 11:09:41 +00:00
|
|
|
|
2024-06-05 10:07:07 +00:00
|
|
|
with reporter.step("Put object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path)
|
2024-06-05 10:07:07 +00:00
|
|
|
|
|
|
|
with reporter.step("Verify private ACL is default"):
|
|
|
|
object_grants = s3_client.get_object_acl(bucket, file_name)
|
|
|
|
s3_helper.verify_acl_permissions(object_grants, PRIVATE_GRANTS)
|
|
|
|
|
|
|
|
with reporter.step("Verify put object ACL is restricted"):
|
|
|
|
with pytest.raises(Exception, match=S3_BUCKET_DOES_NOT_ALLOW_ACL):
|
|
|
|
object_grants = s3_client.put_object_acl(bucket, file_name, acl="public-read")
|
2022-09-23 11:09:41 +00:00
|
|
|
|
2024-06-24 23:27:54 +00:00
|
|
|
@allure.title("Create Bucket with different ACL (s3_client={s3_client})")
|
|
|
|
def test_s3_create_bucket_with_ACL(self, s3_client: S3ClientWrapper):
|
|
|
|
with reporter.step("Create bucket with ACL private"):
|
|
|
|
bucket = s3_client.create_bucket(object_lock_enabled_for_bucket=True, acl="private")
|
|
|
|
bucket_grants = s3_client.get_bucket_acl(bucket)
|
|
|
|
s3_helper.verify_acl_permissions(bucket_grants, PRIVATE_GRANTS)
|
|
|
|
|
|
|
|
with reporter.step("Create bucket with ACL public-read"):
|
|
|
|
read_bucket = s3_client.create_bucket(object_lock_enabled_for_bucket=True, acl="public-read")
|
|
|
|
bucket_grants = s3_client.get_bucket_acl(read_bucket)
|
|
|
|
s3_helper.verify_acl_permissions(bucket_grants, PUBLIC_READ_GRANTS)
|
|
|
|
|
|
|
|
with reporter.step("Create bucket with ACL public-read-write"):
|
|
|
|
public_rw_bucket = s3_client.create_bucket(object_lock_enabled_for_bucket=True, acl="public-read-write")
|
|
|
|
bucket_grants = s3_client.get_bucket_acl(public_rw_bucket)
|
|
|
|
s3_helper.verify_acl_permissions(bucket_grants, PUBLIC_READ_WRITE_GRANTS)
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Bucket ACL (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_bucket_ACL(self, s3_client: S3ClientWrapper):
|
2024-06-05 10:07:07 +00:00
|
|
|
with reporter.step("Create bucket with public-read-write ACL"):
|
2023-11-01 16:20:15 +00:00
|
|
|
bucket = s3_client.create_bucket(object_lock_enabled_for_bucket=True, acl="public-read-write")
|
2024-06-05 10:07:07 +00:00
|
|
|
bucket_grants = s3_client.get_bucket_acl(bucket)
|
|
|
|
s3_helper.verify_acl_permissions(bucket_grants, PUBLIC_READ_WRITE_GRANTS)
|
2022-09-23 11:09:41 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Change bucket ACL to private"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_bucket_acl(bucket, acl="private")
|
2024-06-05 10:07:07 +00:00
|
|
|
bucket_grants = s3_client.get_bucket_acl(bucket)
|
|
|
|
s3_helper.verify_acl_permissions(bucket_grants, PRIVATE_GRANTS)
|
|
|
|
|
|
|
|
with reporter.step("Change bucket ACL to public-read"):
|
|
|
|
s3_client.put_bucket_acl(bucket, acl="public-read")
|
|
|
|
bucket_grants = s3_client.get_bucket_acl(bucket)
|
|
|
|
s3_helper.verify_acl_permissions(bucket_grants, PUBLIC_READ_GRANTS)
|