Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEMP] Enable to use SQLite3 in v1_23_change_oauth2_sub_username_to_user_id.py #999

Closed
wants to merge 10 commits into from
Prev Previous commit
Next Next commit
Restrict new workspace names to 59 characters
index-git authored and jirik committed Jan 8, 2024
commit 000d6152ec9ad5e3cb09b13c234fbbd25ee49e1c
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
- [GET](doc/rest.md#get-workspace-map)/[PATCH](doc/rest.md#patch-workspace-map) Workspace Map
- GET Workspace [Layers](doc/rest.md#get-workspace-layers)/[Maps](doc/rest.md#get-workspace-maps)
- GET [Layers](doc/rest.md#get-layers)/[Maps](doc/rest.md#get-maps)/[Publications](doc/rest.md#get-publications)
- [#165](https://github.com/LayerManager/layman/issues/165) Name of [users](doc/models.md#username) and [public workspaces](doc/models.md#public-workspace) are from now on restricted to 59 characters.
- All changes from [v1.22.1](#v1221), [v1.22.2](#v1222) and [v1.22.3](#v1223).
- [#960](https://github.com/LayerManager/layman/issues/960) Handle WMS requests with HTTP error more efficiently in timgen.
- [#962](https://github.com/LayerManager/layman/issues/962) Make values of `layman_metadata.publication_status` and `status` key(s) more consistent in responses of PATCH Workspace [Layer](doc/rest.md#patch-workspace-layer)/[Map](doc/rest.md#patch-workspace-map) and GET Workspace [Layer](doc/rest.md#get-workspace-layer)/[Map](doc/rest.md#get-workspace-map).
3 changes: 3 additions & 0 deletions src/layman/common/prime_db_schema/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from layman.common.prime_db_schema import users as users_util, workspaces as workspaces_util
from layman.http import LaymanError

get_usernames = users_util.get_usernames
get_workspaces = workspaces_util.get_workspace_names
@@ -26,4 +27,6 @@ def ensure_workspace(workspace):


def check_workspace_name(workspace):
if len(workspace) > 59:
raise LaymanError(56)
workspaces_util.check_workspace_name(workspace)
1 change: 1 addition & 0 deletions src/layman/error_list.py
Original file line number Diff line number Diff line change
@@ -56,4 +56,5 @@
53: (500, 'Error when publishing on GeoServer. It happens for example for raster files with wrong explicit CRS.'),
54: (400, 'Wrong header value'),
55: (400, 'Publication is not complete'), # raised by process_client only
56: (403, 'Username or workspace name is too long. Maximum is 59 characters.')
}
1 change: 1 addition & 0 deletions test_tools/process.py
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ def oauth2_provider_mock():
'test_access_rights_application_other_user': None,
'test_patch_after_feature_change_role_user': None,
'test_patch_current_user_username': None,
'test_patch_current_user_username_fail_xxxxxxxxxxxxxxxxxxxxxx': None,
},
},
'host': '0.0.0.0',
7 changes: 6 additions & 1 deletion test_tools/process_client.py
Original file line number Diff line number Diff line change
@@ -640,8 +640,13 @@ def get_workspace_publication_metadata_comparison(publication_type, workspace, n
get_workspace_map_metadata_comparison = partial(get_workspace_publication_metadata_comparison, MAP_TYPE)


def reserve_username(username, headers=None):
def reserve_username(username, headers=None, *, actor_name=None):
headers = headers or {}
if actor_name:
assert TOKEN_HEADER not in headers

if actor_name and actor_name != settings.ANONYM_USER:
headers.update(get_authz_headers(actor_name))
with app.app_context():
r_url = url_for('rest_current_user.patch')
data = {
17 changes: 17 additions & 0 deletions tests/dynamic_data/publications/wrong_input/wrong_input_test.py
Original file line number Diff line number Diff line change
@@ -1447,6 +1447,23 @@ class Key(Enum):
Key.RUN_ONLY_CASES: frozenset([RestMethod, WithChunksDomain.FALSE, CompressDomain.FALSE]),
Key.SPECIFIC_CASES: {},
},
'workspace_too_long': {
Key.PUBLICATION_TYPE: process_client.LAYER_TYPE,
Key.WORKSPACE: WORKSPACE.ljust(60, 'x'),
Key.REST_ARGS: {
'name': 'workspace_too_long_layer',
},
Key.EXCEPTION: LaymanError,
Key.FAILED_INFO_KEY: 'file',
Key.EXPECTED_EXCEPTION: {
'http_code': 403,
'sync': True,
'code': 56,
},
Key.MANDATORY_CASES: None,
Key.RUN_ONLY_CASES: frozenset([RestMethod.POST, WithChunksDomain.FALSE, CompressDomain.FALSE]),
Key.SPECIFIC_CASES: {},
},
}


8 changes: 8 additions & 0 deletions tests/dynamic_data/users_roles/test_current_user.py
Original file line number Diff line number Diff line change
@@ -22,6 +22,14 @@ def test_patch():
'code': 30,
'message': 'Unauthorized access',
}, id='unauthorized'),
pytest.param({
'username': 'test_patch_current_user_username_fail_'.ljust(60, 'x'),
'actor_name': 'test_patch_current_user_username_fail_'.ljust(60, 'x')
}, {
'http_code': 403,
'code': 56,
'message': 'Username or workspace name is too long. Maximum is 59 characters.',
}, id='too_long'),
])
def test_patch_current_user_raises(params, exp_exception):
with pytest.raises(LaymanError) as exc_info: