Skip to content

Commit

Permalink
Move negative access rights test to wrong_input_test.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Dec 15, 2023
1 parent e33b202 commit 325e909
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 43 deletions.
44 changes: 1 addition & 43 deletions src/layman/rest_publication_test.py
Original file line number Diff line number Diff line change
@@ -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_'
Expand Down
56 changes: 56 additions & 0 deletions tests/dynamic_data/publications/wrong_input/wrong_input_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
},
}


Expand Down

0 comments on commit 325e909

Please sign in to comment.