|
| 1 | +# |
| 2 | +# This file is licensed under the Affero General Public License (AGPL) version 3. |
| 3 | +# |
| 4 | +# Copyright (C) 2025 New Vector, Ltd |
| 5 | +# |
| 6 | +# This program is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Affero General Public License as |
| 8 | +# published by the Free Software Foundation, either version 3 of the |
| 9 | +# License, or (at your option) any later version. |
| 10 | +# |
| 11 | +# See the GNU Affero General Public License for more details: |
| 12 | +# <https://www.gnu.org/licenses/agpl-3.0.html>. |
| 13 | +# |
| 14 | +# [This file includes modifications made by New Vector Limited] |
| 15 | +# |
| 16 | +# |
| 17 | + |
| 18 | +"""Tests REST events for /rtc/endpoints path.""" |
| 19 | + |
| 20 | +from twisted.internet.testing import MemoryReactor |
| 21 | + |
| 22 | +from synapse.rest import admin |
| 23 | +from synapse.rest.client import login, matrixrtc, register, room |
| 24 | +from synapse.server import HomeServer |
| 25 | +from synapse.util.clock import Clock |
| 26 | + |
| 27 | +from tests.unittest import HomeserverTestCase, override_config |
| 28 | + |
| 29 | +PATH_PREFIX = "/_matrix/client/unstable/org.matrix.msc4143" |
| 30 | +RTC_ENDPOINT = {"type": "focusA", "required_field": "theField"} |
| 31 | +LIVEKIT_ENDPOINT = { |
| 32 | + "type": "livekit", |
| 33 | + "livekit_service_url": "https://livekit.example.com", |
| 34 | +} |
| 35 | + |
| 36 | + |
| 37 | +class MatrixRtcTestCase(HomeserverTestCase): |
| 38 | + """Tests /rtc/transports Client-Server REST API.""" |
| 39 | + |
| 40 | + servlets = [ |
| 41 | + admin.register_servlets, |
| 42 | + room.register_servlets, |
| 43 | + login.register_servlets, |
| 44 | + register.register_servlets, |
| 45 | + matrixrtc.register_servlets, |
| 46 | + ] |
| 47 | + |
| 48 | + def prepare( |
| 49 | + self, reactor: MemoryReactor, clock: Clock, homeserver: HomeServer |
| 50 | + ) -> None: |
| 51 | + self.register_user("alice", "password") |
| 52 | + self._alice_tok = self.login("alice", "password") |
| 53 | + |
| 54 | + def test_matrixrtc_endpoint_not_enabled(self) -> None: |
| 55 | + channel = self.make_request( |
| 56 | + "GET", f"{PATH_PREFIX}/rtc/transports", access_token=self._alice_tok |
| 57 | + ) |
| 58 | + self.assertEqual(404, channel.code, channel.json_body) |
| 59 | + self.assertEqual( |
| 60 | + "M_UNRECOGNIZED", channel.json_body["errcode"], channel.json_body |
| 61 | + ) |
| 62 | + |
| 63 | + @override_config({"experimental_features": {"msc4143_enabled": True}}) |
| 64 | + def test_matrixrtc_endpoint_requires_authentication(self) -> None: |
| 65 | + channel = self.make_request("GET", f"{PATH_PREFIX}/rtc/transports") |
| 66 | + self.assertEqual(401, channel.code, channel.json_body) |
| 67 | + |
| 68 | + @override_config( |
| 69 | + { |
| 70 | + "experimental_features": {"msc4143_enabled": True}, |
| 71 | + "matrix_rtc": {"transports": [RTC_ENDPOINT]}, |
| 72 | + } |
| 73 | + ) |
| 74 | + def test_matrixrtc_endpoint_contains_expected_transport(self) -> None: |
| 75 | + channel = self.make_request( |
| 76 | + "GET", f"{PATH_PREFIX}/rtc/transports", access_token=self._alice_tok |
| 77 | + ) |
| 78 | + self.assertEqual(200, channel.code, channel.json_body) |
| 79 | + self.assert_dict({"rtc_transports": [RTC_ENDPOINT]}, channel.json_body) |
| 80 | + |
| 81 | + @override_config( |
| 82 | + { |
| 83 | + "experimental_features": {"msc4143_enabled": True}, |
| 84 | + "matrix_rtc": {"transports": []}, |
| 85 | + } |
| 86 | + ) |
| 87 | + def test_matrixrtc_endpoint_no_transports_configured(self) -> None: |
| 88 | + channel = self.make_request( |
| 89 | + "GET", f"{PATH_PREFIX}/rtc/transports", access_token=self._alice_tok |
| 90 | + ) |
| 91 | + self.assertEqual(200, channel.code, channel.json_body) |
| 92 | + self.assert_dict({}, channel.json_body) |
| 93 | + |
| 94 | + @override_config( |
| 95 | + { |
| 96 | + "experimental_features": {"msc4143_enabled": True}, |
| 97 | + "matrix_rtc": {"transports": [LIVEKIT_ENDPOINT]}, |
| 98 | + } |
| 99 | + ) |
| 100 | + def test_matrixrtc_endpoint_livekit_transport(self) -> None: |
| 101 | + channel = self.make_request( |
| 102 | + "GET", f"{PATH_PREFIX}/rtc/transports", access_token=self._alice_tok |
| 103 | + ) |
| 104 | + self.assertEqual(200, channel.code, channel.json_body) |
| 105 | + self.assert_dict({"rtc_transports": [LIVEKIT_ENDPOINT]}, channel.json_body) |
0 commit comments