2022-08-25 10:57:55 +00:00
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
import allure
|
2022-10-11 08:18:08 +00:00
|
|
|
from file_helper import get_file_hash
|
2022-08-25 10:57:55 +00:00
|
|
|
from grpc_responses import OBJECT_ACCESS_DENIED, error_matches_status
|
2022-10-13 18:53:44 +00:00
|
|
|
from neofs_testlib.shell import Shell
|
2022-09-28 12:07:16 +00:00
|
|
|
from python_keywords.neofs_verbs import (
|
|
|
|
delete_object,
|
|
|
|
get_object,
|
|
|
|
get_range,
|
|
|
|
get_range_hash,
|
|
|
|
head_object,
|
|
|
|
put_object,
|
|
|
|
search_object,
|
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
OPERATION_ERROR_TYPE = RuntimeError
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_get_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
file_name: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> bool:
|
|
|
|
with allure.step("Try get object from container"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-09-28 12:07:16 +00:00
|
|
|
got_file_path = get_object(
|
2022-10-13 16:13:45 +00:00
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
bearer_token=bearer,
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
xhdr=xhdr,
|
|
|
|
shell=shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2022-09-28 12:07:16 +00:00
|
|
|
assert error_matches_status(
|
|
|
|
err, OBJECT_ACCESS_DENIED
|
|
|
|
), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
assert get_file_hash(file_name) == get_file_hash(got_file_path)
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_put_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
file_name: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
attributes: Optional[dict] = None,
|
|
|
|
) -> bool:
|
|
|
|
with allure.step("Try put object to container"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-09-28 12:07:16 +00:00
|
|
|
put_object(
|
|
|
|
wallet,
|
|
|
|
file_name,
|
|
|
|
cid,
|
|
|
|
bearer=bearer,
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
xhdr=xhdr,
|
|
|
|
attributes=attributes,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2022-09-28 12:07:16 +00:00
|
|
|
assert error_matches_status(
|
|
|
|
err, OBJECT_ACCESS_DENIED
|
|
|
|
), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_delete_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> bool:
|
|
|
|
with allure.step("Try delete object from container"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-10-13 18:53:44 +00:00
|
|
|
delete_object(
|
|
|
|
wallet, cid, oid, bearer=bearer, wallet_config=wallet_config, xhdr=xhdr, shell=shell
|
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2022-09-28 12:07:16 +00:00
|
|
|
assert error_matches_status(
|
|
|
|
err, OBJECT_ACCESS_DENIED
|
|
|
|
), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_get_head_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> bool:
|
|
|
|
with allure.step("Try get head of object"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-09-28 12:07:16 +00:00
|
|
|
head_object(
|
2022-10-13 18:53:44 +00:00
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
bearer=bearer,
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
xhdr=xhdr,
|
|
|
|
shell=shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2022-09-28 12:07:16 +00:00
|
|
|
assert error_matches_status(
|
|
|
|
err, OBJECT_ACCESS_DENIED
|
|
|
|
), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_get_range_of_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> bool:
|
|
|
|
with allure.step("Try get range of object"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-09-28 12:07:16 +00:00
|
|
|
get_range(
|
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
bearer=bearer,
|
|
|
|
range_cut="0:10",
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
xhdr=xhdr,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2022-09-28 12:07:16 +00:00
|
|
|
assert error_matches_status(
|
|
|
|
err, OBJECT_ACCESS_DENIED
|
|
|
|
), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_get_range_hash_of_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
|
|
|
oid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> bool:
|
|
|
|
with allure.step("Try get range hash of object"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-09-28 12:07:16 +00:00
|
|
|
get_range_hash(
|
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
bearer_token=bearer,
|
|
|
|
range_cut="0:10",
|
|
|
|
wallet_config=wallet_config,
|
|
|
|
xhdr=xhdr,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2022-09-28 12:07:16 +00:00
|
|
|
assert error_matches_status(
|
|
|
|
err, OBJECT_ACCESS_DENIED
|
|
|
|
), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def can_search_object(
|
|
|
|
wallet: str,
|
|
|
|
cid: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-09-28 12:07:16 +00:00
|
|
|
oid: Optional[str] = None,
|
|
|
|
bearer: Optional[str] = None,
|
|
|
|
wallet_config: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
) -> bool:
|
|
|
|
with allure.step("Try search object in container"):
|
2022-08-25 10:57:55 +00:00
|
|
|
try:
|
2022-10-13 18:53:44 +00:00
|
|
|
oids = search_object(
|
|
|
|
wallet, cid, bearer=bearer, wallet_config=wallet_config, xhdr=xhdr, shell=shell
|
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
except OPERATION_ERROR_TYPE as err:
|
2022-09-28 12:07:16 +00:00
|
|
|
assert error_matches_status(
|
|
|
|
err, OBJECT_ACCESS_DENIED
|
|
|
|
), f"Expected {err} to match {OBJECT_ACCESS_DENIED}"
|
2022-08-25 10:57:55 +00:00
|
|
|
return False
|
|
|
|
if oid:
|
|
|
|
return oid in oids
|
|
|
|
return True
|