2022-09-19 14:22:10 +00:00
|
|
|
import os
|
2022-12-01 08:58:05 +00:00
|
|
|
import string
|
2022-09-19 14:22:10 +00:00
|
|
|
import uuid
|
|
|
|
from datetime import datetime, timedelta
|
2022-12-01 08:58:05 +00:00
|
|
|
from random import choices, sample
|
2023-05-15 09:59:33 +00:00
|
|
|
from typing import Literal
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.resources.common import ASSETS_DIR, DEFAULT_WALLET_PASS
|
|
|
|
from frostfs_testlib.resources.error_patterns import S3_MALFORMED_XML_REQUEST
|
|
|
|
from frostfs_testlib.s3 import AwsCliClient, Boto3ClientWrapper, S3ClientWrapper, VersioningStatus
|
|
|
|
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.testing.test_control import expect_not_raises
|
2023-03-29 16:59:14 +00:00
|
|
|
from frostfs_testlib.utils import wallet_utils
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.utils.file_utils import (
|
2023-02-27 16:54:27 +00:00
|
|
|
concat_files,
|
|
|
|
generate_file,
|
|
|
|
generate_file_with_content,
|
|
|
|
get_file_hash,
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
def pytest_generate_tests(metafunc: pytest.Metafunc):
|
2022-09-19 14:22:10 +00:00
|
|
|
if "s3_client" in metafunc.fixturenames:
|
2023-05-15 09:59:33 +00:00
|
|
|
metafunc.parametrize("s3_client", [AwsCliClient, Boto3ClientWrapper], indirect=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.sanity
|
|
|
|
@pytest.mark.s3_gate
|
2022-09-19 14:22:10 +00:00
|
|
|
@pytest.mark.s3_gate_object
|
2023-05-15 09:59:33 +00:00
|
|
|
class TestS3GateObject:
|
2023-03-29 16:59:14 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def second_wallet_public_key(self):
|
|
|
|
second_wallet = os.path.join(os.getcwd(), ASSETS_DIR, f"{str(uuid.uuid4())}.json")
|
2023-05-15 09:59:33 +00:00
|
|
|
wallet_utils.init_wallet(second_wallet, DEFAULT_WALLET_PASS)
|
|
|
|
public_key = wallet_utils.get_wallet_public_key(second_wallet, DEFAULT_WALLET_PASS)
|
2023-03-29 16:59:14 +00:00
|
|
|
yield public_key
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_copy_object(
|
2023-08-02 11:54:03 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
two_buckets: tuple[str, str],
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
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-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [file_name]
|
|
|
|
|
2022-11-29 14:16:15 +00:00
|
|
|
bucket_1, bucket_2 = two_buckets
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
objects_list = s3_client.list_objects(bucket_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert not objects_list, f"Expected empty bucket, got {objects_list}"
|
|
|
|
|
|
|
|
with allure.step("Put object into one bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket_1, file_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Copy one object into the same bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket_1, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.append(copy_obj_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_1, bucket_1_objects)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
objects_list = s3_client.list_objects(bucket_2)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert not objects_list, f"Expected empty bucket, got {objects_list}"
|
|
|
|
|
|
|
|
with allure.step("Copy object from first bucket into second"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path_b2 = s3_client.copy_object(bucket_1, file_name, bucket=bucket_2)
|
|
|
|
s3_helper.check_objects_in_bucket(
|
|
|
|
s3_client, bucket_1, expected_objects=bucket_1_objects
|
|
|
|
)
|
|
|
|
s3_helper.check_objects_in_bucket(
|
|
|
|
s3_client, bucket_2, expected_objects=[copy_obj_path_b2]
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step("Check copied object has the same content"):
|
2023-05-15 09:59:33 +00:00
|
|
|
got_copied_file_b2 = s3_client.get_object(bucket_2, copy_obj_path_b2)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert get_file_hash(file_path) == get_file_hash(
|
|
|
|
got_copied_file_b2
|
|
|
|
), "Hashes must be the same"
|
|
|
|
|
|
|
|
with allure.step("Delete one object from first bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_object(bucket_1, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.remove(file_name)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(
|
|
|
|
s3_client, bucket_1, expected_objects=bucket_1_objects
|
|
|
|
)
|
|
|
|
s3_helper.check_objects_in_bucket(
|
|
|
|
s3_client, bucket_2, expected_objects=[copy_obj_path_b2]
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Copy one object into the same bucket"):
|
|
|
|
with pytest.raises(Exception):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.copy_object(bucket_1, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy version of object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_copy_version_object(
|
2023-08-02 11:54:03 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
two_buckets: tuple[str, str],
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
version_1_content = "Version 1"
|
2023-08-02 11:54:03 +00:00
|
|
|
file_name_simple = generate_file_with_content(
|
|
|
|
simple_object_size.value, content=version_1_content
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
obj_key = os.path.basename(file_name_simple)
|
|
|
|
|
2022-11-29 14:16:15 +00:00
|
|
|
bucket_1, bucket_2 = two_buckets
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket_1, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket_1, file_name_simple)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [obj_key]
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_1, [obj_key])
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Copy one object into the same bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket_1, obj_key)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.append(copy_obj_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket_1, bucket_1_objects)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket_2, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
with allure.step("Copy object from first bucket into second"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path_b2 = s3_client.copy_object(bucket_1, obj_key, bucket=bucket_2)
|
|
|
|
s3_helper.check_objects_in_bucket(
|
|
|
|
s3_client, bucket_1, expected_objects=bucket_1_objects
|
|
|
|
)
|
|
|
|
s3_helper.check_objects_in_bucket(
|
|
|
|
s3_client, bucket_2, expected_objects=[copy_obj_path_b2]
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step("Delete one object from first bucket and check object in bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_object(bucket_1, obj_key)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.remove(obj_key)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(
|
|
|
|
s3_client, bucket_1, expected_objects=bucket_1_objects
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Copy one object into the same bucket"):
|
|
|
|
with pytest.raises(Exception):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.copy_object(bucket_1, obj_key)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy with acl (s3_client={s3_client})")
|
2023-08-02 11:54:03 +00:00
|
|
|
def test_s3_copy_acl(
|
|
|
|
self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize
|
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
version_1_content = "Version 1"
|
2023-08-02 11:54:03 +00:00
|
|
|
file_name_simple = generate_file_with_content(
|
|
|
|
simple_object_size.value, content=version_1_content
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
obj_key = os.path.basename(file_name_simple)
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_name_simple)
|
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, [obj_key])
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Copy object and check acl attribute"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket, obj_key, acl="public-read-write")
|
|
|
|
obj_acl = s3_client.get_object_acl(bucket, copy_obj_path)
|
|
|
|
s3_helper.assert_s3_acl(acl_grants=obj_acl, permitted_users="CanonicalUser")
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy object with metadata (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_copy_metadate(
|
2023-08-02 11:54:03 +00:00
|
|
|
self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
object_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
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-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [file_name]
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path, metadata=object_metadata)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [file_name]
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, bucket_1_objects)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Copy one object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.append(copy_obj_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, bucket_1_objects)
|
|
|
|
obj_head = s3_client.head_object(bucket, copy_obj_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
obj_head.get("Metadata") == object_metadata
|
|
|
|
), f"Metadata must be {object_metadata}"
|
|
|
|
|
|
|
|
with allure.step("Copy one object with metadata"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket, file_name, metadata_directive="COPY")
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects.append(copy_obj_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_head = s3_client.head_object(bucket, copy_obj_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
obj_head.get("Metadata") == object_metadata
|
|
|
|
), f"Metadata must be {object_metadata}"
|
|
|
|
|
|
|
|
with allure.step("Copy one object with new metadata"):
|
|
|
|
object_metadata_1 = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(
|
2022-11-29 14:16:15 +00:00
|
|
|
bucket,
|
2022-09-19 14:22:10 +00:00
|
|
|
file_name,
|
|
|
|
metadata_directive="REPLACE",
|
|
|
|
metadata=object_metadata_1,
|
|
|
|
)
|
|
|
|
bucket_1_objects.append(copy_obj_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_head = s3_client.head_object(bucket, copy_obj_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
obj_head.get("Metadata") == object_metadata_1
|
|
|
|
), f"Metadata must be {object_metadata_1}"
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy object with tagging (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_copy_tagging(
|
2023-08-02 11:54:03 +00:00
|
|
|
self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
object_tagging = [(f"{uuid.uuid4()}", f"{uuid.uuid4()}")]
|
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_simple = s3_helper.object_key_from_file_path(file_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [file_name_simple]
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path)
|
|
|
|
s3_client.put_object_tagging(bucket, file_name_simple, tags=object_tagging)
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket_1_objects = [file_name_simple]
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, bucket_1_objects)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Copy one object without tag"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(bucket, file_name_simple)
|
|
|
|
got_tags = s3_client.get_object_tagging(bucket, copy_obj_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags, f"Expected tags, got {got_tags}"
|
|
|
|
expected_tags = [{"Key": key, "Value": value} for key, value in object_tagging]
|
|
|
|
for tag in expected_tags:
|
|
|
|
assert tag in got_tags, f"Expected tag {tag} in {got_tags}"
|
|
|
|
|
|
|
|
with allure.step("Copy one object with tag"):
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path_1 = s3_client.copy_object(
|
|
|
|
bucket, file_name_simple, tagging_directive="COPY"
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags = s3_client.get_object_tagging(bucket, copy_obj_path_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags, f"Expected tags, got {got_tags}"
|
|
|
|
expected_tags = [{"Key": key, "Value": value} for key, value in object_tagging]
|
|
|
|
for tag in expected_tags:
|
|
|
|
assert tag in got_tags, f"Expected tag {tag} in {got_tags}"
|
|
|
|
|
|
|
|
with allure.step("Copy one object with new tag"):
|
|
|
|
tag_key = "tag1"
|
|
|
|
tag_value = uuid.uuid4()
|
|
|
|
new_tag = f"{tag_key}={tag_value}"
|
2023-05-15 09:59:33 +00:00
|
|
|
copy_obj_path = s3_client.copy_object(
|
2022-11-29 14:16:15 +00:00
|
|
|
bucket,
|
2022-09-19 14:22:10 +00:00
|
|
|
file_name_simple,
|
|
|
|
tagging_directive="REPLACE",
|
|
|
|
tagging=new_tag,
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags = s3_client.get_object_tagging(bucket, copy_obj_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags, f"Expected tags, got {got_tags}"
|
|
|
|
expected_tags = [{"Key": tag_key, "Value": str(tag_value)}]
|
|
|
|
for tag in expected_tags:
|
|
|
|
assert tag in got_tags, f"Expected tag {tag} in {got_tags}"
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Delete version of object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_delete_versioning(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size: ObjectSize,
|
|
|
|
complex_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
version_1_content = "Version 1"
|
|
|
|
version_2_content = "Version 2"
|
2023-08-02 11:54:03 +00:00
|
|
|
file_name_simple = generate_file_with_content(
|
|
|
|
simple_object_size.value, content=version_1_content
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
obj_key = os.path.basename(file_name_simple)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_name_simple)
|
2022-10-11 15:15:50 +00:00
|
|
|
file_name_1 = generate_file_with_content(
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size.value, file_path=file_name_simple, content=version_2_content
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_name_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Check bucket shows all versions"):
|
2023-05-15 09:59:33 +00:00
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2022-09-19 14:22:10 +00:00
|
|
|
obj_versions = {
|
|
|
|
version.get("VersionId") for version in versions if version.get("Key") == obj_key
|
|
|
|
}
|
|
|
|
assert obj_versions == {
|
|
|
|
version_id_1,
|
|
|
|
version_id_2,
|
2023-03-29 16:59:14 +00:00
|
|
|
}, f"Object should have versions: {version_id_1, version_id_2}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Delete 1 version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_obj = s3_client.delete_object(bucket, obj_key, version_id=version_id_1)
|
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2022-09-19 14:22:10 +00:00
|
|
|
obj_versions = {
|
|
|
|
version.get("VersionId") for version in versions if version.get("Key") == obj_key
|
|
|
|
}
|
2023-03-29 16:59:14 +00:00
|
|
|
assert obj_versions == {version_id_2}, f"Object should have versions: {version_id_2}"
|
2023-05-24 14:20:25 +00:00
|
|
|
assert "DeleteMarker" not in delete_obj.keys(), "Delete markers should not be created"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Delete second version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_obj = s3_client.delete_object(bucket, obj_key, version_id=version_id_2)
|
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2022-09-19 14:22:10 +00:00
|
|
|
obj_versions = {
|
|
|
|
version.get("VersionId") for version in versions if version.get("Key") == obj_key
|
|
|
|
}
|
|
|
|
assert not obj_versions, "Expected object not found"
|
2023-05-24 14:20:25 +00:00
|
|
|
assert "DeleteMarker" not in delete_obj.keys(), "Delete markers should not be created"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put new object into bucket"):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_name_simple = generate_file(complex_object_size.value)
|
2022-09-19 14:22:10 +00:00
|
|
|
obj_key = os.path.basename(file_name_simple)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_name_simple)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Delete last object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_obj = s3_client.delete_object(bucket, obj_key)
|
|
|
|
versions = s3_client.list_objects_versions(bucket, True)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert versions.get("DeleteMarkers", None), "Expected delete Marker"
|
|
|
|
assert "DeleteMarker" in delete_obj.keys(), "Expected delete Marker"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Bulk delete version of object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_bulk_delete_versioning(
|
2023-08-02 11:54:03 +00:00
|
|
|
self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
version_1_content = "Version 1"
|
|
|
|
version_2_content = "Version 2"
|
|
|
|
version_3_content = "Version 3"
|
|
|
|
version_4_content = "Version 4"
|
2023-08-02 11:54:03 +00:00
|
|
|
file_name_1 = generate_file_with_content(
|
|
|
|
simple_object_size.value, content=version_1_content
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
obj_key = os.path.basename(file_name_1)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_name_1)
|
2022-10-11 15:15:50 +00:00
|
|
|
file_name_2 = generate_file_with_content(
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size.value, file_path=file_name_1, content=version_2_content
|
2022-10-11 15:15:50 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_name_2)
|
2022-10-11 15:15:50 +00:00
|
|
|
file_name_3 = generate_file_with_content(
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size.value, file_path=file_name_1, content=version_3_content
|
2022-10-11 15:15:50 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_3 = s3_client.put_object(bucket, file_name_3)
|
2022-10-11 15:15:50 +00:00
|
|
|
file_name_4 = generate_file_with_content(
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size.value, file_path=file_name_1, content=version_4_content
|
2022-10-11 15:15:50 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_4 = s3_client.put_object(bucket, file_name_4)
|
2022-09-19 14:22:10 +00:00
|
|
|
version_ids = {version_id_1, version_id_2, version_id_3, version_id_4}
|
|
|
|
|
|
|
|
with allure.step("Check bucket shows all versions"):
|
2023-05-15 09:59:33 +00:00
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2022-09-19 14:22:10 +00:00
|
|
|
obj_versions = {
|
|
|
|
version.get("VersionId") for version in versions if version.get("Key") == obj_key
|
|
|
|
}
|
2023-03-29 16:59:14 +00:00
|
|
|
assert obj_versions == version_ids, f"Object should have versions: {version_ids}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Delete two objects from bucket one by one"):
|
|
|
|
version_to_delete_b1 = sample(
|
|
|
|
[version_id_1, version_id_2, version_id_3, version_id_4], k=2
|
|
|
|
)
|
|
|
|
version_to_save = list(set(version_ids) - set(version_to_delete_b1))
|
|
|
|
for ver in version_to_delete_b1:
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_object(bucket, obj_key, ver)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Check bucket shows all versions"):
|
2023-05-15 09:59:33 +00:00
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2022-09-19 14:22:10 +00:00
|
|
|
obj_versions = [
|
|
|
|
version.get("VersionId") for version in versions if version.get("Key") == obj_key
|
|
|
|
]
|
|
|
|
assert (
|
|
|
|
obj_versions.sort() == version_to_save.sort()
|
2023-03-29 16:59:14 +00:00
|
|
|
), f"Object should have versions: {version_to_save}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Get versions of object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_get_versioning(
|
2023-08-02 11:54:03 +00:00
|
|
|
self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
version_1_content = "Version 1"
|
|
|
|
version_2_content = "Version 2"
|
2023-08-02 11:54:03 +00:00
|
|
|
file_name_simple = generate_file_with_content(
|
|
|
|
simple_object_size.value, content=version_1_content
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
obj_key = os.path.basename(file_name_simple)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
with allure.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_name_simple)
|
2022-10-11 15:15:50 +00:00
|
|
|
file_name_1 = generate_file_with_content(
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size.value, file_path=file_name_simple, content=version_2_content
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_name_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Get first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_1 = s3_client.get_object(bucket, obj_key, version_id_1, full_output=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
object_1.get("VersionId") == version_id_1
|
|
|
|
), f"Get object with version {version_id_1}"
|
|
|
|
|
|
|
|
with allure.step("Get second version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_2 = s3_client.get_object(bucket, obj_key, version_id_2, full_output=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
object_2.get("VersionId") == version_id_2
|
|
|
|
), f"Get object with version {version_id_2}"
|
|
|
|
|
|
|
|
with allure.step("Get object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3 = s3_client.get_object(bucket, obj_key, full_output=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
object_3.get("VersionId") == version_id_2
|
|
|
|
), f"Get object with version {version_id_2}"
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Get range (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_get_range(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
2022-09-19 14:22:10 +00:00
|
|
|
file_hash = get_file_hash(file_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
with allure.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_path)
|
2023-08-02 11:54:03 +00:00
|
|
|
file_name_1 = generate_file_with_content(simple_object_size.value, file_path=file_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_name_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Get first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_1_part_1 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_1,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[0, int(complex_object_size.value / 3)],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_1_part_2 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_1,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[
|
|
|
|
int(complex_object_size.value / 3) + 1,
|
|
|
|
2 * int(complex_object_size.value / 3),
|
|
|
|
],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_1_part_3 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_1,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[
|
|
|
|
2 * int(complex_object_size.value / 3) + 1,
|
|
|
|
complex_object_size.value,
|
|
|
|
],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
con_file = concat_files([object_1_part_1, object_1_part_2, object_1_part_3])
|
|
|
|
assert get_file_hash(con_file) == file_hash, "Hashes must be the same"
|
|
|
|
|
|
|
|
with allure.step("Get second version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_2_part_1 = s3_client.get_object(
|
2022-12-07 12:38:56 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_2,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[0, int(simple_object_size.value / 3)],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_2_part_2 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_2,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[
|
|
|
|
int(simple_object_size.value / 3) + 1,
|
|
|
|
2 * int(simple_object_size.value / 3),
|
|
|
|
],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_2_part_3 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
|
|
|
version_id_2,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[2 * int(simple_object_size.value / 3) + 1, simple_object_size.value],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
con_file_1 = concat_files([object_2_part_1, object_2_part_2, object_2_part_3])
|
|
|
|
assert get_file_hash(con_file_1) == get_file_hash(
|
|
|
|
file_name_1
|
|
|
|
), "Hashes must be the same"
|
|
|
|
|
|
|
|
with allure.step("Get object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3_part_1 = s3_client.get_object(
|
2023-08-02 11:54:03 +00:00
|
|
|
bucket, file_name, object_range=[0, int(simple_object_size.value / 3)]
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3_part_2 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[
|
|
|
|
int(simple_object_size.value / 3) + 1,
|
|
|
|
2 * int(simple_object_size.value / 3),
|
|
|
|
],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3_part_3 = s3_client.get_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_name,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_range=[2 * int(simple_object_size.value / 3) + 1, simple_object_size.value],
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
con_file = concat_files([object_3_part_1, object_3_part_2, object_3_part_3])
|
|
|
|
assert get_file_hash(con_file) == get_file_hash(file_name_1), "Hashes must be the same"
|
|
|
|
|
2023-04-05 16:02:42 +00:00
|
|
|
def copy_extend_list(self, original_list: list[str], n: int) -> list[str]:
|
|
|
|
"""Extend the list with own elements up to n elements"""
|
|
|
|
multiplier = n // len(original_list)
|
|
|
|
result_list = original_list.copy()
|
|
|
|
result_list = result_list * multiplier
|
|
|
|
for i in range(n - len(result_list)):
|
|
|
|
result_list.append(result_list[i])
|
|
|
|
|
|
|
|
return result_list
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Bulk deletion is limited to 1000 objects (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_bulk_deletion_limit(
|
2023-09-08 10:35:34 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2023-09-08 10:35:34 +00:00
|
|
|
objects_in_bucket = []
|
|
|
|
objects_count = 3
|
|
|
|
|
|
|
|
with allure.step(f"Put {objects_count} into bucket"):
|
|
|
|
for _ in range(objects_count):
|
|
|
|
file_path = generate_file(simple_object_size.value)
|
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
|
|
|
objects_in_bucket.append(file_name)
|
|
|
|
s3_client.put_object(bucket, file_path)
|
|
|
|
|
2023-04-05 16:02:42 +00:00
|
|
|
# Extend deletion list to 1001 elements with same keys for test speed
|
|
|
|
objects_to_delete = self.copy_extend_list(objects_in_bucket, 1001)
|
2023-09-08 10:35:34 +00:00
|
|
|
with allure.step("Send delete request with 1001 objects and expect error"):
|
2023-04-05 16:02:42 +00:00
|
|
|
with pytest.raises(Exception, match=S3_MALFORMED_XML_REQUEST):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_objects(bucket, objects_to_delete)
|
2023-04-05 16:02:42 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
with allure.step("Send delete request with 1000 objects without error"):
|
2023-04-05 16:02:42 +00:00
|
|
|
with expect_not_raises():
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.delete_objects(bucket, objects_to_delete[:1000])
|
2023-04-05 16:02:42 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Copy object with metadata (s3_client={s3_client})")
|
2022-11-10 05:27:52 +00:00
|
|
|
@pytest.mark.smoke
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_head_object(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
object_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path)
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put several versions of object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(bucket, file_path, metadata=object_metadata)
|
2023-08-02 11:54:03 +00:00
|
|
|
file_name_1 = generate_file_with_content(simple_object_size.value, file_path=file_path)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_name_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Get head of first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
response = s3_client.head_object(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert "LastModified" in response, "Expected LastModified field"
|
|
|
|
assert "ETag" in response, "Expected ETag field"
|
|
|
|
assert response.get("Metadata") == {}, "Expected Metadata empty"
|
|
|
|
assert (
|
|
|
|
response.get("VersionId") == version_id_2
|
|
|
|
), f"Expected VersionId is {version_id_2}"
|
|
|
|
assert response.get("ContentLength") != 0, "Expected ContentLength is not zero"
|
|
|
|
|
|
|
|
with allure.step("Get head ob first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
response = s3_client.head_object(bucket, file_name, version_id=version_id_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert "LastModified" in response, "Expected LastModified field"
|
|
|
|
assert "ETag" in response, "Expected ETag field"
|
|
|
|
assert (
|
|
|
|
response.get("Metadata") == object_metadata
|
|
|
|
), f"Expected Metadata is {object_metadata}"
|
|
|
|
assert (
|
|
|
|
response.get("VersionId") == version_id_1
|
|
|
|
), f"Expected VersionId is {version_id_1}"
|
|
|
|
assert response.get("ContentLength") != 0, "Expected ContentLength is not zero"
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title(
|
|
|
|
"List of objects with version (method_version={list_type}, s3_client={s3_client})"
|
|
|
|
)
|
2022-09-19 14:22:10 +00:00
|
|
|
@pytest.mark.parametrize("list_type", ["v1", "v2"])
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_list_object(
|
2023-08-02 11:54:03 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
list_type: str,
|
|
|
|
bucket: str,
|
|
|
|
complex_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_1 = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path_1)
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_2 = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name_2 = s3_helper.object_key_from_file_path(file_path_2)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
with allure.step("Put several versions of object 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)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Get list of object"):
|
|
|
|
if list_type == "v1":
|
2023-05-15 09:59:33 +00:00
|
|
|
list_obj = s3_client.list_objects(bucket)
|
2022-09-19 14:22:10 +00:00
|
|
|
elif list_type == "v2":
|
2023-05-15 09:59:33 +00:00
|
|
|
list_obj = s3_client.list_objects_v2(bucket)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert len(list_obj) == 2, "bucket should have 2 objects"
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
list_obj.sort() == [file_name, file_name_2].sort()
|
2023-03-29 16:59:14 +00:00
|
|
|
), f"bucket should have object key {file_name, file_name_2}"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Delete object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_obj = s3_client.delete_object(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
if list_type == "v1":
|
2023-05-15 09:59:33 +00:00
|
|
|
list_obj_1 = s3_client.list_objects(bucket, full_output=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
elif list_type == "v2":
|
2023-05-15 09:59:33 +00:00
|
|
|
list_obj_1 = s3_client.list_objects_v2(bucket, full_output=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
contents = list_obj_1.get("Contents", [])
|
2023-03-29 16:59:14 +00:00
|
|
|
assert len(contents) == 1, "bucket should have only 1 object"
|
|
|
|
assert (
|
|
|
|
contents[0].get("Key") == file_name_2
|
|
|
|
), f"bucket should have object key {file_name_2}"
|
|
|
|
assert "DeleteMarker" in delete_obj.keys(), "Expected delete Marker"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Put object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_put_object(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_1 = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
object_1_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
|
|
|
tag_key_1 = "tag1"
|
|
|
|
tag_value_1 = uuid.uuid4()
|
|
|
|
tag_1 = f"{tag_key_1}={tag_value_1}"
|
|
|
|
object_2_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
|
|
|
tag_key_2 = "tag2"
|
|
|
|
tag_value_2 = uuid.uuid4()
|
|
|
|
tag_2 = f"{tag_key_2}={tag_value_2}"
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.SUSPENDED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put first object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_1, metadata=object_1_metadata, tagging=tag_1)
|
|
|
|
obj_head = s3_client.head_object(bucket, file_name)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert obj_head.get("Metadata") == object_1_metadata, "Metadata must be the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags = s3_client.get_object_tagging(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags, f"Expected tags, got {got_tags}"
|
|
|
|
assert got_tags == [
|
|
|
|
{"Key": tag_key_1, "Value": str(tag_value_1)}
|
|
|
|
], "Tags must be the same"
|
|
|
|
|
|
|
|
with allure.step("Rewrite file into bucket"):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_2 = generate_file_with_content(
|
|
|
|
simple_object_size.value, file_path=file_path_1
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_2, metadata=object_2_metadata, tagging=tag_2)
|
|
|
|
obj_head = s3_client.head_object(bucket, file_name)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert obj_head.get("Metadata") == object_2_metadata, "Metadata must be the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags_1 = s3_client.get_object_tagging(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags_1, f"Expected tags, got {got_tags_1}"
|
|
|
|
assert got_tags_1 == [
|
|
|
|
{"Key": tag_key_2, "Value": str(tag_value_2)}
|
|
|
|
], "Tags must be the same"
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_3 = generate_file(complex_object_size.value)
|
2022-09-19 14:22:10 +00:00
|
|
|
file_hash = get_file_hash(file_path_3)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name_3 = s3_helper.object_key_from_file_path(file_path_3)
|
2022-09-19 14:22:10 +00:00
|
|
|
object_3_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
|
|
|
tag_key_3 = "tag3"
|
|
|
|
tag_value_3 = uuid.uuid4()
|
|
|
|
tag_3 = f"{tag_key_3}={tag_value_3}"
|
|
|
|
|
|
|
|
with allure.step("Put third object into bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_1 = s3_client.put_object(
|
|
|
|
bucket, file_path_3, metadata=object_3_metadata, tagging=tag_3
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_head_3 = s3_client.head_object(bucket, file_name_3)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert obj_head_3.get("Metadata") == object_3_metadata, "Matadata must be the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags_3 = s3_client.get_object_tagging(bucket, file_name_3)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags_3, f"Expected tags, got {got_tags_3}"
|
|
|
|
assert got_tags_3 == [
|
|
|
|
{"Key": tag_key_3, "Value": str(tag_value_3)}
|
|
|
|
], "Tags must be the same"
|
|
|
|
|
|
|
|
with allure.step("Put new version of file into bucket"):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_4 = generate_file_with_content(
|
|
|
|
simple_object_size.value, file_path=file_path_3
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
version_id_2 = s3_client.put_object(bucket, file_path_4)
|
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2022-09-19 14:22:10 +00:00
|
|
|
obj_versions = {
|
|
|
|
version.get("VersionId")
|
|
|
|
for version in versions
|
|
|
|
if version.get("Key") == file_name_3
|
|
|
|
}
|
|
|
|
assert obj_versions == {
|
|
|
|
version_id_1,
|
|
|
|
version_id_2,
|
2023-03-29 16:59:14 +00:00
|
|
|
}, f"Object should have versions: {version_id_1, version_id_2}"
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags_4 = s3_client.get_object_tagging(bucket, file_name_3)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert not got_tags_4, "No tags expected"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Get object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3 = s3_client.get_object(bucket, file_name_3, full_output=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
object_3.get("VersionId") == version_id_2
|
|
|
|
), f"get object with version {version_id_2}"
|
2023-05-15 09:59:33 +00:00
|
|
|
object_3 = s3_client.get_object(bucket, file_name_3)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert get_file_hash(file_path_4) == get_file_hash(object_3), "Hashes must be the same"
|
|
|
|
|
|
|
|
with allure.step("Get first version of object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
object_4 = s3_client.get_object(bucket, file_name_3, version_id_1, full_output=True)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
object_4.get("VersionId") == version_id_1
|
|
|
|
), f"get object with version {version_id_1}"
|
2023-05-15 09:59:33 +00:00
|
|
|
object_4 = s3_client.get_object(bucket, file_name_3, version_id_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert file_hash == get_file_hash(object_4), "Hashes must be the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_head_3 = s3_client.head_object(bucket, file_name_3, version_id_1)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert obj_head_3.get("Metadata") == object_3_metadata, "Metadata must be the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
got_tags_3 = s3_client.get_object_tagging(bucket, file_name_3, version_id_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert got_tags_3, f"Expected tags, got {got_tags_3}"
|
|
|
|
assert got_tags_3 == [
|
|
|
|
{"Key": tag_key_3, "Value": str(tag_value_3)}
|
|
|
|
], "Tags must be the same"
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Put object with ACL (versioning={bucket_versioning}, s3_client={s3_client})")
|
2022-09-19 14:22:10 +00:00
|
|
|
@pytest.mark.parametrize("bucket_versioning", ["ENABLED", "SUSPENDED"])
|
2022-12-07 12:38:56 +00:00
|
|
|
def test_s3_put_object_acl(
|
|
|
|
self,
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket_versioning: Literal["ENABLED", "SUSPENDED"],
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
second_wallet_public_key: str,
|
2022-12-07 12:38:56 +00:00
|
|
|
):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_1 = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path_1)
|
2022-09-19 14:22:10 +00:00
|
|
|
if bucket_versioning == "ENABLED":
|
2023-05-15 09:59:33 +00:00
|
|
|
status = VersioningStatus.ENABLED
|
2022-09-19 14:22:10 +00:00
|
|
|
elif bucket_versioning == "SUSPENDED":
|
2023-05-15 09:59:33 +00:00
|
|
|
status = VersioningStatus.SUSPENDED
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, status)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put object with acl private"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_1, acl="private")
|
|
|
|
obj_acl = s3_client.get_object_acl(bucket, file_name)
|
|
|
|
s3_helper.assert_s3_acl(acl_grants=obj_acl, permitted_users="CanonicalUser")
|
|
|
|
object_1 = s3_client.get_object(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert get_file_hash(file_path_1) == get_file_hash(object_1), "Hashes must be the same"
|
|
|
|
|
|
|
|
with allure.step("Put object with acl public-read"):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_2 = generate_file_with_content(
|
|
|
|
simple_object_size.value, file_path=file_path_1
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_2, acl="public-read")
|
|
|
|
obj_acl = s3_client.get_object_acl(bucket, file_name)
|
|
|
|
s3_helper.assert_s3_acl(acl_grants=obj_acl, permitted_users="AllUsers")
|
|
|
|
object_2 = s3_client.get_object(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert get_file_hash(file_path_2) == get_file_hash(object_2), "Hashes must be the same"
|
|
|
|
|
|
|
|
with allure.step("Put object with acl public-read-write"):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_3 = generate_file_with_content(
|
|
|
|
simple_object_size.value, file_path=file_path_1
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_3, acl="public-read-write")
|
|
|
|
obj_acl = s3_client.get_object_acl(bucket, file_name)
|
|
|
|
s3_helper.assert_s3_acl(acl_grants=obj_acl, permitted_users="AllUsers")
|
|
|
|
object_3 = s3_client.get_object(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert get_file_hash(file_path_3) == get_file_hash(object_3), "Hashes must be the same"
|
|
|
|
|
|
|
|
with allure.step("Put object with acl authenticated-read"):
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_4 = generate_file_with_content(
|
|
|
|
simple_object_size.value, file_path=file_path_1
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_4, acl="authenticated-read")
|
|
|
|
obj_acl = s3_client.get_object_acl(bucket, file_name)
|
|
|
|
s3_helper.assert_s3_acl(acl_grants=obj_acl, permitted_users="AllUsers")
|
|
|
|
object_4 = s3_client.get_object(bucket, file_name)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert get_file_hash(file_path_4) == get_file_hash(object_4), "Hashes must be the same"
|
|
|
|
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_5 = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name_5 = s3_helper.object_key_from_file_path(file_path_5)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step("Put object with --grant-full-control id=mycanonicaluserid"):
|
2023-08-02 11:54:03 +00:00
|
|
|
generate_file_with_content(simple_object_size.value, file_path=file_path_5)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
2023-03-29 16:59:14 +00:00
|
|
|
file_path_5,
|
2023-05-15 09:59:33 +00:00
|
|
|
grant_full_control=f"id={second_wallet_public_key}",
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_acl = s3_client.get_object_acl(bucket, file_name_5)
|
|
|
|
s3_helper.assert_s3_acl(acl_grants=obj_acl, permitted_users="CanonicalUser")
|
|
|
|
object_5 = s3_client.get_object(bucket, file_name_5)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert get_file_hash(file_path_5) == get_file_hash(object_5), "Hashes must be the same"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step(
|
|
|
|
"Put object with --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers"
|
|
|
|
):
|
2023-08-02 11:54:03 +00:00
|
|
|
generate_file_with_content(simple_object_size.value, file_path=file_path_5)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
2023-03-29 16:59:14 +00:00
|
|
|
file_path_5,
|
2023-05-15 09:59:33 +00:00
|
|
|
grant_read="uri=http://acs.amazonaws.com/groups/global/AllUsers",
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_acl = s3_client.get_object_acl(bucket, file_name_5)
|
|
|
|
s3_helper.assert_s3_acl(acl_grants=obj_acl, permitted_users="AllUsers")
|
|
|
|
object_6 = s3_client.get_object(bucket, file_name_5)
|
2023-03-29 16:59:14 +00:00
|
|
|
assert get_file_hash(file_path_5) == get_file_hash(object_6), "Hashes must be the same"
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Put object with lock-mode (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_put_object_lock_mode(
|
2023-08-02 11:54:03 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
complex_object_size: ObjectSize,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-09-19 14:22:10 +00:00
|
|
|
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path_1 = generate_file(complex_object_size.value)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path_1)
|
|
|
|
bucket = s3_client.create_bucket(object_lock_enabled_for_bucket=True)
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-09-19 14:22:10 +00:00
|
|
|
|
|
|
|
with allure.step(
|
|
|
|
"Put object with lock-mode GOVERNANCE lock-retain-until-date +1day, lock-legal-hold-status"
|
|
|
|
):
|
|
|
|
date_obj = datetime.utcnow() + timedelta(days=1)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_path_1,
|
2023-05-15 09:59:33 +00:00
|
|
|
object_lock_mode="GOVERNANCE",
|
|
|
|
object_lock_retain_until_date=date_obj.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
|
|
object_lock_legal_hold_status="OFF",
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.assert_object_lock_mode(
|
|
|
|
s3_client, bucket, file_name, "GOVERNANCE", date_obj, "OFF"
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step(
|
|
|
|
"Put new version of object with [--object-lock-mode COMPLIANCE] и [--object-lock-retain-until-date +3days]"
|
|
|
|
):
|
|
|
|
date_obj = datetime.utcnow() + timedelta(days=2)
|
2023-08-02 11:54:03 +00:00
|
|
|
generate_file_with_content(simple_object_size.value, file_path=file_path_1)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_path_1,
|
2023-05-15 09:59:33 +00:00
|
|
|
object_lock_mode="COMPLIANCE",
|
|
|
|
object_lock_retain_until_date=date_obj,
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.assert_object_lock_mode(
|
|
|
|
s3_client, bucket, file_name, "COMPLIANCE", date_obj, "OFF"
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step(
|
|
|
|
"Put new version of object with [--object-lock-mode COMPLIANCE] и [--object-lock-retain-until-date +2days]"
|
|
|
|
):
|
|
|
|
date_obj = datetime.utcnow() + timedelta(days=3)
|
2023-08-02 11:54:03 +00:00
|
|
|
generate_file_with_content(simple_object_size.value, file_path=file_path_1)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-09-19 14:22:10 +00:00
|
|
|
bucket,
|
|
|
|
file_path_1,
|
2023-05-15 09:59:33 +00:00
|
|
|
object_lock_mode="COMPLIANCE",
|
|
|
|
object_lock_retain_until_date=date_obj,
|
|
|
|
object_lock_legal_hold_status="ON",
|
|
|
|
)
|
|
|
|
s3_helper.assert_object_lock_mode(
|
|
|
|
s3_client, bucket, file_name, "COMPLIANCE", date_obj, "ON"
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
|
2022-10-03 13:03:55 +00:00
|
|
|
with allure.step("Put object with lock-mode"):
|
|
|
|
with pytest.raises(
|
|
|
|
Exception,
|
2022-10-11 08:18:08 +00:00
|
|
|
match=r".*must both be supplied*",
|
2022-10-03 13:03:55 +00:00
|
|
|
):
|
2022-10-11 08:18:08 +00:00
|
|
|
# x-amz-object-lock-retain-until-date and x-amz-object-lock-mode must both be supplied
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_1, object_lock_mode="COMPLIANCE")
|
2022-10-03 13:03:55 +00:00
|
|
|
|
2022-10-11 08:18:08 +00:00
|
|
|
with allure.step("Put object with lock-mode and past date"):
|
|
|
|
date_obj = datetime.utcnow() - timedelta(days=3)
|
|
|
|
with pytest.raises(
|
|
|
|
Exception,
|
|
|
|
match=r".*until date must be in the future*",
|
|
|
|
):
|
|
|
|
# The retain until date must be in the future
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(
|
2022-10-11 08:18:08 +00:00
|
|
|
bucket,
|
|
|
|
file_path_1,
|
2023-05-15 09:59:33 +00:00
|
|
|
object_lock_mode="COMPLIANCE",
|
|
|
|
object_lock_retain_until_date=date_obj,
|
2022-10-11 08:18:08 +00:00
|
|
|
)
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Sync directory (sync_type={sync_type}, s3_client={s3_client})")
|
2022-09-19 14:22:10 +00:00
|
|
|
@pytest.mark.parametrize("sync_type", ["sync", "cp"])
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_sync_dir(
|
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
sync_type: Literal["sync", "cp"],
|
|
|
|
bucket: str,
|
2023-08-02 11:54:03 +00:00
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-10-18 07:11:57 +00:00
|
|
|
file_path_1 = os.path.join(os.getcwd(), ASSETS_DIR, "test_sync", "test_file_1")
|
|
|
|
file_path_2 = os.path.join(os.getcwd(), ASSETS_DIR, "test_sync", "test_file_2")
|
2022-09-19 14:22:10 +00:00
|
|
|
object_metadata = {f"{uuid.uuid4()}": f"{uuid.uuid4()}"}
|
|
|
|
key_to_path = {"test_file_1": file_path_1, "test_file_2": file_path_2}
|
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
if not isinstance(s3_client, AwsCliClient):
|
2022-09-19 14:22:10 +00:00
|
|
|
pytest.skip("This test is not supported with boto3 client")
|
|
|
|
|
2023-08-02 11:54:03 +00:00
|
|
|
generate_file_with_content(simple_object_size.value, file_path=file_path_1)
|
|
|
|
generate_file_with_content(simple_object_size.value, file_path=file_path_2)
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2022-10-13 16:42:33 +00:00
|
|
|
# TODO: return ACL, when https://github.com/nspcc-dev/neofs-s3-gw/issues/685 will be closed
|
2022-09-19 14:22:10 +00:00
|
|
|
if sync_type == "sync":
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.sync(
|
|
|
|
bucket=bucket,
|
2022-09-19 14:22:10 +00:00
|
|
|
dir_path=os.path.dirname(file_path_1),
|
2023-05-15 09:59:33 +00:00
|
|
|
# acl="public-read-write",
|
|
|
|
metadata=object_metadata,
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
elif sync_type == "cp":
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.cp(
|
|
|
|
bucket=bucket,
|
2022-09-19 14:22:10 +00:00
|
|
|
dir_path=os.path.dirname(file_path_1),
|
2023-05-15 09:59:33 +00:00
|
|
|
# acl="public-read-write",
|
|
|
|
metadata=object_metadata,
|
2022-09-19 14:22:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step("Check objects are synced"):
|
2023-05-15 09:59:33 +00:00
|
|
|
objects = s3_client.list_objects(bucket)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert set(key_to_path.keys()) == set(
|
|
|
|
objects
|
|
|
|
), f"Expected all abjects saved. Got {objects}"
|
|
|
|
|
|
|
|
with allure.step("Check these are the same objects"):
|
|
|
|
for obj_key in objects:
|
2023-05-15 09:59:33 +00:00
|
|
|
got_object = s3_client.get_object(bucket, obj_key)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert get_file_hash(got_object) == get_file_hash(
|
|
|
|
key_to_path.get(obj_key)
|
|
|
|
), "Expected hashes are the same"
|
2023-05-15 09:59:33 +00:00
|
|
|
obj_head = s3_client.head_object(bucket, obj_key)
|
2022-09-19 14:22:10 +00:00
|
|
|
assert (
|
|
|
|
obj_head.get("Metadata") == object_metadata
|
|
|
|
), f"Metadata of object is {object_metadata}"
|
2023-02-14 08:09:37 +00:00
|
|
|
# Uncomment after https://github.com/nspcc-dev/neofs-s3-gw/issues/685 is solved
|
2023-05-15 17:20:27 +00:00
|
|
|
# obj_acl = s3_client.get_object_acl(bucket, obj_key)
|
2023-05-15 09:59:33 +00:00
|
|
|
# s3_helper.assert_s3_acl(acl_grants = obj_acl, permitted_users = "AllUsers")
|
2022-12-01 08:58:05 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Put 10 nested level object (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_put_10_folder(
|
2023-08-02 11:54:03 +00:00
|
|
|
self,
|
|
|
|
s3_client: S3ClientWrapper,
|
|
|
|
bucket: str,
|
|
|
|
temp_directory,
|
|
|
|
simple_object_size: ObjectSize,
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
2022-12-01 08:58:05 +00:00
|
|
|
path = "/".join(["".join(choices(string.ascii_letters, k=3)) for _ in range(10)])
|
2022-12-05 22:31:45 +00:00
|
|
|
file_path_1 = os.path.join(temp_directory, path, "test_file_1")
|
2023-08-02 11:54:03 +00:00
|
|
|
generate_file_with_content(simple_object_size.value, file_path=file_path_1)
|
2023-05-15 09:59:33 +00:00
|
|
|
file_name = s3_helper.object_key_from_file_path(file_path_1)
|
|
|
|
objects_list = s3_client.list_objects(bucket)
|
2022-12-01 08:58:05 +00:00
|
|
|
assert not objects_list, f"Expected empty bucket, got {objects_list}"
|
|
|
|
|
|
|
|
with allure.step("Put object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path_1)
|
|
|
|
s3_helper.check_objects_in_bucket(s3_client, bucket, [file_name])
|
2023-05-04 06:52:55 +00:00
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Delete non-existing object from empty bucket (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_delete_non_existing_object(self, s3_client: S3ClientWrapper, bucket: str):
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
2023-05-15 09:59:33 +00:00
|
|
|
objects_list = s3_client.list_objects_versions(bucket)
|
2023-05-04 06:52:55 +00:00
|
|
|
with allure.step("Check that bucket is empty"):
|
|
|
|
assert not objects_list, f"Expected empty bucket, got {objects_list}"
|
|
|
|
|
|
|
|
obj_key = "fake_object_key"
|
|
|
|
|
|
|
|
with allure.step("Delete non-existing object"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_obj = s3_client.delete_object(bucket, obj_key)
|
2023-05-04 06:52:55 +00:00
|
|
|
# there should be no objects or delete markers in the bucket
|
|
|
|
assert "DeleteMarker" not in delete_obj.keys(), "Delete markers should not be created"
|
2023-05-15 09:59:33 +00:00
|
|
|
objects_list = s3_client.list_objects_versions(bucket)
|
2023-05-04 06:52:55 +00:00
|
|
|
assert not objects_list, f"Expected empty bucket, got {objects_list}"
|
|
|
|
|
2023-09-08 10:35:34 +00:00
|
|
|
@allure.title("Delete the same object twice (s3_client={s3_client})")
|
2023-05-15 09:59:33 +00:00
|
|
|
def test_s3_delete_twice(
|
2023-08-02 11:54:03 +00:00
|
|
|
self, s3_client: S3ClientWrapper, bucket: str, simple_object_size: ObjectSize
|
2023-05-15 09:59:33 +00:00
|
|
|
):
|
|
|
|
s3_helper.set_bucket_versioning(s3_client, bucket, VersioningStatus.ENABLED)
|
|
|
|
objects_list = s3_client.list_objects(bucket)
|
2023-05-04 06:52:55 +00:00
|
|
|
with allure.step("Check that bucket is empty"):
|
|
|
|
assert not objects_list, f"Expected empty bucket, got {objects_list}"
|
|
|
|
|
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)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
|
|
|
with allure.step("Put object into one bucket"):
|
2023-05-15 09:59:33 +00:00
|
|
|
s3_client.put_object(bucket, file_path)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
|
|
|
with allure.step("Delete the object from the bucket"):
|
2023-05-15 17:20:27 +00:00
|
|
|
delete_object = s3_client.delete_object(bucket, file_name)
|
|
|
|
versions = s3_client.list_objects_versions(bucket)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
|
|
|
obj_versions = {
|
|
|
|
version.get("VersionId") for version in versions if version.get("Key") == file_name
|
|
|
|
}
|
|
|
|
assert obj_versions, f"Object versions were not found {objects_list}"
|
|
|
|
assert "DeleteMarker" in delete_object.keys(), "Delete markers not found"
|
|
|
|
|
|
|
|
with allure.step("Delete the object from the bucket again"):
|
2023-05-15 09:59:33 +00:00
|
|
|
delete_object_2nd_attempt = s3_client.delete_object(bucket, file_name)
|
|
|
|
versions_2nd_attempt = s3_client.list_objects_versions(bucket)
|
2023-05-04 06:52:55 +00:00
|
|
|
|
|
|
|
assert (
|
|
|
|
delete_object.keys() == delete_object_2nd_attempt.keys()
|
|
|
|
), "Delete markers are not the same"
|
|
|
|
# check that nothing was changed
|
|
|
|
# checking here not VersionId only, but all data (for example LastModified)
|
|
|
|
assert versions == versions_2nd_attempt, "Versions are not the same"
|