-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from db import util as db_util | ||
from layman import settings | ||
|
||
|
||
def ensure_role(rolename): | ||
insert_role_statement = f'''insert into {settings.LAYMAN_INTERNAL_ROLE_SERVICE_SCHEMA}.bussiness_roles(name) values (%s) ON CONFLICT (name) DO nothing;''' | ||
db_util.run_statement(insert_role_statement, (rolename,)) | ||
|
||
|
||
def delete_role(rolename): | ||
delete_statement = f"""delete from {settings.LAYMAN_INTERNAL_ROLE_SERVICE_SCHEMA}.bussiness_roles where name = %s;""" | ||
db_util.run_statement(delete_statement, (rolename,)) | ||
|
||
|
||
def ensure_user_role(username, rolename): | ||
ensure_role(rolename) | ||
insert_user_role_statement = f'''insert into {settings.LAYMAN_INTERNAL_ROLE_SERVICE_SCHEMA}.bussiness_user_roles(username, rolename) values (%s, %s) ON CONFLICT (username, rolename) DO nothing;''' | ||
db_util.run_statement(insert_user_role_statement, (username, rolename,)) | ||
|
||
|
||
def delete_user_role(username, rolename): | ||
delete_statement = f"""delete from {settings.LAYMAN_INTERNAL_ROLE_SERVICE_SCHEMA}.bussiness_user_roles where username = %s and rolename = %s;""" | ||
db_util.run_statement(delete_statement, (username, rolename,)) |
62 changes: 62 additions & 0 deletions
62
tests/dynamic_data/publications/access_rights/test_role_application.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import pytest | ||
|
||
from layman import LaymanError | ||
from test_tools import process_client, role_service as role_service_util | ||
from tests import EnumTestTypes | ||
from tests.asserts.final.publication import util as assert_util | ||
from tests.dynamic_data import base_test, base_test_classes | ||
from tests.dynamic_data.publications import common_publications | ||
|
||
pytest_generate_tests = base_test.pytest_generate_tests | ||
|
||
|
||
class PublicationTypes(base_test_classes.PublicationByDefinitionBase): | ||
LAYER = (common_publications.LAYER_VECTOR_SLD, 'layer') | ||
|
||
|
||
OWNER = 'test_role_application_user' | ||
ROLE = 'TEST_ROLE_APPLICATION_ROLE' | ||
ROLE_USER = 'test_role_application_role_user' | ||
USERS_AND_ROLES = {OWNER, ROLE} | ||
|
||
|
||
@pytest.mark.usefixtures('oauth2_provider_mock') | ||
class TestPublication(base_test.TestSingleRestPublication): | ||
workspace = OWNER | ||
publication_type = process_client.LAYER_TYPE | ||
|
||
rest_parametrization = [ | ||
] | ||
|
||
usernames_to_reserve = [ | ||
OWNER, | ||
ROLE_USER, | ||
] | ||
role_user_headers = process_client.get_authz_headers(ROLE_USER) | ||
|
||
test_cases = [base_test.TestCaseType(key='role_test', | ||
rest_args={ | ||
'access_rights': { | ||
'read': ','.join(USERS_AND_ROLES), | ||
}, | ||
'actor_name': OWNER, | ||
}, | ||
type=EnumTestTypes.MANDATORY, | ||
)] | ||
|
||
def test_publication(self, layer, rest_method, rest_args): | ||
rest_method.fn(layer, args=rest_args) | ||
assert_util.is_publication_valid_and_complete(layer) | ||
|
||
with pytest.raises(LaymanError) as exc_info: | ||
process_client.get_workspace_publication(layer.type, layer.workspace, layer.name, headers=self.role_user_headers) | ||
assert exc_info.value.http_code == 404 | ||
assert exc_info.value.code == 15 | ||
assert exc_info.value.message == 'Layer was not found' | ||
|
||
role_service_util.ensure_user_role(ROLE_USER, ROLE) | ||
info = process_client.get_workspace_publication(layer.type, layer.workspace, layer.name, headers=self.role_user_headers) | ||
assert set(info['access_rights']['read']) == USERS_AND_ROLES | ||
|
||
role_service_util.delete_user_role(ROLE_USER, ROLE) | ||
role_service_util.delete_role(ROLE) |