2022-10-04 08:22:04 +00:00
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2023-02-27 16:54:27 +00:00
|
|
|
|
|
|
|
from pytest_tests.helpers.file_helper import generate_file
|
|
|
|
from pytest_tests.helpers.s3_helper import (
|
2023-02-14 08:09:37 +00:00
|
|
|
assert_object_lock_mode,
|
|
|
|
assert_s3_acl,
|
|
|
|
check_objects_in_bucket,
|
|
|
|
object_key_from_file_path,
|
|
|
|
)
|
2023-02-27 16:54:27 +00:00
|
|
|
from pytest_tests.steps import s3_gate_bucket, s3_gate_object
|
|
|
|
from pytest_tests.steps.s3_gate_base import TestS3GateBase
|
2022-10-04 08:22:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
def pytest_generate_tests(metafunc):
|
|
|
|
if "s3_client" in metafunc.fixturenames:
|
|
|
|
metafunc.parametrize("s3_client", ["aws cli", "boto3"], indirect=True)
|
|
|
|
|
|
|
|
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.sanity
|
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
|
2022-10-04 08:22:04 +00:00
|
|
|
class TestS3GateBucket(TestS3GateBase):
|
|
|
|
@allure.title("Test S3: Create Bucket with different ACL")
|
|
|
|
def test_s3_create_bucket_with_ACL(self):
|
|
|
|
|
|
|
|
with allure.step("Create bucket with ACL private"):
|
|
|
|
bucket = s3_gate_bucket.create_bucket_s3(self.s3_client, True, acl="private")
|
|
|
|
bucket_acl = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket)
|
2023-02-14 08:09:37 +00:00
|
|
|
assert_s3_acl(acl_grants=bucket_acl, permitted_users="CanonicalUser")
|
2022-10-04 08:22:04 +00:00
|
|
|
|
|
|
|
with allure.step("Create bucket with ACL = public-read"):
|
|
|
|
bucket_1 = s3_gate_bucket.create_bucket_s3(self.s3_client, True, acl="public-read")
|
|
|
|
bucket_acl_1 = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket_1)
|
2023-02-14 08:09:37 +00:00
|
|
|
assert_s3_acl(acl_grants=bucket_acl_1, permitted_users="AllUsers")
|
2022-10-04 08:22:04 +00:00
|
|
|
|
|
|
|
with allure.step("Create bucket with ACL public-read-write"):
|
|
|
|
bucket_2 = s3_gate_bucket.create_bucket_s3(
|
|
|
|
self.s3_client, True, acl="public-read-write"
|
|
|
|
)
|
|
|
|
bucket_acl_2 = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket_2)
|
2023-02-14 08:09:37 +00:00
|
|
|
assert_s3_acl(acl_grants=bucket_acl_2, permitted_users="AllUsers")
|
2022-10-04 08:22:04 +00:00
|
|
|
|
|
|
|
with allure.step("Create bucket with ACL = authenticated-read"):
|
|
|
|
bucket_3 = s3_gate_bucket.create_bucket_s3(
|
|
|
|
self.s3_client, True, acl="authenticated-read"
|
|
|
|
)
|
|
|
|
bucket_acl_3 = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket_3)
|
2023-02-14 08:09:37 +00:00
|
|
|
assert_s3_acl(acl_grants=bucket_acl_3, permitted_users="AllUsers")
|
2022-10-04 08:22:04 +00:00
|
|
|
|
|
|
|
@allure.title("Test S3: Create Bucket with different ACL by grand")
|
|
|
|
def test_s3_create_bucket_with_grands(self):
|
|
|
|
|
|
|
|
with allure.step("Create bucket with --grant-read"):
|
|
|
|
bucket = s3_gate_bucket.create_bucket_s3(
|
|
|
|
self.s3_client,
|
|
|
|
True,
|
|
|
|
grant_read="uri=http://acs.amazonaws.com/groups/global/AllUsers",
|
|
|
|
)
|
|
|
|
bucket_acl = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket)
|
2023-02-14 08:09:37 +00:00
|
|
|
assert_s3_acl(acl_grants=bucket_acl, permitted_users="AllUsers")
|
2022-10-04 08:22:04 +00:00
|
|
|
|
|
|
|
with allure.step("Create bucket with --grant-wtite"):
|
|
|
|
bucket_1 = s3_gate_bucket.create_bucket_s3(
|
|
|
|
self.s3_client,
|
|
|
|
True,
|
|
|
|
grant_write="uri=http://acs.amazonaws.com/groups/global/AllUsers",
|
|
|
|
)
|
|
|
|
bucket_acl_1 = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket_1)
|
2023-02-14 08:09:37 +00:00
|
|
|
assert_s3_acl(acl_grants=bucket_acl_1, permitted_users="AllUsers")
|
2022-10-04 08:22:04 +00:00
|
|
|
|
|
|
|
with allure.step("Create bucket with --grant-full-control"):
|
|
|
|
bucket_2 = s3_gate_bucket.create_bucket_s3(
|
|
|
|
self.s3_client,
|
|
|
|
True,
|
|
|
|
grant_full_control="uri=http://acs.amazonaws.com/groups/global/AllUsers",
|
|
|
|
)
|
|
|
|
bucket_acl_2 = s3_gate_bucket.get_bucket_acl(self.s3_client, bucket_2)
|
2023-02-14 08:09:37 +00:00
|
|
|
assert_s3_acl(acl_grants=bucket_acl_2, permitted_users="AllUsers")
|
2022-10-04 08:22:04 +00:00
|
|
|
|
|
|
|
@allure.title("Test S3: create bucket with object lock")
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_s3_bucket_object_lock(self, simple_object_size):
|
|
|
|
file_path = generate_file(simple_object_size)
|
2022-10-04 08:22:04 +00:00
|
|
|
file_name = object_key_from_file_path(file_path)
|
|
|
|
|
|
|
|
with allure.step("Create bucket with --no-object-lock-enabled-for-bucket"):
|
|
|
|
bucket = s3_gate_bucket.create_bucket_s3(self.s3_client, False)
|
|
|
|
date_obj = datetime.utcnow() + timedelta(days=1)
|
|
|
|
with pytest.raises(
|
|
|
|
Exception, match=r".*Object Lock configuration does not exist for this bucket.*"
|
|
|
|
):
|
|
|
|
# An error occurred (ObjectLockConfigurationNotFoundError) when calling the PutObject operation (reached max retries: 0):
|
|
|
|
# Object Lock configuration does not exist for this bucket
|
|
|
|
s3_gate_object.put_object_s3(
|
|
|
|
self.s3_client,
|
|
|
|
bucket,
|
|
|
|
file_path,
|
|
|
|
ObjectLockMode="COMPLIANCE",
|
|
|
|
ObjectLockRetainUntilDate=date_obj.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
|
|
)
|
|
|
|
with allure.step("Create bucket with --object-lock-enabled-for-bucket"):
|
|
|
|
bucket_1 = s3_gate_bucket.create_bucket_s3(self.s3_client, True)
|
|
|
|
date_obj_1 = datetime.utcnow() + timedelta(days=1)
|
|
|
|
s3_gate_object.put_object_s3(
|
|
|
|
self.s3_client,
|
|
|
|
bucket_1,
|
|
|
|
file_path,
|
|
|
|
ObjectLockMode="COMPLIANCE",
|
|
|
|
ObjectLockRetainUntilDate=date_obj_1.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
|
|
ObjectLockLegalHoldStatus="ON",
|
|
|
|
)
|
2022-10-17 11:41:20 +00:00
|
|
|
assert_object_lock_mode(
|
2022-10-21 07:49:25 +00:00
|
|
|
self.s3_client, bucket_1, file_name, "COMPLIANCE", date_obj_1, "ON"
|
2022-10-04 08:22:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@allure.title("Test S3: delete bucket")
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_s3_delete_bucket(self, simple_object_size):
|
|
|
|
file_path_1 = generate_file(simple_object_size)
|
2022-10-04 08:22:04 +00:00
|
|
|
file_name_1 = object_key_from_file_path(file_path_1)
|
2022-12-07 12:38:56 +00:00
|
|
|
file_path_2 = generate_file(simple_object_size)
|
2022-10-04 08:22:04 +00:00
|
|
|
file_name_2 = object_key_from_file_path(file_path_2)
|
|
|
|
bucket = s3_gate_bucket.create_bucket_s3(self.s3_client)
|
|
|
|
|
|
|
|
with allure.step("Put two objects into bucket"):
|
|
|
|
s3_gate_object.put_object_s3(self.s3_client, bucket, file_path_1)
|
|
|
|
s3_gate_object.put_object_s3(self.s3_client, bucket, file_path_2)
|
|
|
|
check_objects_in_bucket(self.s3_client, bucket, [file_name_1, file_name_2])
|
|
|
|
|
|
|
|
with allure.step("Try to delete not empty bucket and get error"):
|
|
|
|
with pytest.raises(Exception, match=r".*The bucket you tried to delete is not empty.*"):
|
|
|
|
s3_gate_bucket.delete_bucket_s3(self.s3_client, bucket)
|
|
|
|
|
|
|
|
with allure.step("Delete object in bucket"):
|
|
|
|
s3_gate_object.delete_object_s3(self.s3_client, bucket, file_name_1)
|
|
|
|
s3_gate_object.delete_object_s3(self.s3_client, bucket, file_name_2)
|
|
|
|
check_objects_in_bucket(self.s3_client, bucket, [])
|
|
|
|
|
|
|
|
with allure.step(f"Delete empty bucket"):
|
|
|
|
s3_gate_bucket.delete_bucket_s3(self.s3_client, bucket)
|
|
|
|
with pytest.raises(Exception, match=r".*Not Found.*"):
|
|
|
|
s3_gate_bucket.head_bucket(self.s3_client, bucket)
|