2022-08-25 10:57:55 +00:00
|
|
|
import allure
|
|
|
|
import pytest
|
2022-09-05 12:12:56 +00:00
|
|
|
from python_keywords.acl import (
|
|
|
|
EACLAccess,
|
|
|
|
EACLOperation,
|
|
|
|
EACLRole,
|
|
|
|
EACLRule,
|
|
|
|
create_eacl,
|
|
|
|
form_bearertoken_file,
|
|
|
|
set_eacl,
|
|
|
|
wait_for_cache_expired,
|
|
|
|
)
|
|
|
|
from python_keywords.container_access import (
|
|
|
|
check_custom_access_to_container,
|
|
|
|
check_full_access_to_container,
|
|
|
|
check_no_access_to_container,
|
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sanity
|
|
|
|
@pytest.mark.acl
|
|
|
|
@pytest.mark.acl_bearer
|
|
|
|
class TestACLBearer:
|
2022-09-05 12:12:56 +00:00
|
|
|
@pytest.mark.parametrize("role", [EACLRole.USER, EACLRole.OTHERS])
|
2022-10-13 18:53:44 +00:00
|
|
|
def test_bearer_token_operations(
|
|
|
|
self, wallets, client_shell, eacl_container_with_objects, role
|
|
|
|
):
|
2022-09-28 12:07:16 +00:00
|
|
|
allure.dynamic.title(f"Testcase to validate NeoFS operations with {role.value} BearerToken")
|
2022-08-25 10:57:55 +00:00
|
|
|
cid, objects_oids, file_path = eacl_container_with_objects
|
|
|
|
user_wallet = wallets.get_wallet()
|
|
|
|
deny_wallet = wallets.get_wallet(role)
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step(f"Check {role.value} has full access to container without bearer token"):
|
2022-09-05 12:12:56 +00:00
|
|
|
check_full_access_to_container(
|
|
|
|
deny_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
wallet_config=deny_wallet.config_path,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step(f"Set deny all operations for {role.value} via eACL"):
|
|
|
|
eacl = [
|
2022-09-28 12:07:16 +00:00
|
|
|
EACLRule(access=EACLAccess.DENY, role=role, operation=op) for op in EACLOperation
|
2022-09-05 12:12:56 +00:00
|
|
|
]
|
2022-10-13 18:53:44 +00:00
|
|
|
eacl_file = create_eacl(cid, eacl, shell=client_shell)
|
|
|
|
set_eacl(user_wallet.wallet_path, cid, eacl_file, shell=client_shell)
|
2022-08-25 10:57:55 +00:00
|
|
|
wait_for_cache_expired()
|
|
|
|
|
2022-09-28 12:07:16 +00:00
|
|
|
with allure.step(f"Create bearer token for {role.value} with all operations allowed"):
|
2022-09-05 12:12:56 +00:00
|
|
|
bearer_token = form_bearertoken_file(
|
|
|
|
user_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
[
|
|
|
|
EACLRule(operation=op, access=EACLAccess.ALLOW, role=role)
|
|
|
|
for op in EACLOperation
|
|
|
|
],
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step(
|
|
|
|
f"Check {role.value} without token has no access to all operations with container"
|
|
|
|
):
|
2022-08-25 10:57:55 +00:00
|
|
|
check_no_access_to_container(
|
2022-09-05 12:12:56 +00:00
|
|
|
deny_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
wallet_config=deny_wallet.config_path,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step(
|
|
|
|
f"Check {role.value} with token has access to all operations with container"
|
|
|
|
):
|
|
|
|
check_full_access_to_container(
|
|
|
|
deny_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
bearer=bearer_token,
|
|
|
|
wallet_config=deny_wallet.config_path,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step(f"Set allow all operations for {role.value} via eACL"):
|
|
|
|
eacl = [
|
2022-09-28 12:07:16 +00:00
|
|
|
EACLRule(access=EACLAccess.ALLOW, role=role, operation=op) for op in EACLOperation
|
2022-09-05 12:12:56 +00:00
|
|
|
]
|
2022-10-13 18:53:44 +00:00
|
|
|
eacl_file = create_eacl(cid, eacl, shell=client_shell)
|
|
|
|
set_eacl(user_wallet.wallet_path, cid, eacl_file, shell=client_shell)
|
2022-08-25 10:57:55 +00:00
|
|
|
wait_for_cache_expired()
|
|
|
|
|
2022-09-05 12:12:56 +00:00
|
|
|
with allure.step(
|
|
|
|
f"Check {role.value} without token has access to all operations with container"
|
|
|
|
):
|
|
|
|
check_full_access_to_container(
|
|
|
|
deny_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
wallet_config=deny_wallet.config_path,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@allure.title("BearerToken Operations for compound Operations")
|
2022-10-13 18:53:44 +00:00
|
|
|
def test_bearer_token_compound_operations(
|
|
|
|
self, wallets, client_shell, eacl_container_with_objects
|
|
|
|
):
|
2022-08-25 10:57:55 +00:00
|
|
|
cid, objects_oids, file_path = eacl_container_with_objects
|
|
|
|
user_wallet = wallets.get_wallet()
|
|
|
|
other_wallet = wallets.get_wallet(role=EACLRole.OTHERS)
|
|
|
|
|
|
|
|
# Operations that we will deny for each role via eACL
|
|
|
|
deny_map = {
|
|
|
|
EACLRole.USER: [EACLOperation.DELETE],
|
2022-09-05 12:12:56 +00:00
|
|
|
EACLRole.OTHERS: [
|
|
|
|
EACLOperation.SEARCH,
|
|
|
|
EACLOperation.GET_RANGE_HASH,
|
|
|
|
EACLOperation.GET_RANGE,
|
|
|
|
],
|
2022-08-25 10:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Operations that we will allow for each role with bearer token
|
|
|
|
bearer_map = {
|
2022-09-05 12:12:56 +00:00
|
|
|
EACLRole.USER: [
|
|
|
|
EACLOperation.DELETE,
|
|
|
|
EACLOperation.PUT,
|
|
|
|
EACLOperation.GET_RANGE,
|
|
|
|
],
|
|
|
|
EACLRole.OTHERS: [
|
|
|
|
EACLOperation.GET,
|
|
|
|
EACLOperation.GET_RANGE,
|
|
|
|
EACLOperation.GET_RANGE_HASH,
|
|
|
|
],
|
2022-08-25 10:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deny_map_with_bearer = {
|
2022-09-05 12:12:56 +00:00
|
|
|
EACLRole.USER: [
|
2022-09-28 12:07:16 +00:00
|
|
|
op for op in deny_map[EACLRole.USER] if op not in bearer_map[EACLRole.USER]
|
2022-09-05 12:12:56 +00:00
|
|
|
],
|
|
|
|
EACLRole.OTHERS: [
|
2022-09-28 12:07:16 +00:00
|
|
|
op for op in deny_map[EACLRole.OTHERS] if op not in bearer_map[EACLRole.OTHERS]
|
2022-09-05 12:12:56 +00:00
|
|
|
],
|
2022-08-25 10:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
eacl_deny = []
|
|
|
|
for role, operations in deny_map.items():
|
2022-09-05 12:12:56 +00:00
|
|
|
eacl_deny += [
|
2022-09-28 12:07:16 +00:00
|
|
|
EACLRule(access=EACLAccess.DENY, role=role, operation=op) for op in operations
|
2022-09-05 12:12:56 +00:00
|
|
|
]
|
2022-10-13 18:53:44 +00:00
|
|
|
set_eacl(
|
|
|
|
user_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
eacl_table_path=create_eacl(cid, eacl_deny, shell=client_shell),
|
|
|
|
shell=client_shell,
|
|
|
|
)
|
2022-08-25 10:57:55 +00:00
|
|
|
wait_for_cache_expired()
|
|
|
|
|
2022-09-05 12:12:56 +00:00
|
|
|
with allure.step("Check rule consistency without bearer"):
|
|
|
|
check_custom_access_to_container(
|
|
|
|
user_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
deny_operations=deny_map[EACLRole.USER],
|
|
|
|
wallet_config=user_wallet.config_path,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
check_custom_access_to_container(
|
|
|
|
other_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
deny_operations=deny_map[EACLRole.OTHERS],
|
|
|
|
wallet_config=other_wallet.config_path,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
with allure.step("Check rule consistency using bearer token"):
|
|
|
|
bearer_token_user = form_bearertoken_file(
|
|
|
|
user_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
[
|
|
|
|
EACLRule(operation=op, access=EACLAccess.ALLOW, role=EACLRole.USER)
|
|
|
|
for op in bearer_map[EACLRole.USER]
|
|
|
|
],
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
bearer_token_other = form_bearertoken_file(
|
|
|
|
user_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
[
|
2022-09-28 12:07:16 +00:00
|
|
|
EACLRule(operation=op, access=EACLAccess.ALLOW, role=EACLRole.OTHERS)
|
2022-09-05 12:12:56 +00:00
|
|
|
for op in bearer_map[EACLRole.OTHERS]
|
|
|
|
],
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check_custom_access_to_container(
|
|
|
|
user_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
deny_operations=deny_map_with_bearer[EACLRole.USER],
|
|
|
|
bearer=bearer_token_user,
|
|
|
|
wallet_config=user_wallet.config_path,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|
|
|
|
check_custom_access_to_container(
|
|
|
|
other_wallet.wallet_path,
|
|
|
|
cid,
|
|
|
|
objects_oids.pop(),
|
|
|
|
file_path,
|
|
|
|
deny_operations=deny_map_with_bearer[EACLRole.OTHERS],
|
|
|
|
bearer=bearer_token_other,
|
|
|
|
wallet_config=other_wallet.config_path,
|
2022-10-13 18:53:44 +00:00
|
|
|
shell=client_shell,
|
2022-09-05 12:12:56 +00:00
|
|
|
)
|