2022-12-29 07:17:51 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import allure
|
|
|
|
import pytest
|
2023-11-29 13:34:59 +00:00
|
|
|
from frostfs_testlib import reporter
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.resources.wellknown_acl import PUBLIC_ACL
|
|
|
|
from frostfs_testlib.steps.acl import (
|
2022-12-29 07:17:51 +00:00
|
|
|
bearer_token_base64_from_file,
|
|
|
|
create_eacl,
|
|
|
|
form_bearertoken_file,
|
|
|
|
set_eacl,
|
|
|
|
sign_bearer,
|
|
|
|
wait_for_cache_expired,
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
from frostfs_testlib.steps.cli.container import create_container
|
|
|
|
from frostfs_testlib.steps.http.http_gate import upload_via_http_gate_curl, verify_object_hash
|
|
|
|
from frostfs_testlib.storage.dataclasses.acl import EACLAccess, EACLOperation, EACLRole, EACLRule
|
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.cluster_test_base import ClusterTestBase
|
|
|
|
from frostfs_testlib.utils.file_utils import generate_file
|
2022-12-29 07:17:51 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger("NeoLogger")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.http_gate
|
2023-08-08 13:40:00 +00:00
|
|
|
@pytest.mark.http_put
|
2022-12-29 07:17:51 +00:00
|
|
|
class Test_http_bearer(ClusterTestBase):
|
|
|
|
PLACEMENT_RULE = "REP 2 IN X CBF 1 SELECT 2 FROM * AS X"
|
|
|
|
|
|
|
|
@pytest.fixture(scope="class", autouse=True)
|
|
|
|
@allure.title("[Class/Autouse]: Prepare wallet and deposit")
|
|
|
|
def prepare_wallet(self, default_wallet):
|
|
|
|
Test_http_bearer.wallet = default_wallet
|
|
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
|
|
def user_container(self) -> str:
|
|
|
|
return create_container(
|
|
|
|
wallet=self.wallet,
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
rule=self.PLACEMENT_RULE,
|
|
|
|
basic_acl=PUBLIC_ACL,
|
|
|
|
)
|
|
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
|
|
def eacl_deny_for_others(self, user_container: str) -> None:
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Set deny all operations for {EACLRole.OTHERS} via eACL"):
|
2023-10-31 14:51:09 +00:00
|
|
|
eacl = EACLRule(access=EACLAccess.DENY, role=EACLRole.OTHERS, operation=EACLOperation.PUT)
|
2022-12-29 07:17:51 +00:00
|
|
|
set_eacl(
|
|
|
|
self.wallet,
|
|
|
|
user_container,
|
|
|
|
create_eacl(user_container, eacl, shell=self.shell),
|
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
)
|
|
|
|
wait_for_cache_expired()
|
|
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
|
|
def bearer_token_no_limit_for_others(self, user_container: str) -> str:
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Create bearer token for {EACLRole.OTHERS} with all operations allowed"):
|
2022-12-29 07:17:51 +00:00
|
|
|
bearer = form_bearertoken_file(
|
|
|
|
self.wallet,
|
|
|
|
user_container,
|
2023-10-31 14:51:09 +00:00
|
|
|
[EACLRule(operation=op, access=EACLAccess.ALLOW, role=EACLRole.OTHERS) for op in EACLOperation],
|
2022-12-29 07:17:51 +00:00
|
|
|
shell=self.shell,
|
|
|
|
endpoint=self.cluster.default_rpc_endpoint,
|
|
|
|
sign=False,
|
|
|
|
)
|
|
|
|
bearer_signed = f"{bearer}_signed"
|
|
|
|
sign_bearer(
|
|
|
|
shell=self.shell,
|
2024-03-11 16:34:54 +00:00
|
|
|
wallet=self.wallet,
|
2022-12-29 07:17:51 +00:00
|
|
|
eacl_rules_file_from=bearer,
|
|
|
|
eacl_rules_file_to=bearer_signed,
|
|
|
|
json=False,
|
|
|
|
)
|
|
|
|
return bearer_token_base64_from_file(bearer_signed)
|
|
|
|
|
2023-08-07 09:43:16 +00:00
|
|
|
@allure.title(f"[NEGATIVE] Put object without bearer token for {EACLRole.OTHERS}")
|
2022-12-29 07:17:51 +00:00
|
|
|
def test_unable_put_without_bearer_token(
|
2023-08-02 11:54:03 +00:00
|
|
|
self, simple_object_size: ObjectSize, user_container: str, eacl_deny_for_others
|
2022-12-29 07:17:51 +00:00
|
|
|
):
|
|
|
|
eacl_deny_for_others
|
|
|
|
upload_via_http_gate_curl(
|
|
|
|
cid=user_container,
|
2023-08-02 11:54:03 +00:00
|
|
|
filepath=generate_file(simple_object_size.value),
|
2022-12-29 07:17:51 +00:00
|
|
|
endpoint=self.cluster.default_http_gate_endpoint,
|
|
|
|
error_pattern="access to object operation denied",
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_put_with_bearer_when_eacl_restrict(
|
|
|
|
self,
|
2023-08-02 11:54:03 +00:00
|
|
|
object_size: ObjectSize,
|
2022-12-29 07:17:51 +00:00
|
|
|
user_container: str,
|
|
|
|
eacl_deny_for_others,
|
|
|
|
bearer_token_no_limit_for_others: str,
|
|
|
|
):
|
|
|
|
eacl_deny_for_others
|
|
|
|
bearer = bearer_token_no_limit_for_others
|
2023-08-02 11:54:03 +00:00
|
|
|
file_path = generate_file(object_size.value)
|
2023-11-29 13:34:59 +00:00
|
|
|
with reporter.step(f"Put object with bearer token for {EACLRole.OTHERS}, then get and verify hashes"):
|
2022-12-29 07:17:51 +00:00
|
|
|
headers = [f" -H 'Authorization: Bearer {bearer}'"]
|
|
|
|
oid = upload_via_http_gate_curl(
|
|
|
|
cid=user_container,
|
|
|
|
filepath=file_path,
|
|
|
|
endpoint=self.cluster.default_http_gate_endpoint,
|
|
|
|
headers=headers,
|
|
|
|
)
|
2023-05-15 09:59:33 +00:00
|
|
|
verify_object_hash(
|
2022-12-29 07:17:51 +00:00
|
|
|
oid=oid,
|
|
|
|
file_name=file_path,
|
|
|
|
wallet=self.wallet,
|
|
|
|
cid=user_container,
|
|
|
|
shell=self.shell,
|
|
|
|
nodes=self.cluster.storage_nodes,
|
2024-02-14 13:20:06 +00:00
|
|
|
request_node=self.cluster.cluster_nodes[0],
|
2022-12-29 07:17:51 +00:00
|
|
|
)
|