From 325e909000075092975a174dcaf9fd62f48acaec Mon Sep 17 00:00:00 2001 From: Jiri Kozel Date: Fri, 15 Dec 2023 11:44:05 +0100 Subject: [PATCH] Move negative access rights test to wrong_input_test.py --- src/layman/rest_publication_test.py | 44 +-------------- .../wrong_input/wrong_input_test.py | 56 +++++++++++++++++++ 2 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/layman/rest_publication_test.py b/src/layman/rest_publication_test.py index 9cae2bf51..4d8a952a9 100644 --- a/src/layman/rest_publication_test.py +++ b/src/layman/rest_publication_test.py @@ -1,54 +1,12 @@ import pytest -from layman import LaymanError, settings, common +from layman import settings, common from layman.common.micka import util as micka_util from test_tools import process_client db_schema = settings.LAYMAN_PRIME_SCHEMA -@pytest.mark.parametrize('publ_type', process_client.PUBLICATION_TYPES) -@pytest.mark.usefixtures('ensure_layman') -def test_wrong_post(publ_type): - def check_response(exception): - assert exception.value.http_code == 400 - assert exception.value.code == 43 - assert exception.value.message == 'Wrong access rights.' - - workspace = 'test_wrong_post_workspace' - publication = 'test_wrong_post_publication' - - with pytest.raises(LaymanError) as exc_info: - process_client.publish_workspace_publication(publ_type, workspace, publication, access_rights={'read': 'EVRBODY'}, ) - check_response(exc_info) - - with pytest.raises(LaymanError) as exc_info: - process_client.publish_workspace_publication(publ_type, workspace, publication, access_rights={'write': 'EVRBODY'}, ) - check_response(exc_info) - - with pytest.raises(LaymanError) as exc_info: - process_client.publish_workspace_publication(publ_type, workspace, publication, access_rights={'read': 'EVRBODY', 'write': 'EVRBODY'}, ) - check_response(exc_info) - - process_client.publish_workspace_publication(publ_type, workspace, publication) - - with pytest.raises(LaymanError) as exc_info: - process_client.patch_workspace_publication(publ_type, workspace, publication, access_rights={'read': 'EVRBODY'}, ) - check_response(exc_info) - - with pytest.raises(LaymanError) as exc_info: - process_client.patch_workspace_publication(publ_type, workspace, publication, access_rights={'write': 'EVRBODY'}, ) - check_response(exc_info) - - with pytest.raises(LaymanError) as exc_info: - process_client.patch_workspace_publication(publ_type, workspace, publication, access_rights={'read': 'EVRBODY', 'write': 'EVRBODY'}, ) - check_response(exc_info) - - process_client.patch_workspace_publication(publ_type, workspace, publication) - - process_client.delete_workspace_publication(publ_type, workspace, publication) - - class TestSoapClass: username = 'test_rest_soap_user' publ_name_prefix = 'test_rest_soap_' diff --git a/tests/dynamic_data/publications/wrong_input/wrong_input_test.py b/tests/dynamic_data/publications/wrong_input/wrong_input_test.py index 5333703f4..676ca6399 100644 --- a/tests/dynamic_data/publications/wrong_input/wrong_input_test.py +++ b/tests/dynamic_data/publications/wrong_input/wrong_input_test.py @@ -1391,6 +1391,62 @@ class Key(Enum): Key.RUN_ONLY_CASES: frozenset([RestMethod.PATCH, WithChunksDomain.FALSE, CompressDomain.FALSE]), Key.SPECIFIC_CASES: {}, }, + 'layer_wrong_access_rights_wrong_role': { + Key.PUBLICATION_TYPE: process_client.LAYER_TYPE, + Key.WORKSPACE: OWNER, + Key.POST_BEFORE_TEST_ARGS: { + 'access_rights': { + 'read': OWNER, + 'write': OWNER, + }, + 'actor_name': OWNER, + }, + Key.REST_ARGS: { + 'access_rights': { + 'read': f'{OWNER},EVERYONE,ROLE__WITH_TWO_UNDERSCORES', + 'write': f'{OWNER},EVERYONE,ROLE__WITH_TWO_UNDERSCORES', + }, + 'actor_name': OWNER, + }, + Key.EXCEPTION: LaymanError, + Key.EXPECTED_EXCEPTION: { + 'http_code': 400, + 'sync': True, + 'code': 43, + 'message': 'Wrong access rights.', + }, + Key.MANDATORY_CASES: frozenset([RestMethod.POST, WithChunksDomain.FALSE, CompressDomain.FALSE]), + Key.RUN_ONLY_CASES: frozenset([RestMethod, WithChunksDomain.FALSE, CompressDomain.FALSE]), + Key.SPECIFIC_CASES: {}, + }, + 'map_wrong_access_rights_wrong_role': { + Key.PUBLICATION_TYPE: process_client.MAP_TYPE, + Key.WORKSPACE: OWNER, + Key.POST_BEFORE_TEST_ARGS: { + 'access_rights': { + 'read': OWNER, + 'write': OWNER, + }, + 'actor_name': OWNER, + }, + Key.REST_ARGS: { + 'access_rights': { + 'read': f'{OWNER},EVERYONE,ROLE__WITH_TWO_UNDERSCORES', + 'write': f'{OWNER},EVERYONE,ROLE__WITH_TWO_UNDERSCORES', + }, + 'actor_name': OWNER, + }, + Key.EXCEPTION: LaymanError, + Key.EXPECTED_EXCEPTION: { + 'http_code': 400, + 'sync': True, + 'code': 43, + 'message': 'Wrong access rights.', + }, + Key.MANDATORY_CASES: frozenset([RestMethod.POST, WithChunksDomain.FALSE, CompressDomain.FALSE]), + Key.RUN_ONLY_CASES: frozenset([RestMethod, WithChunksDomain.FALSE, CompressDomain.FALSE]), + Key.SPECIFIC_CASES: {}, + }, }