Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

presigned url test updates #921

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions neofs-testlib/neofs_testlib/cli/neofs_authmate/authmate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

from neofs_testlib.cli.neofs_authmate.secret import NeofsAuthmateSecret
from neofs_testlib.cli.neofs_authmate.version import NeofsAuthmateVersion
from neofs_testlib.cli.neofs_authmate.presigned import NeofsAuthmatePresigned
from neofs_testlib.shell import Shell


class NeofsAuthmate:
secret: Optional[NeofsAuthmateSecret] = None
version: Optional[NeofsAuthmateVersion] = None
presigned: Optional[NeofsAuthmatePresigned] = None

def __init__(self, shell: Shell, neofs_authmate_exec_path: str):
self.secret = NeofsAuthmateSecret(shell, neofs_authmate_exec_path)
self.version = NeofsAuthmateVersion(shell, neofs_authmate_exec_path)
self.presigned = NeofsAuthmatePresigned(shell, neofs_authmate_exec_path)
33 changes: 0 additions & 33 deletions neofs-testlib/neofs_testlib/cli/neofs_authmate/presigned.py

This file was deleted.

5 changes: 3 additions & 2 deletions pytest_tests/lib/s3/s3_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ def list_objects_delete_markers_s3(s3_client, bucket: str, full_output: bool = F


@allure.step("Put object S3")
def put_object_s3(s3_client, bucket: str, filepath: str, **kwargs):
filename = os.path.basename(filepath)
def put_object_s3(s3_client, bucket: str, filepath: str, filename: str = "", **kwargs):
if not filename:
filename = os.path.basename(filepath)

if isinstance(s3_client, AwsCliClient):
file_content = filepath
Expand Down
74 changes: 35 additions & 39 deletions pytest_tests/tests/s3/test_s3_presigned.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import logging
import os
import shutil
Expand All @@ -9,8 +8,6 @@
import requests
from helpers.common import TEST_FILES_DIR, get_assets_dir_path
from helpers.file_helper import generate_file, get_file_hash
from helpers.s3_helper import object_key_from_file_path
from neofs_testlib.cli import NeofsAuthmate
from s3 import s3_object
from s3.s3_base import TestNeofsS3Base

Expand All @@ -19,37 +16,36 @@

def pytest_generate_tests(metafunc):
if "s3_client" in metafunc.fixturenames:
metafunc.parametrize("s3_client", ["aws cli", "boto3"], indirect=True)
metafunc.parametrize("s3_client", ["boto3"], indirect=True)


class TestS3Presigned(TestNeofsS3Base):
@allure.title("Test S3: Get Object With Presigned Url")
@pytest.mark.parametrize("url_from", ["neofs_authmate", "s3"])
@pytest.mark.parametrize("url_from", ["s3"])
def test_s3_get_object_with_presigned_url(self, bucket, simple_object_size, url_from: str):
file_path = generate_file(simple_object_size)
file_name = object_key_from_file_path(file_path)
file_names_to_check = [
"temp_file_12345",
"%40hashed/4e/07/temp_file_12345",
"\\inter\\stingfile",
">cool<>name<",
"&cool&&name&",
"cool\\/name\\",
"||cool||name||",
":cool::name",
"@cool@name@",
";cool;name;",
";cool,name!",
]

with allure.step("Put object into Bucket"):
s3_object.put_object_s3(self.s3_client, bucket, file_path)
if self.neofs_env.s3_gw._get_version() <= "0.33.0":
file_names_to_check = ["temp_file_12345"]

with allure.step(f"Get presigned URL from {url_from}"):
if url_from == "neofs_authmate":
neofs_authmate = NeofsAuthmate(
shell=self.shell, neofs_authmate_exec_path=self.neofs_env.neofs_s3_authmate_path
)
raw_url = json.loads(
neofs_authmate.presigned.generate_presigned_url(
endpoint=f"https://{self.neofs_env.s3_gw.address}",
method="GET",
bucket=bucket,
object=file_name,
lifetime="30s",
aws_secret_access_key=self.secret_access_key,
aws_access_key_id=self.access_key_id,
).stdout
)
presigned_url = raw_url["URL"]
else:
for file_name in file_names_to_check:
with allure.step("Put object into Bucket"):
s3_object.put_object_s3(self.s3_client, bucket, file_path, file_name)

with allure.step(f"Get presigned URL from {url_from}"):
presigned_url = self.s3_client.generate_presigned_url(
ClientMethod="get_object",
Params={"Bucket": bucket, "Key": file_name},
Expand All @@ -58,19 +54,19 @@ def test_s3_get_object_with_presigned_url(self, bucket, simple_object_size, url_
).strip()
logger.info(f"Presigned URL: {presigned_url}")

with allure.step("Get object with generated presigned url"):
resp = requests.get(presigned_url, stream=True, timeout=30, verify=False)
with allure.step("Get object with generated presigned url"):
resp = requests.get(presigned_url, stream=True, timeout=30, verify=False)

if not resp.ok:
raise Exception(
f"""Failed to get object via presigned url:
request: {resp.request.path_url},
response: {resp.text},
status code: {resp.status_code} {resp.reason}"""
)
if not resp.ok:
raise Exception(
f"""Failed to get object via presigned url:
request: {resp.request.path_url},
response: {resp.text},
status code: {resp.status_code} {resp.reason}"""
)

new_file_path = os.path.join(get_assets_dir_path(), TEST_FILES_DIR, f"temp_file_{uuid.uuid4()}")
with open(new_file_path, "wb") as file:
shutil.copyfileobj(resp.raw, file)
new_file_path = os.path.join(get_assets_dir_path(), TEST_FILES_DIR, f"temp_file_{uuid.uuid4()}")
with open(new_file_path, "wb") as file:
shutil.copyfileobj(resp.raw, file)

assert get_file_hash(file_path) == get_file_hash(new_file_path), "Files hashes are different"
assert get_file_hash(file_path) == get_file_hash(new_file_path), "Files hashes are different"
Loading