Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/626.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor test users in integration tests.
3 changes: 2 additions & 1 deletion tests/integration/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .data import ESSData, generated_data
from .helm import helm_prerequisites, ingress_ready, matrix_stack, secrets_generated
from .matrix_tools import build_matrix_tools, loaded_matrix_tools
from .users import users
from .users import User, users

__all__ = [
"build_matrix_tools",
Expand All @@ -28,5 +28,6 @@
"root_ca",
"secrets_generated",
"ssl_context",
"User",
"users",
]
34 changes: 26 additions & 8 deletions tests/integration/fixtures/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,48 @@
# SPDX-License-Identifier: AGPL-3.0-only

import asyncio
from collections.abc import Iterable
from dataclasses import dataclass, field

import pytest

from ..lib.matrix_authentication_service import create_mas_user, get_client_token
from ..lib.matrix_authentication_service import (
create_mas_user,
get_client_token,
)
from ..lib.synapse import create_synapse_user
from ..lib.utils import value_file_has
from .data import ESSData


@pytest.fixture(scope="session")
@dataclass
class User:
name: str
admin: bool = field(default=False)
access_token: str | None = field(default=None)


@pytest.fixture
async def users(
request, pytestconfig, matrix_stack, secrets_generated, generated_data: ESSData, ssl_context, ingress_ready
):
await ingress_ready("synapse")
if value_file_has("matrixAuthenticationService.enabled", True):
await ingress_ready("matrix-authentication-service")

users = request.param
assert isinstance(users, Iterable)

wait_for_users = []
if value_file_has("matrixAuthenticationService.enabled", True):
admin_token = await get_client_token(f"mas.{generated_data.server_name}", generated_data, ssl_context)
for user in request.param:
for user in users:
wait_for_users.append(
create_mas_user(
f"mas.{generated_data.server_name}",
user,
user.name,
generated_data.secrets_random,
False,
user.admin,
admin_token,
ssl_context,
pytestconfig,
Expand All @@ -41,12 +56,15 @@ async def users(
wait_for_users.append(
create_synapse_user(
f"synapse.{generated_data.server_name}",
user,
user.name,
generated_data.secrets_random,
False,
user.admin,
synapse_registration_shared_secret,
ssl_context,
pytestconfig,
)
)
return await asyncio.gather(*wait_for_users)
tokens = await asyncio.gather(*wait_for_users)
for i, user in enumerate(users):
user.access_token = tokens[i]
return users
8 changes: 4 additions & 4 deletions tests/integration/test_element_call.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Copyright 2024 New Vector Ltd
# Copyright 2024-2025 New Vector Ltd
#
# SPDX-License-Identifier: AGPL-3.0-only

import pytest

from .fixtures import ESSData
from .fixtures import ESSData, User
from .lib.utils import aiohttp_post_json, value_file_has


@pytest.mark.skipif(value_file_has("matrixRTC.enabled", False), reason="Matrix RTC not deployed")
@pytest.mark.skipif(value_file_has("synapse.enabled", False), reason="Synapse not deployed")
@pytest.mark.skipif(value_file_has("wellKnownDelegation.enabled", False), reason="Well-Known Delegation not deployed")
@pytest.mark.parametrize("users", [("matrix-rtc-user",)], indirect=True)
@pytest.mark.parametrize("users", [(User(name="matrix-rtc-user"),)], indirect=True)
@pytest.mark.asyncio_cooperative
async def test_element_call_livekit_jwt(ingress_ready, users, generated_data: ESSData, ssl_context):
await ingress_ready("synapse")
access_token = users[0]
access_token = users[0].access_token

openid_token = await aiohttp_post_json(
f"https://synapse.{generated_data.server_name}/_matrix/client/v3/user/@matrix-rtc-user:{generated_data.server_name}/openid/request_token",
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_syn2mas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
from lightkube import AsyncClient

from .fixtures import ESSData
from .fixtures import ESSData, User
from .fixtures.users import create_mas_user, get_client_token
from .lib.helpers import deploy_with_values_patch, get_deployment_marker
from .lib.utils import aiohttp_get_json, aiohttp_post_json, value_file_has
Expand All @@ -21,7 +21,7 @@
or value_file_has("matrixAuthenticationService.syn2mas.enabled", False),
reason="Syn2Mas not deployed or the tested chart version does not support syn2mas",
)
@pytest.mark.parametrize("users", [("syn2mas-user",)], indirect=True)
@pytest.mark.parametrize("users", [(User(name="syn2mas-user"),)], indirect=True)
@pytest.mark.asyncio_cooperative
async def test_run_syn2mas_upgrade(
helm_client: pyhelm3.Client,
Expand All @@ -32,7 +32,7 @@ async def test_run_syn2mas_upgrade(
generated_data: ESSData,
pytestconfig,
):
access_token = users[0]
access_token = users[0].access_token
await ingress_ready("synapse")
assert await get_deployment_marker(kube_client, generated_data, "MATRIX_STACK_MSC3861") == "legacy_auth"
# After the base chart is setup, we enable MAS to run the syn2mas dry run job
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/test_synapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pyhelm3
import pytest

from .fixtures import ESSData
from .fixtures import ESSData, User
from .lib.helpers import deploy_with_values_patch, get_deployment_marker
from .lib.synapse import assert_downloaded_content, download_media, upload_media
from .lib.utils import KubeCtl, aiohttp_client, aiohttp_get_json, aiohttp_post_json, value_file_has
Expand All @@ -33,10 +33,10 @@ async def test_synapse_can_access_client_api(


@pytest.mark.skipif(value_file_has("synapse.enabled", False), reason="Synapse not deployed")
@pytest.mark.parametrize("users", [("sliding-sync-user",)], indirect=True)
@pytest.mark.parametrize("users", [(User(name="sliding-sync-user"),)], indirect=True)
@pytest.mark.asyncio_cooperative
async def test_simplified_sliding_sync_syncs(ssl_context, users, generated_data: ESSData):
access_token = users[0]
access_token = users[0].access_token

sync_result = await aiohttp_post_json(
f"https://synapse.{generated_data.server_name}/_matrix/client/unstable/org.matrix.simplified_msc3575/sync",
Expand All @@ -49,15 +49,15 @@ async def test_simplified_sliding_sync_syncs(ssl_context, users, generated_data:


@pytest.mark.skipif(value_file_has("synapse.enabled", False), reason="Synapse not deployed")
@pytest.mark.parametrize("users", [("media-upload-unauth",)], indirect=True)
@pytest.mark.parametrize("users", [(User(name="media-upload-unauth"),)], indirect=True)
@pytest.mark.asyncio_cooperative
async def test_synapse_media_upload_fetch_authenticated(
cluster,
ssl_context,
users,
generated_data: ESSData,
):
user_access_token = users[0]
user_access_token = users[0].access_token

filepath = Path(__file__).parent.resolve() / Path("artifacts/files/minimal.png")
with open(filepath, "rb") as file:
Expand Down
Loading