2022-08-25 10:57:55 +00:00
|
|
|
from typing import List, Optional
|
|
|
|
|
2023-01-09 12:46:03 +00:00
|
|
|
from frostfs_testlib.shell import Shell
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.storage.cluster import Cluster
|
|
|
|
from frostfs_testlib.storage.dataclasses.acl import EACLOperation
|
2024-03-11 16:34:54 +00:00
|
|
|
from frostfs_testlib.storage.dataclasses.wallet import WalletInfo
|
2023-02-27 16:54:27 +00:00
|
|
|
|
|
|
|
from pytest_tests.helpers.object_access import (
|
2022-09-28 12:07:16 +00:00
|
|
|
can_delete_object,
|
|
|
|
can_get_head_object,
|
|
|
|
can_get_object,
|
|
|
|
can_get_range_hash_of_object,
|
|
|
|
can_get_range_of_object,
|
|
|
|
can_put_object,
|
|
|
|
can_search_object,
|
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def check_full_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
file_name: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
cluster: Cluster,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
):
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint = cluster.default_rpc_endpoint
|
2024-03-11 16:34:54 +00:00
|
|
|
assert can_put_object(wallet, cid, file_name, shell, cluster, bearer, xhdr)
|
|
|
|
assert can_get_head_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
|
|
|
assert can_get_range_of_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
|
|
|
assert can_get_range_hash_of_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
|
|
|
assert can_search_object(wallet, cid, shell, endpoint, oid, bearer, xhdr)
|
|
|
|
assert can_get_object(wallet, cid, oid, file_name, shell, cluster, bearer, xhdr)
|
|
|
|
assert can_delete_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def check_no_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
file_name: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
cluster: Cluster,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
):
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint = cluster.default_rpc_endpoint
|
2024-03-11 16:34:54 +00:00
|
|
|
assert not can_put_object(wallet, cid, file_name, shell, cluster, bearer, xhdr)
|
|
|
|
assert not can_get_head_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
|
|
|
assert not can_get_range_of_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
|
|
|
assert not can_get_range_hash_of_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
|
|
|
assert not can_search_object(wallet, cid, shell, endpoint, oid, bearer, xhdr)
|
|
|
|
assert not can_get_object(wallet, cid, oid, file_name, shell, cluster, bearer, xhdr)
|
|
|
|
assert not can_delete_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def check_custom_access_to_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
file_name: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
cluster: Cluster,
|
2022-09-28 12:07:16 +00:00
|
|
|
deny_operations: Optional[List[EACLOperation]] = None,
|
|
|
|
ignore_operations: Optional[List[EACLOperation]] = None,
|
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
):
|
2022-12-05 22:31:45 +00:00
|
|
|
endpoint = cluster.default_rpc_endpoint
|
2022-08-25 10:57:55 +00:00
|
|
|
deny_operations = [op.value for op in deny_operations or []]
|
|
|
|
ignore_operations = [op.value for op in ignore_operations or []]
|
|
|
|
checks: dict = {}
|
|
|
|
if EACLOperation.PUT.value not in ignore_operations:
|
2024-03-11 16:34:54 +00:00
|
|
|
checks[EACLOperation.PUT.value] = can_put_object(wallet, cid, file_name, shell, cluster, bearer, xhdr)
|
2022-08-25 10:57:55 +00:00
|
|
|
if EACLOperation.HEAD.value not in ignore_operations:
|
2024-03-11 16:34:54 +00:00
|
|
|
checks[EACLOperation.HEAD.value] = can_get_head_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
2022-08-25 10:57:55 +00:00
|
|
|
if EACLOperation.GET_RANGE.value not in ignore_operations:
|
2024-03-11 16:34:54 +00:00
|
|
|
checks[EACLOperation.GET_RANGE.value] = can_get_range_of_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
2022-08-25 10:57:55 +00:00
|
|
|
if EACLOperation.GET_RANGE_HASH.value not in ignore_operations:
|
2022-09-28 12:07:16 +00:00
|
|
|
checks[EACLOperation.GET_RANGE_HASH.value] = can_get_range_hash_of_object(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet, cid, oid, shell, endpoint, bearer, xhdr
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
if EACLOperation.SEARCH.value not in ignore_operations:
|
2024-03-11 16:34:54 +00:00
|
|
|
checks[EACLOperation.SEARCH.value] = can_search_object(wallet, cid, shell, endpoint, oid, bearer, xhdr)
|
2022-08-25 10:57:55 +00:00
|
|
|
if EACLOperation.GET.value not in ignore_operations:
|
2024-03-11 16:34:54 +00:00
|
|
|
checks[EACLOperation.GET.value] = can_get_object(wallet, cid, oid, file_name, shell, cluster, bearer, xhdr)
|
2022-08-25 10:57:55 +00:00
|
|
|
if EACLOperation.DELETE.value not in ignore_operations:
|
2024-03-11 16:34:54 +00:00
|
|
|
checks[EACLOperation.DELETE.value] = can_delete_object(wallet, cid, oid, shell, endpoint, bearer, xhdr)
|
2022-08-25 10:57:55 +00:00
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
failed_checks = [
|
|
|
|
f"allowed {action} failed"
|
|
|
|
for action, success in checks.items()
|
|
|
|
if not success and action not in deny_operations
|
2024-03-11 16:34:54 +00:00
|
|
|
] + [f"denied {action} succeeded" for action, success in checks.items() if success and action in deny_operations]
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
assert not failed_checks, ", ".join(failed_checks)
|
|
|
|
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
def check_read_only_container(
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet: WalletInfo,
|
2022-09-28 12:07:16 +00:00
|
|
|
cid: str,
|
|
|
|
oid: str,
|
|
|
|
file_name: str,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell: Shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
cluster: Cluster,
|
2022-09-28 12:07:16 +00:00
|
|
|
bearer: Optional[str] = None,
|
|
|
|
xhdr: Optional[dict] = None,
|
|
|
|
):
|
|
|
|
return check_custom_access_to_container(
|
|
|
|
wallet,
|
|
|
|
cid,
|
|
|
|
oid,
|
|
|
|
file_name,
|
|
|
|
deny_operations=[EACLOperation.PUT, EACLOperation.DELETE],
|
|
|
|
bearer=bearer,
|
|
|
|
xhdr=xhdr,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=shell,
|
2022-12-05 22:31:45 +00:00
|
|
|
cluster=cluster,
|
2022-09-28 12:07:16 +00:00
|
|
|
)
|