Skip to content

Commit 393c6ff

Browse files
committed
adds check on permissions
1 parent 891aba4 commit 393c6ff

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

services/web/server/src/simcore_service_webserver/security/decorators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async def _wrapped(request: web.Request):
6262
# If product or group check fails, continue to deny access
6363
# NOTE: Logging omitted to avoid exposing internal errors
6464
):
65+
# FIXME: must be >GUEST !!
6566
if permission in NAMED_GROUP_PERMISSIONS.get(
6667
"PRODUCT_SUPPORT_GROUP", []
6768
) and await products_web.is_user_in_product_support_group(

services/web/server/tests/unit/with_dbs/03/invitations/test_users_accounts_rest_registration.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
import asyncio
10-
from collections.abc import AsyncGenerator
10+
from collections.abc import AsyncGenerator, AsyncIterator
1111
from http import HTTPStatus
1212
from typing import Any
1313
from unittest.mock import AsyncMock
@@ -23,6 +23,7 @@
2323
from models_library.api_schemas_webserver.users import (
2424
UserAccountGet,
2525
)
26+
from models_library.groups import AccessRightsDict
2627
from models_library.products import ProductName
2728
from models_library.rest_pagination import Page
2829
from pytest_mock import MockerFixture
@@ -36,6 +37,7 @@
3637
from pytest_simcore.helpers.webserver_login import (
3738
UserInfoDict,
3839
)
40+
from pytest_simcore.helpers.webserver_users import NewUser
3941
from servicelib.aiohttp import status
4042
from servicelib.rest_constants import X_PRODUCT_NAME_HEADER
4143
from simcore_postgres_database.models.users_details import (
@@ -88,6 +90,36 @@ async def mock_send_message(msg):
8890
return mock_session
8991

9092

93+
@pytest.fixture
94+
async def support_user(
95+
support_group_before_app_starts: dict,
96+
client: TestClient,
97+
) -> AsyncIterator[UserInfoDict]:
98+
"""Creates an active user that belongs to the product's support group."""
99+
async with NewUser(
100+
user_data={
101+
"name": "support-user",
102+
"status": UserStatus.ACTIVE.name,
103+
"role": UserRole.USER.name,
104+
},
105+
app=client.app,
106+
) as user_info:
107+
# Add the user to the support group
108+
assert client.app
109+
110+
from simcore_service_webserver.groups import _groups_repository
111+
112+
# Now add user to support group with read-only access
113+
await _groups_repository.add_new_user_in_group(
114+
client.app,
115+
group_id=support_group_before_app_starts["gid"],
116+
new_user_id=user_info["id"],
117+
access_rights=AccessRightsDict(read=True, write=False, delete=False),
118+
)
119+
120+
yield user_info
121+
122+
91123
@pytest.mark.parametrize(
92124
"user_role,expected",
93125
[
@@ -116,6 +148,26 @@ async def test_access_rights_on_search_users_only_product_owners_can_access(
116148
await assert_status(resp, expected)
117149

118150

151+
async def test_access_rights_on_search_users_support_user_can_access_when_above_guest(
152+
support_user: UserInfoDict,
153+
# keep support_user first since it has to be created before the app starts
154+
client: TestClient,
155+
pre_registration_details_db_cleanup: None,
156+
):
157+
"""Test that support users with role > GUEST can access the search endpoint."""
158+
assert client.app
159+
160+
from pytest_simcore.helpers.webserver_login import switch_client_session_to
161+
162+
# Switch client session to the support user
163+
async with switch_client_session_to(client, support_user):
164+
url = client.app.router["search_user_accounts"].url_for()
165+
assert url.path == "/v0/admin/user-accounts:search"
166+
167+
resp = await client.get(url.path, params={"email": "[email protected]"})
168+
await assert_status(resp, status.HTTP_200_OK)
169+
170+
119171
@pytest.fixture
120172
def account_request_form(
121173
faker: Faker,

0 commit comments

Comments
 (0)