2022-10-04 08:22:04 +00:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
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.s3_acl_grants import PRIVATE_GRANTS, PUBLIC_READ_GRANTS, PUBLIC_READ_WRITE_GRANTS
|
2023-10-31 14:51:09 +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
|
2023-02-27 16:54:27 +00:00
|
|
|
|
2022-10-04 08:22:04 +00:00
|
|
|
|
|
|
|
@pytest.mark.s3_gate
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.s3_gate_bucket
|
2023-05-15 09:59:33 +00:00
|
|
|
class TestS3GateBucket:
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Create Bucket with different ACL (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_create_bucket_with_ACL(self, s3_client: S3ClientWrapper):
|
2022-10-04 08:22:04 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Create bucket with ACL private"):
|
2023-05-15 09:59:33 +00:00
|
|
|
bucket = s3_client.create_bucket(object_lock_enabled_for_bucket=True, 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)
|
2022-10-04 08:22:04 +00:00
|
|
|
|
2024-06-05 10:07:07 +00:00
|
|
|
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)
|
2022-10-04 08:22:04 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Create bucket with ACL public-read-write"):
|
2024-06-05 10:07:07 +00:00
|
|
|
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)
|
2022-10-04 08:22:04 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Create bucket with object lock (s3_client={s3_client})")
|
2023-10-31 14:51:09 +00:00
|
|
|
def test_s3_bucket_object_lock(self, s3_client: S3ClientWrapper, 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-10-04 08:22:04 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Create bucket with --no-object-lock-enabled-for-bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
bucket = s3_client.create_bucket(object_lock_enabled_for_bucket=False)
|
2022-10-04 08:22:04 +00:00
|
|
|
date_obj = datetime.utcnow() + timedelta(days=1)
|
2023-10-31 14:51:09 +00:00
|
|
|
with pytest.raises(Exception, match=r".*Object Lock configuration does not exist for this bucket.*"):
|
2022-10-04 08:22:04 +00:00
|
|
|
# An error occurred (ObjectLockConfigurationNotFoundError) when calling the PutObject operation (reached max retries: 0):
|
|
|
|
# Object Lock configuration does not exist for this bucket
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-10-04 08:22:04 +00:00
|
|
|
bucket,
|
|
|
|
file_path,
|
2023-05-15 09:59:33 +00:00
|
|
|
object_lock_mode="COMPLIANCE",
|
|
|
|
object_lock_retain_until_date=date_obj.strftime("%Y-%m-%dT%H:%M:%S"),
|
2022-10-04 08:22:04 +00:00
|
|
|
)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Create bucket with --object-lock-enabled-for-bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
bucket_1 = s3_client.create_bucket(object_lock_enabled_for_bucket=True)
|
2022-10-04 08:22:04 +00:00
|
|
|
date_obj_1 = datetime.utcnow() + timedelta(days=1)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-10-04 08:22:04 +00:00
|
|
|
bucket_1,
|
|
|
|
file_path,
|
2023-05-15 09:59:33 +00:00
|
|
|
object_lock_mode="COMPLIANCE",
|
|
|
|
object_lock_retain_until_date=date_obj_1.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
|
|
object_lock_legal_hold_status="ON",
|
2022-10-04 08:22:04 +00:00
|
|
|
)
|
2023-10-31 14:51:09 +00:00
|
|
|
s3_helper.assert_object_lock_mode(s3_client, bucket_1, file_name, "COMPLIANCE", date_obj_1, "ON")
|
2022-10-04 08:22:04 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Delete bucket (s3_client={s3_client})")
|
2023-08-02 11:54:03 +00:00
|
|
|
def test_s3_delete_bucket(self, s3_client: S3ClientWrapper, simple_object_size: ObjectSize):
|
|
|
|
file_path_1 = generate_file(simple_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name_1 = s3_helper.object_key_from_file_path(file_path_1)
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_2 = generate_file(simple_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name_2 = s3_helper.object_key_from_file_path(file_path_2)
|
|
|
|
bucket = s3_client.create_bucket()
|
2022-10-04 08:22:04 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Put two objects into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_1)
|
|
|
|
s3_client.put_object(bucket, file_path_2)
|
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, [file_name_1, file_name_2])
|
2022-10-04 08:22:04 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Try to delete not empty bucket and get error"):
|
2022-10-04 08:22:04 +00:00
|
|
|
with pytest.raises(Exception, match=r".*The bucket you tried to delete is not empty.*"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_bucket(bucket)
|
2022-10-04 08:22:04 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete object in bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_object(bucket, file_name_1)
|
|
|
|
s3_client.delete_object(bucket, file_name_2)
|
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, [])
|
2022-10-04 08:22:04 +00:00
|
|
|
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step("Delete empty bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_bucket(bucket)
|
2022-10-04 08:22:04 +00:00
|
|
|
with pytest.raises(Exception, match=r".*Not Found.*"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.head_bucket(bucket)
|