Merge pull request #8946 from matrix-org/rav/refactor_send_request
Remove `Request` return value from `make_request`
This commit is contained in:
commit
651e1ae534
|
@ -0,0 +1 @@
|
||||||
|
Refactor test utilities for injecting HTTP requests.
|
|
@ -57,7 +57,7 @@ class FrontendProxyTests(HomeserverTestCase):
|
||||||
self.assertEqual(len(self.reactor.tcpServers), 1)
|
self.assertEqual(len(self.reactor.tcpServers), 1)
|
||||||
site = self.reactor.tcpServers[0][1]
|
site = self.reactor.tcpServers[0][1]
|
||||||
|
|
||||||
_, channel = make_request(self.reactor, site, "PUT", "presence/a/status")
|
channel = make_request(self.reactor, site, "PUT", "presence/a/status")
|
||||||
|
|
||||||
# 400 + unrecognised, because nothing is registered
|
# 400 + unrecognised, because nothing is registered
|
||||||
self.assertEqual(channel.code, 400)
|
self.assertEqual(channel.code, 400)
|
||||||
|
@ -77,7 +77,7 @@ class FrontendProxyTests(HomeserverTestCase):
|
||||||
self.assertEqual(len(self.reactor.tcpServers), 1)
|
self.assertEqual(len(self.reactor.tcpServers), 1)
|
||||||
site = self.reactor.tcpServers[0][1]
|
site = self.reactor.tcpServers[0][1]
|
||||||
|
|
||||||
_, channel = make_request(self.reactor, site, "PUT", "presence/a/status")
|
channel = make_request(self.reactor, site, "PUT", "presence/a/status")
|
||||||
|
|
||||||
# 401, because the stub servlet still checks authentication
|
# 401, because the stub servlet still checks authentication
|
||||||
self.assertEqual(channel.code, 401)
|
self.assertEqual(channel.code, 401)
|
||||||
|
|
|
@ -73,7 +73,7 @@ class FederationReaderOpenIDListenerTests(HomeserverTestCase):
|
||||||
return
|
return
|
||||||
raise
|
raise
|
||||||
|
|
||||||
_, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor, site, "GET", "/_matrix/federation/v1/openid/userinfo"
|
self.reactor, site, "GET", "/_matrix/federation/v1/openid/userinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ class SynapseHomeserverOpenIDListenerTests(HomeserverTestCase):
|
||||||
return
|
return
|
||||||
raise
|
raise
|
||||||
|
|
||||||
_, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor, site, "GET", "/_matrix/federation/v1/openid/userinfo"
|
self.reactor, site, "GET", "/_matrix/federation/v1/openid/userinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class RoomComplexityTests(unittest.FederatingHomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get the room complexity
|
# Get the room complexity
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/federation/unstable/rooms/%s/complexity" % (room_1,)
|
"GET", "/_matrix/federation/unstable/rooms/%s/complexity" % (room_1,)
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
@ -60,7 +60,7 @@ class RoomComplexityTests(unittest.FederatingHomeserverTestCase):
|
||||||
store.get_current_state_event_counts = lambda x: make_awaitable(500 * 1.23)
|
store.get_current_state_event_counts = lambda x: make_awaitable(500 * 1.23)
|
||||||
|
|
||||||
# Get the room complexity again -- make sure it's our artificial value
|
# Get the room complexity again -- make sure it's our artificial value
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/federation/unstable/rooms/%s/complexity" % (room_1,)
|
"GET", "/_matrix/federation/unstable/rooms/%s/complexity" % (room_1,)
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
|
|
@ -46,7 +46,7 @@ class FederationServerTests(unittest.FederatingHomeserverTestCase):
|
||||||
|
|
||||||
"/get_missing_events/(?P<room_id>[^/]*)/?"
|
"/get_missing_events/(?P<room_id>[^/]*)/?"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/federation/v1/get_missing_events/%s" % (room_1,),
|
"/_matrix/federation/v1/get_missing_events/%s" % (room_1,),
|
||||||
query_content,
|
query_content,
|
||||||
|
@ -95,7 +95,7 @@ class StateQueryTests(unittest.FederatingHomeserverTestCase):
|
||||||
room_1 = self.helper.create_room_as(u1, tok=u1_token)
|
room_1 = self.helper.create_room_as(u1, tok=u1_token)
|
||||||
self.inject_room_member(room_1, "@user:other.example.com", "join")
|
self.inject_room_member(room_1, "@user:other.example.com", "join")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/federation/v1/state/%s" % (room_1,)
|
"GET", "/_matrix/federation/v1/state/%s" % (room_1,)
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
|
@ -127,7 +127,7 @@ class StateQueryTests(unittest.FederatingHomeserverTestCase):
|
||||||
|
|
||||||
room_1 = self.helper.create_room_as(u1, tok=u1_token)
|
room_1 = self.helper.create_room_as(u1, tok=u1_token)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/federation/v1/state/%s" % (room_1,)
|
"GET", "/_matrix/federation/v1/state/%s" % (room_1,)
|
||||||
)
|
)
|
||||||
self.assertEquals(403, channel.code, channel.result)
|
self.assertEquals(403, channel.code, channel.result)
|
||||||
|
|
|
@ -37,14 +37,10 @@ class RoomDirectoryFederationTests(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
@override_config({"allow_public_rooms_over_federation": False})
|
@override_config({"allow_public_rooms_over_federation": False})
|
||||||
def test_blocked_public_room_list_over_federation(self):
|
def test_blocked_public_room_list_over_federation(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "/_matrix/federation/v1/publicRooms")
|
||||||
"GET", "/_matrix/federation/v1/publicRooms"
|
|
||||||
)
|
|
||||||
self.assertEquals(403, channel.code)
|
self.assertEquals(403, channel.code)
|
||||||
|
|
||||||
@override_config({"allow_public_rooms_over_federation": True})
|
@override_config({"allow_public_rooms_over_federation": True})
|
||||||
def test_open_public_room_list_over_federation(self):
|
def test_open_public_room_list_over_federation(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "/_matrix/federation/v1/publicRooms")
|
||||||
"GET", "/_matrix/federation/v1/publicRooms"
|
|
||||||
)
|
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
|
|
@ -405,7 +405,7 @@ class TestCreateAliasACL(unittest.HomeserverTestCase):
|
||||||
def test_denied(self):
|
def test_denied(self):
|
||||||
room_id = self.helper.create_room_as(self.user_id)
|
room_id = self.helper.create_room_as(self.user_id)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
b"directory/room/%23test%3Atest",
|
b"directory/room/%23test%3Atest",
|
||||||
('{"room_id":"%s"}' % (room_id,)).encode("ascii"),
|
('{"room_id":"%s"}' % (room_id,)).encode("ascii"),
|
||||||
|
@ -415,7 +415,7 @@ class TestCreateAliasACL(unittest.HomeserverTestCase):
|
||||||
def test_allowed(self):
|
def test_allowed(self):
|
||||||
room_id = self.helper.create_room_as(self.user_id)
|
room_id = self.helper.create_room_as(self.user_id)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
b"directory/room/%23unofficial_test%3Atest",
|
b"directory/room/%23unofficial_test%3Atest",
|
||||||
('{"room_id":"%s"}' % (room_id,)).encode("ascii"),
|
('{"room_id":"%s"}' % (room_id,)).encode("ascii"),
|
||||||
|
@ -431,7 +431,7 @@ class TestRoomListSearchDisabled(unittest.HomeserverTestCase):
|
||||||
def prepare(self, reactor, clock, hs):
|
def prepare(self, reactor, clock, hs):
|
||||||
room_id = self.helper.create_room_as(self.user_id)
|
room_id = self.helper.create_room_as(self.user_id)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", b"directory/list/room/%s" % (room_id.encode("ascii"),), b"{}"
|
"PUT", b"directory/list/room/%s" % (room_id.encode("ascii"),), b"{}"
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
|
@ -446,7 +446,7 @@ class TestRoomListSearchDisabled(unittest.HomeserverTestCase):
|
||||||
self.directory_handler.enable_room_list_search = True
|
self.directory_handler.enable_room_list_search = True
|
||||||
|
|
||||||
# Room list is enabled so we should get some results
|
# Room list is enabled so we should get some results
|
||||||
request, channel = self.make_request("GET", b"publicRooms")
|
channel = self.make_request("GET", b"publicRooms")
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
self.assertTrue(len(channel.json_body["chunk"]) > 0)
|
self.assertTrue(len(channel.json_body["chunk"]) > 0)
|
||||||
|
|
||||||
|
@ -454,13 +454,13 @@ class TestRoomListSearchDisabled(unittest.HomeserverTestCase):
|
||||||
self.directory_handler.enable_room_list_search = False
|
self.directory_handler.enable_room_list_search = False
|
||||||
|
|
||||||
# Room list disabled so we should get no results
|
# Room list disabled so we should get no results
|
||||||
request, channel = self.make_request("GET", b"publicRooms")
|
channel = self.make_request("GET", b"publicRooms")
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
self.assertTrue(len(channel.json_body["chunk"]) == 0)
|
self.assertTrue(len(channel.json_body["chunk"]) == 0)
|
||||||
|
|
||||||
# Room list disabled so we shouldn't be allowed to publish rooms
|
# Room list disabled so we shouldn't be allowed to publish rooms
|
||||||
room_id = self.helper.create_room_as(self.user_id)
|
room_id = self.helper.create_room_as(self.user_id)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", b"directory/list/room/%s" % (room_id.encode("ascii"),), b"{}"
|
"PUT", b"directory/list/room/%s" % (room_id.encode("ascii"),), b"{}"
|
||||||
)
|
)
|
||||||
self.assertEquals(403, channel.code, channel.result)
|
self.assertEquals(403, channel.code, channel.result)
|
||||||
|
|
|
@ -206,7 +206,7 @@ class ServerAclValidationTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Redaction of event should fail.
|
# Redaction of event should fail.
|
||||||
path = "/_matrix/client/r0/rooms/%s/redact/%s" % (self.room_id, event_id)
|
path = "/_matrix/client/r0/rooms/%s/redact/%s" % (self.room_id, event_id)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", path, content={}, access_token=self.access_token
|
"POST", path, content={}, access_token=self.access_token
|
||||||
)
|
)
|
||||||
self.assertEqual(int(channel.result["code"]), 403)
|
self.assertEqual(int(channel.result["code"]), 403)
|
||||||
|
|
|
@ -551,7 +551,7 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(channel.code, 400, channel.result)
|
self.assertEqual(channel.code, 400, channel.result)
|
||||||
|
|
||||||
def _get_login_flows(self) -> JsonDict:
|
def _get_login_flows(self) -> JsonDict:
|
||||||
_, channel = self.make_request("GET", "/_matrix/client/r0/login")
|
channel = self.make_request("GET", "/_matrix/client/r0/login")
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
return channel.json_body["flows"]
|
return channel.json_body["flows"]
|
||||||
|
|
||||||
|
@ -560,7 +560,7 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def _send_login(self, type, user, **params) -> FakeChannel:
|
def _send_login(self, type, user, **params) -> FakeChannel:
|
||||||
params.update({"identifier": {"type": "m.id.user", "user": user}, "type": type})
|
params.update({"identifier": {"type": "m.id.user", "user": user}, "type": type})
|
||||||
_, channel = self.make_request("POST", "/_matrix/client/r0/login", params)
|
channel = self.make_request("POST", "/_matrix/client/r0/login", params)
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
def _start_delete_device_session(self, access_token, device_id) -> str:
|
def _start_delete_device_session(self, access_token, device_id) -> str:
|
||||||
|
@ -597,7 +597,7 @@ class PasswordAuthProviderTests(unittest.HomeserverTestCase):
|
||||||
self, access_token: str, device: str, body: Union[JsonDict, bytes] = b"",
|
self, access_token: str, device: str, body: Union[JsonDict, bytes] = b"",
|
||||||
) -> FakeChannel:
|
) -> FakeChannel:
|
||||||
"""Delete an individual device."""
|
"""Delete an individual device."""
|
||||||
_, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"DELETE", "devices/" + device, body, access_token=access_token
|
"DELETE", "devices/" + device, body, access_token=access_token
|
||||||
)
|
)
|
||||||
return channel
|
return channel
|
||||||
|
|
|
@ -220,7 +220,7 @@ class TypingNotificationsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self.assertEquals(self.event_source.get_current_key(), 0)
|
self.assertEquals(self.event_source.get_current_key(), 0)
|
||||||
|
|
||||||
(request, channel) = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/_matrix/federation/v1/send/1000000",
|
"/_matrix/federation/v1/send/1000000",
|
||||||
_make_edu_transaction_json(
|
_make_edu_transaction_json(
|
||||||
|
|
|
@ -534,7 +534,7 @@ class TestUserDirSearchDisabled(unittest.HomeserverTestCase):
|
||||||
self.helper.join(room, user=u2)
|
self.helper.join(room, user=u2)
|
||||||
|
|
||||||
# Assert user directory is not empty
|
# Assert user directory is not empty
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", b"user_directory/search", b'{"search_term":"user2"}'
|
"POST", b"user_directory/search", b'{"search_term":"user2"}'
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
|
@ -542,7 +542,7 @@ class TestUserDirSearchDisabled(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Disable user directory and check search returns nothing
|
# Disable user directory and check search returns nothing
|
||||||
self.config.user_directory_search_enabled = False
|
self.config.user_directory_search_enabled = False
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", b"user_directory/search", b'{"search_term":"user2"}'
|
"POST", b"user_directory/search", b'{"search_term":"user2"}'
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
|
|
|
@ -46,16 +46,16 @@ class AdditionalResourceTests(HomeserverTestCase):
|
||||||
handler = _AsyncTestCustomEndpoint({}, None).handle_request
|
handler = _AsyncTestCustomEndpoint({}, None).handle_request
|
||||||
resource = AdditionalResource(self.hs, handler)
|
resource = AdditionalResource(self.hs, handler)
|
||||||
|
|
||||||
request, channel = make_request(self.reactor, FakeSite(resource), "GET", "/")
|
channel = make_request(self.reactor, FakeSite(resource), "GET", "/")
|
||||||
|
|
||||||
self.assertEqual(request.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
self.assertEqual(channel.json_body, {"some_key": "some_value_async"})
|
self.assertEqual(channel.json_body, {"some_key": "some_value_async"})
|
||||||
|
|
||||||
def test_sync(self):
|
def test_sync(self):
|
||||||
handler = _SyncTestCustomEndpoint({}, None).handle_request
|
handler = _SyncTestCustomEndpoint({}, None).handle_request
|
||||||
resource = AdditionalResource(self.hs, handler)
|
resource = AdditionalResource(self.hs, handler)
|
||||||
|
|
||||||
request, channel = make_request(self.reactor, FakeSite(resource), "GET", "/")
|
channel = make_request(self.reactor, FakeSite(resource), "GET", "/")
|
||||||
|
|
||||||
self.assertEqual(request.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
self.assertEqual(channel.json_body, {"some_key": "some_value_sync"})
|
self.assertEqual(channel.json_body, {"some_key": "some_value_sync"})
|
||||||
|
|
|
@ -667,7 +667,7 @@ class HTTPPusherTests(HomeserverTestCase):
|
||||||
# This will actually trigger a new notification to be sent out so that
|
# This will actually trigger a new notification to be sent out so that
|
||||||
# even if the user does not receive another message, their unread
|
# even if the user does not receive another message, their unread
|
||||||
# count goes down
|
# count goes down
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/rooms/%s/receipt/m.read/%s" % (room_id, first_message_event_id),
|
"/rooms/%s/receipt/m.read/%s" % (room_id, first_message_event_id),
|
||||||
{},
|
{},
|
||||||
|
|
|
@ -13,9 +13,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import logging
|
import logging
|
||||||
from typing import Tuple
|
|
||||||
|
|
||||||
from synapse.http.site import SynapseRequest
|
|
||||||
from synapse.rest.client.v2_alpha import register
|
from synapse.rest.client.v2_alpha import register
|
||||||
|
|
||||||
from tests.replication._base import BaseMultiWorkerStreamTestCase
|
from tests.replication._base import BaseMultiWorkerStreamTestCase
|
||||||
|
@ -47,7 +45,7 @@ class WorkerAuthenticationTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def _test_register(self) -> Tuple[SynapseRequest, FakeChannel]:
|
def _test_register(self) -> FakeChannel:
|
||||||
"""Run the actual test:
|
"""Run the actual test:
|
||||||
|
|
||||||
1. Create a worker homeserver.
|
1. Create a worker homeserver.
|
||||||
|
@ -59,14 +57,14 @@ class WorkerAuthenticationTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
worker_hs = self.make_worker_hs("synapse.app.client_reader")
|
worker_hs = self.make_worker_hs("synapse.app.client_reader")
|
||||||
site = self._hs_to_site[worker_hs]
|
site = self._hs_to_site[worker_hs]
|
||||||
|
|
||||||
request_1, channel_1 = make_request(
|
channel_1 = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
site,
|
site,
|
||||||
"POST",
|
"POST",
|
||||||
"register",
|
"register",
|
||||||
{"username": "user", "type": "m.login.password", "password": "bar"},
|
{"username": "user", "type": "m.login.password", "password": "bar"},
|
||||||
) # type: SynapseRequest, FakeChannel
|
)
|
||||||
self.assertEqual(request_1.code, 401)
|
self.assertEqual(channel_1.code, 401)
|
||||||
|
|
||||||
# Grab the session
|
# Grab the session
|
||||||
session = channel_1.json_body["session"]
|
session = channel_1.json_body["session"]
|
||||||
|
@ -83,8 +81,8 @@ class WorkerAuthenticationTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
def test_no_auth(self):
|
def test_no_auth(self):
|
||||||
"""With no authentication the request should finish.
|
"""With no authentication the request should finish.
|
||||||
"""
|
"""
|
||||||
request, channel = self._test_register()
|
channel = self._test_register()
|
||||||
self.assertEqual(request.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# We're given a registered user.
|
# We're given a registered user.
|
||||||
self.assertEqual(channel.json_body["user_id"], "@user:test")
|
self.assertEqual(channel.json_body["user_id"], "@user:test")
|
||||||
|
@ -93,8 +91,8 @@ class WorkerAuthenticationTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
def test_missing_auth(self):
|
def test_missing_auth(self):
|
||||||
"""If the main process expects a secret that is not provided, an error results.
|
"""If the main process expects a secret that is not provided, an error results.
|
||||||
"""
|
"""
|
||||||
request, channel = self._test_register()
|
channel = self._test_register()
|
||||||
self.assertEqual(request.code, 500)
|
self.assertEqual(channel.code, 500)
|
||||||
|
|
||||||
@override_config(
|
@override_config(
|
||||||
{
|
{
|
||||||
|
@ -105,15 +103,15 @@ class WorkerAuthenticationTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
def test_unauthorized(self):
|
def test_unauthorized(self):
|
||||||
"""If the main process receives the wrong secret, an error results.
|
"""If the main process receives the wrong secret, an error results.
|
||||||
"""
|
"""
|
||||||
request, channel = self._test_register()
|
channel = self._test_register()
|
||||||
self.assertEqual(request.code, 500)
|
self.assertEqual(channel.code, 500)
|
||||||
|
|
||||||
@override_config({"worker_replication_secret": "my-secret"})
|
@override_config({"worker_replication_secret": "my-secret"})
|
||||||
def test_authorized(self):
|
def test_authorized(self):
|
||||||
"""The request should finish when the worker provides the authentication header.
|
"""The request should finish when the worker provides the authentication header.
|
||||||
"""
|
"""
|
||||||
request, channel = self._test_register()
|
channel = self._test_register()
|
||||||
self.assertEqual(request.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# We're given a registered user.
|
# We're given a registered user.
|
||||||
self.assertEqual(channel.json_body["user_id"], "@user:test")
|
self.assertEqual(channel.json_body["user_id"], "@user:test")
|
||||||
|
|
|
@ -14,11 +14,10 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from synapse.http.site import SynapseRequest
|
|
||||||
from synapse.rest.client.v2_alpha import register
|
from synapse.rest.client.v2_alpha import register
|
||||||
|
|
||||||
from tests.replication._base import BaseMultiWorkerStreamTestCase
|
from tests.replication._base import BaseMultiWorkerStreamTestCase
|
||||||
from tests.server import FakeChannel, make_request
|
from tests.server import make_request
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -41,27 +40,27 @@ class ClientReaderTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
worker_hs = self.make_worker_hs("synapse.app.client_reader")
|
worker_hs = self.make_worker_hs("synapse.app.client_reader")
|
||||||
site = self._hs_to_site[worker_hs]
|
site = self._hs_to_site[worker_hs]
|
||||||
|
|
||||||
request_1, channel_1 = make_request(
|
channel_1 = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
site,
|
site,
|
||||||
"POST",
|
"POST",
|
||||||
"register",
|
"register",
|
||||||
{"username": "user", "type": "m.login.password", "password": "bar"},
|
{"username": "user", "type": "m.login.password", "password": "bar"},
|
||||||
) # type: SynapseRequest, FakeChannel
|
)
|
||||||
self.assertEqual(request_1.code, 401)
|
self.assertEqual(channel_1.code, 401)
|
||||||
|
|
||||||
# Grab the session
|
# Grab the session
|
||||||
session = channel_1.json_body["session"]
|
session = channel_1.json_body["session"]
|
||||||
|
|
||||||
# also complete the dummy auth
|
# also complete the dummy auth
|
||||||
request_2, channel_2 = make_request(
|
channel_2 = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
site,
|
site,
|
||||||
"POST",
|
"POST",
|
||||||
"register",
|
"register",
|
||||||
{"auth": {"session": session, "type": "m.login.dummy"}},
|
{"auth": {"session": session, "type": "m.login.dummy"}},
|
||||||
) # type: SynapseRequest, FakeChannel
|
)
|
||||||
self.assertEqual(request_2.code, 200)
|
self.assertEqual(channel_2.code, 200)
|
||||||
|
|
||||||
# We're given a registered user.
|
# We're given a registered user.
|
||||||
self.assertEqual(channel_2.json_body["user_id"], "@user:test")
|
self.assertEqual(channel_2.json_body["user_id"], "@user:test")
|
||||||
|
@ -73,28 +72,28 @@ class ClientReaderTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
worker_hs_2 = self.make_worker_hs("synapse.app.client_reader")
|
worker_hs_2 = self.make_worker_hs("synapse.app.client_reader")
|
||||||
|
|
||||||
site_1 = self._hs_to_site[worker_hs_1]
|
site_1 = self._hs_to_site[worker_hs_1]
|
||||||
request_1, channel_1 = make_request(
|
channel_1 = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
site_1,
|
site_1,
|
||||||
"POST",
|
"POST",
|
||||||
"register",
|
"register",
|
||||||
{"username": "user", "type": "m.login.password", "password": "bar"},
|
{"username": "user", "type": "m.login.password", "password": "bar"},
|
||||||
) # type: SynapseRequest, FakeChannel
|
)
|
||||||
self.assertEqual(request_1.code, 401)
|
self.assertEqual(channel_1.code, 401)
|
||||||
|
|
||||||
# Grab the session
|
# Grab the session
|
||||||
session = channel_1.json_body["session"]
|
session = channel_1.json_body["session"]
|
||||||
|
|
||||||
# also complete the dummy auth
|
# also complete the dummy auth
|
||||||
site_2 = self._hs_to_site[worker_hs_2]
|
site_2 = self._hs_to_site[worker_hs_2]
|
||||||
request_2, channel_2 = make_request(
|
channel_2 = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
site_2,
|
site_2,
|
||||||
"POST",
|
"POST",
|
||||||
"register",
|
"register",
|
||||||
{"auth": {"session": session, "type": "m.login.dummy"}},
|
{"auth": {"session": session, "type": "m.login.dummy"}},
|
||||||
) # type: SynapseRequest, FakeChannel
|
)
|
||||||
self.assertEqual(request_2.code, 200)
|
self.assertEqual(channel_2.code, 200)
|
||||||
|
|
||||||
# We're given a registered user.
|
# We're given a registered user.
|
||||||
self.assertEqual(channel_2.json_body["user_id"], "@user:test")
|
self.assertEqual(channel_2.json_body["user_id"], "@user:test")
|
||||||
|
|
|
@ -68,7 +68,7 @@ class MediaRepoShardTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
the media which the caller should respond to.
|
the media which the caller should respond to.
|
||||||
"""
|
"""
|
||||||
resource = hs.get_media_repository_resource().children[b"download"]
|
resource = hs.get_media_repository_resource().children[b"download"]
|
||||||
_, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(resource),
|
FakeSite(resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
|
|
@ -180,7 +180,7 @@ class EventPersisterShardTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Do an initial sync so that we're up to date.
|
# Do an initial sync so that we're up to date.
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor, sync_hs_site, "GET", "/sync", access_token=access_token
|
self.reactor, sync_hs_site, "GET", "/sync", access_token=access_token
|
||||||
)
|
)
|
||||||
next_batch = channel.json_body["next_batch"]
|
next_batch = channel.json_body["next_batch"]
|
||||||
|
@ -206,7 +206,7 @@ class EventPersisterShardTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
|
|
||||||
# Check that syncing still gets the new event, despite the gap in the
|
# Check that syncing still gets the new event, despite the gap in the
|
||||||
# stream IDs.
|
# stream IDs.
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
sync_hs_site,
|
sync_hs_site,
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -236,7 +236,7 @@ class EventPersisterShardTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
response = self.helper.send(room_id2, body="Hi!", tok=self.other_access_token)
|
response = self.helper.send(room_id2, body="Hi!", tok=self.other_access_token)
|
||||||
first_event_in_room2 = response["event_id"]
|
first_event_in_room2 = response["event_id"]
|
||||||
|
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
sync_hs_site,
|
sync_hs_site,
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -261,7 +261,7 @@ class EventPersisterShardTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
self.helper.send(room_id1, body="Hi again!", tok=self.other_access_token)
|
self.helper.send(room_id1, body="Hi again!", tok=self.other_access_token)
|
||||||
self.helper.send(room_id2, body="Hi again!", tok=self.other_access_token)
|
self.helper.send(room_id2, body="Hi again!", tok=self.other_access_token)
|
||||||
|
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
sync_hs_site,
|
sync_hs_site,
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -279,7 +279,7 @@ class EventPersisterShardTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
# Paginating back in the first room should not produce any results, as
|
# Paginating back in the first room should not produce any results, as
|
||||||
# no events have happened in it. This tests that we are correctly
|
# no events have happened in it. This tests that we are correctly
|
||||||
# filtering results based on the vector clock portion.
|
# filtering results based on the vector clock portion.
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
sync_hs_site,
|
sync_hs_site,
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -292,7 +292,7 @@ class EventPersisterShardTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
|
|
||||||
# Paginating back on the second room should produce the first event
|
# Paginating back on the second room should produce the first event
|
||||||
# again. This tests that pagination isn't completely broken.
|
# again. This tests that pagination isn't completely broken.
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
sync_hs_site,
|
sync_hs_site,
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -307,7 +307,7 @@ class EventPersisterShardTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Paginating forwards should give the same results
|
# Paginating forwards should give the same results
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
sync_hs_site,
|
sync_hs_site,
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -318,7 +318,7 @@ class EventPersisterShardTestCase(BaseMultiWorkerStreamTestCase):
|
||||||
)
|
)
|
||||||
self.assertListEqual([], channel.json_body["chunk"])
|
self.assertListEqual([], channel.json_body["chunk"])
|
||||||
|
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
sync_hs_site,
|
sync_hs_site,
|
||||||
"GET",
|
"GET",
|
||||||
|
|
|
@ -42,7 +42,7 @@ class VersionTestCase(unittest.HomeserverTestCase):
|
||||||
return resource
|
return resource
|
||||||
|
|
||||||
def test_version_string(self):
|
def test_version_string(self):
|
||||||
request, channel = self.make_request("GET", self.url, shorthand=False)
|
channel = self.make_request("GET", self.url, shorthand=False)
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -68,7 +68,7 @@ class DeleteGroupTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_delete_group(self):
|
def test_delete_group(self):
|
||||||
# Create a new group
|
# Create a new group
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/create_group".encode("ascii"),
|
"/create_group".encode("ascii"),
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -84,13 +84,13 @@ class DeleteGroupTestCase(unittest.HomeserverTestCase):
|
||||||
# Invite/join another user
|
# Invite/join another user
|
||||||
|
|
||||||
url = "/groups/%s/admin/users/invite/%s" % (group_id, self.other_user)
|
url = "/groups/%s/admin/users/invite/%s" % (group_id, self.other_user)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", url.encode("ascii"), access_token=self.admin_user_tok, content={}
|
"PUT", url.encode("ascii"), access_token=self.admin_user_tok, content={}
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
url = "/groups/%s/self/accept_invite" % (group_id,)
|
url = "/groups/%s/self/accept_invite" % (group_id,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", url.encode("ascii"), access_token=self.other_user_token, content={}
|
"PUT", url.encode("ascii"), access_token=self.other_user_token, content={}
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -101,7 +101,7 @@ class DeleteGroupTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Now delete the group
|
# Now delete the group
|
||||||
url = "/_synapse/admin/v1/delete_group/" + group_id
|
url = "/_synapse/admin/v1/delete_group/" + group_id
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url.encode("ascii"),
|
url.encode("ascii"),
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -123,7 +123,7 @@ class DeleteGroupTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
url = "/groups/%s/profile" % (group_id,)
|
url = "/groups/%s/profile" % (group_id,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ class DeleteGroupTestCase(unittest.HomeserverTestCase):
|
||||||
def _get_groups_user_is_in(self, access_token):
|
def _get_groups_user_is_in(self, access_token):
|
||||||
"""Returns the list of groups the user is in (given their access token)
|
"""Returns the list of groups the user is in (given their access token)
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/joined_groups".encode("ascii"), access_token=access_token
|
"GET", "/joined_groups".encode("ascii"), access_token=access_token
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def _ensure_quarantined(self, admin_user_tok, server_and_media_id):
|
def _ensure_quarantined(self, admin_user_tok, server_and_media_id):
|
||||||
"""Ensure a piece of media is quarantined when trying to access it."""
|
"""Ensure a piece of media is quarantined when trying to access it."""
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(self.download_resource),
|
FakeSite(self.download_resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -241,7 +241,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Attempt quarantine media APIs as non-admin
|
# Attempt quarantine media APIs as non-admin
|
||||||
url = "/_synapse/admin/v1/media/quarantine/example.org/abcde12345"
|
url = "/_synapse/admin/v1/media/quarantine/example.org/abcde12345"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", url.encode("ascii"), access_token=non_admin_user_tok,
|
"POST", url.encode("ascii"), access_token=non_admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# And the roomID/userID endpoint
|
# And the roomID/userID endpoint
|
||||||
url = "/_synapse/admin/v1/room/!room%3Aexample.com/media/quarantine"
|
url = "/_synapse/admin/v1/room/!room%3Aexample.com/media/quarantine"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", url.encode("ascii"), access_token=non_admin_user_tok,
|
"POST", url.encode("ascii"), access_token=non_admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
||||||
server_name, media_id = server_name_and_media_id.split("/")
|
server_name, media_id = server_name_and_media_id.split("/")
|
||||||
|
|
||||||
# Attempt to access the media
|
# Attempt to access the media
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(self.download_resource),
|
FakeSite(self.download_resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -299,7 +299,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
||||||
urllib.parse.quote(server_name),
|
urllib.parse.quote(server_name),
|
||||||
urllib.parse.quote(media_id),
|
urllib.parse.quote(media_id),
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", url, access_token=admin_user_tok,)
|
channel = self.make_request("POST", url, access_token=admin_user_tok,)
|
||||||
self.pump(1.0)
|
self.pump(1.0)
|
||||||
self.assertEqual(200, int(channel.code), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.code), msg=channel.result["body"])
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_synapse/admin/v1/room/%s/media/quarantine" % urllib.parse.quote(
|
url = "/_synapse/admin/v1/room/%s/media/quarantine" % urllib.parse.quote(
|
||||||
room_id
|
room_id
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", url, access_token=admin_user_tok,)
|
channel = self.make_request("POST", url, access_token=admin_user_tok,)
|
||||||
self.pump(1.0)
|
self.pump(1.0)
|
||||||
self.assertEqual(200, int(channel.code), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.code), msg=channel.result["body"])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -395,7 +395,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_synapse/admin/v1/user/%s/media/quarantine" % urllib.parse.quote(
|
url = "/_synapse/admin/v1/user/%s/media/quarantine" % urllib.parse.quote(
|
||||||
non_admin_user
|
non_admin_user
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", url.encode("ascii"), access_token=admin_user_tok,
|
"POST", url.encode("ascii"), access_token=admin_user_tok,
|
||||||
)
|
)
|
||||||
self.pump(1.0)
|
self.pump(1.0)
|
||||||
|
@ -437,7 +437,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_synapse/admin/v1/user/%s/media/quarantine" % urllib.parse.quote(
|
url = "/_synapse/admin/v1/user/%s/media/quarantine" % urllib.parse.quote(
|
||||||
non_admin_user
|
non_admin_user
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", url.encode("ascii"), access_token=admin_user_tok,
|
"POST", url.encode("ascii"), access_token=admin_user_tok,
|
||||||
)
|
)
|
||||||
self.pump(1.0)
|
self.pump(1.0)
|
||||||
|
@ -453,7 +453,7 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase):
|
||||||
self._ensure_quarantined(admin_user_tok, server_and_media_id_1)
|
self._ensure_quarantined(admin_user_tok, server_and_media_id_1)
|
||||||
|
|
||||||
# Attempt to access each piece of media
|
# Attempt to access each piece of media
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(self.download_resource),
|
FakeSite(self.download_resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
|
|
@ -50,17 +50,17 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to get a device of an user without authentication.
|
Try to get a device of an user without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url, b"{}")
|
channel = self.make_request("GET", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", self.url, b"{}")
|
channel = self.make_request("PUT", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
|
||||||
request, channel = self.make_request("DELETE", self.url, b"{}")
|
channel = self.make_request("DELETE", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -69,21 +69,21 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
If the user is not a server admin, an error is returned.
|
If the user is not a server admin, an error is returned.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url, access_token=self.other_user_token,
|
"GET", self.url, access_token=self.other_user_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", self.url, access_token=self.other_user_token,
|
"PUT", self.url, access_token=self.other_user_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"DELETE", self.url, access_token=self.other_user_token,
|
"DELETE", self.url, access_token=self.other_user_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -99,23 +99,17 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
% self.other_user_device_id
|
% self.other_user_device_id
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("PUT", url, access_token=self.admin_user_tok,)
|
||||||
"PUT", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("DELETE", url, access_token=self.admin_user_tok,)
|
||||||
"DELETE", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||||
|
@ -129,23 +123,17 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
% self.other_user_device_id
|
% self.other_user_device_id
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("PUT", url, access_token=self.admin_user_tok,)
|
||||||
"PUT", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("DELETE", url, access_token=self.admin_user_tok,)
|
||||||
"DELETE", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
||||||
|
@ -158,22 +146,16 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.other_user
|
self.other_user
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("PUT", url, access_token=self.admin_user_tok,)
|
||||||
"PUT", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("DELETE", url, access_token=self.admin_user_tok,)
|
||||||
"DELETE", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Delete unknown device returns status 200
|
# Delete unknown device returns status 200
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
@ -197,7 +179,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
body = json.dumps(update)
|
body = json.dumps(update)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
self.url,
|
self.url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -208,9 +190,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.TOO_LARGE, channel.json_body["errcode"])
|
self.assertEqual(Codes.TOO_LARGE, channel.json_body["errcode"])
|
||||||
|
|
||||||
# Ensure the display name was not updated.
|
# Ensure the display name was not updated.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("new display", channel.json_body["display_name"])
|
self.assertEqual("new display", channel.json_body["display_name"])
|
||||||
|
@ -227,16 +207,12 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("PUT", self.url, access_token=self.admin_user_tok,)
|
||||||
"PUT", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
|
||||||
# Ensure the display name was not updated.
|
# Ensure the display name was not updated.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("new display", channel.json_body["display_name"])
|
self.assertEqual("new display", channel.json_body["display_name"])
|
||||||
|
@ -247,7 +223,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
# Set new display_name
|
# Set new display_name
|
||||||
body = json.dumps({"display_name": "new displayname"})
|
body = json.dumps({"display_name": "new displayname"})
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
self.url,
|
self.url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -257,9 +233,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
|
||||||
# Check new display_name
|
# Check new display_name
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("new displayname", channel.json_body["display_name"])
|
self.assertEqual("new displayname", channel.json_body["display_name"])
|
||||||
|
@ -268,9 +242,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Tests that a normal lookup for a device is successfully
|
Tests that a normal lookup for a device is successfully
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
||||||
|
@ -291,7 +263,7 @@ class DeviceRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(1, number_devices)
|
self.assertEqual(1, number_devices)
|
||||||
|
|
||||||
# Delete device
|
# Delete device
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"DELETE", self.url, access_token=self.admin_user_tok,
|
"DELETE", self.url, access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -323,7 +295,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to list devices of an user without authentication.
|
Try to list devices of an user without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url, b"{}")
|
channel = self.make_request("GET", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -334,9 +306,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
other_user_token = self.login("user", "pass")
|
other_user_token = self.login("user", "pass")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=other_user_token,)
|
||||||
"GET", self.url, access_token=other_user_token,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
@ -346,9 +316,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
Tests that a lookup for a user that does not exist returns a 404
|
Tests that a lookup for a user that does not exist returns a 404
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v2/users/@unknown_person:test/devices"
|
url = "/_synapse/admin/v2/users/@unknown_person:test/devices"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||||
|
@ -359,9 +327,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v2/users/@unknown_person:unknown_domain/devices"
|
url = "/_synapse/admin/v2/users/@unknown_person:unknown_domain/devices"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
||||||
|
@ -373,9 +339,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Get devices
|
# Get devices
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(0, channel.json_body["total"])
|
self.assertEqual(0, channel.json_body["total"])
|
||||||
|
@ -391,9 +355,7 @@ class DevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.login("user", "pass")
|
self.login("user", "pass")
|
||||||
|
|
||||||
# Get devices
|
# Get devices
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(number_devices, channel.json_body["total"])
|
self.assertEqual(number_devices, channel.json_body["total"])
|
||||||
|
@ -431,7 +393,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to delete devices of an user without authentication.
|
Try to delete devices of an user without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("POST", self.url, b"{}")
|
channel = self.make_request("POST", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -442,9 +404,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
other_user_token = self.login("user", "pass")
|
other_user_token = self.login("user", "pass")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("POST", self.url, access_token=other_user_token,)
|
||||||
"POST", self.url, access_token=other_user_token,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
@ -454,9 +414,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
Tests that a lookup for a user that does not exist returns a 404
|
Tests that a lookup for a user that does not exist returns a 404
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v2/users/@unknown_person:test/delete_devices"
|
url = "/_synapse/admin/v2/users/@unknown_person:test/delete_devices"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("POST", url, access_token=self.admin_user_tok,)
|
||||||
"POST", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||||
|
@ -467,9 +425,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v2/users/@unknown_person:unknown_domain/delete_devices"
|
url = "/_synapse/admin/v2/users/@unknown_person:unknown_domain/delete_devices"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("POST", url, access_token=self.admin_user_tok,)
|
||||||
"POST", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
||||||
|
@ -479,7 +435,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
Tests that a remove of a device that does not exist returns 200.
|
Tests that a remove of a device that does not exist returns 200.
|
||||||
"""
|
"""
|
||||||
body = json.dumps({"devices": ["unknown_device1", "unknown_device2"]})
|
body = json.dumps({"devices": ["unknown_device1", "unknown_device2"]})
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -510,7 +466,7 @@ class DeleteDevicesRestTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Delete devices
|
# Delete devices
|
||||||
body = json.dumps({"devices": device_ids})
|
body = json.dumps({"devices": device_ids})
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
|
|
@ -74,7 +74,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to get an event report without authentication.
|
Try to get an event report without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url, b"{}")
|
channel = self.make_request("GET", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -84,9 +84,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
If the user is not a server admin, an error 403 is returned.
|
If the user is not a server admin, an error 403 is returned.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.other_user_tok,)
|
||||||
"GET", self.url, access_token=self.other_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
@ -96,9 +94,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
Testing list of reported events
|
Testing list of reported events
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(channel.json_body["total"], 20)
|
self.assertEqual(channel.json_body["total"], 20)
|
||||||
|
@ -111,7 +107,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
Testing list of reported events with limit
|
Testing list of reported events with limit
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=5", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -126,7 +122,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
Testing list of reported events with a defined starting point (from)
|
Testing list of reported events with a defined starting point (from)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=5", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -141,7 +137,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
Testing list of reported events with a defined starting point and limit
|
Testing list of reported events with a defined starting point and limit
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=5&limit=10", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=5&limit=10", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -156,7 +152,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
Testing list of reported events with a filter of room
|
Testing list of reported events with a filter of room
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
self.url + "?room_id=%s" % self.room_id1,
|
self.url + "?room_id=%s" % self.room_id1,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -176,7 +172,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
Testing list of reported events with a filter of user
|
Testing list of reported events with a filter of user
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
self.url + "?user_id=%s" % self.other_user,
|
self.url + "?user_id=%s" % self.other_user,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -196,7 +192,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
Testing list of reported events with a filter of user and room
|
Testing list of reported events with a filter of user and room
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
self.url + "?user_id=%s&room_id=%s" % (self.other_user, self.room_id1),
|
self.url + "?user_id=%s&room_id=%s" % (self.other_user, self.room_id1),
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -218,7 +214,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# fetch the most recent first, largest timestamp
|
# fetch the most recent first, largest timestamp
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?dir=b", access_token=self.admin_user_tok,
|
"GET", self.url + "?dir=b", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -234,7 +230,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
report += 1
|
report += 1
|
||||||
|
|
||||||
# fetch the oldest first, smallest timestamp
|
# fetch the oldest first, smallest timestamp
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?dir=f", access_token=self.admin_user_tok,
|
"GET", self.url + "?dir=f", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -254,7 +250,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
Testing that a invalid search order returns a 400
|
Testing that a invalid search order returns a 400
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?dir=bar", access_token=self.admin_user_tok,
|
"GET", self.url + "?dir=bar", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -267,7 +263,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
Testing that a negative limit parameter returns a 400
|
Testing that a negative limit parameter returns a 400
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=-5", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=-5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -279,7 +275,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
Testing that a negative from parameter returns a 400
|
Testing that a negative from parameter returns a 400
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=-5", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=-5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -293,7 +289,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# `next_token` does not appear
|
# `next_token` does not appear
|
||||||
# Number of results is the number of entries
|
# Number of results is the number of entries
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=20", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=20", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -304,7 +300,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# `next_token` does not appear
|
# `next_token` does not appear
|
||||||
# Number of max results is larger than the number of entries
|
# Number of max results is larger than the number of entries
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=21", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=21", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -315,7 +311,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# `next_token` does appear
|
# `next_token` does appear
|
||||||
# Number of max results is smaller than the number of entries
|
# Number of max results is smaller than the number of entries
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=19", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=19", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -327,7 +323,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
# Check
|
# Check
|
||||||
# Set `from` to value of `next_token` for request remaining entries
|
# Set `from` to value of `next_token` for request remaining entries
|
||||||
# `next_token` does not appear
|
# `next_token` does not appear
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=19", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=19", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -342,7 +338,7 @@ class EventReportsTestCase(unittest.HomeserverTestCase):
|
||||||
resp = self.helper.send(room_id, tok=user_tok)
|
resp = self.helper.send(room_id, tok=user_tok)
|
||||||
event_id = resp["event_id"]
|
event_id = resp["event_id"]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"rooms/%s/report/%s" % (room_id, event_id),
|
"rooms/%s/report/%s" % (room_id, event_id),
|
||||||
json.dumps({"score": -100, "reason": "this makes me sad"}),
|
json.dumps({"score": -100, "reason": "this makes me sad"}),
|
||||||
|
@ -399,7 +395,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to get event report without authentication.
|
Try to get event report without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url, b"{}")
|
channel = self.make_request("GET", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -409,9 +405,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
||||||
If the user is not a server admin, an error 403 is returned.
|
If the user is not a server admin, an error 403 is returned.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.other_user_tok,)
|
||||||
"GET", self.url, access_token=self.other_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
@ -421,9 +415,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
||||||
Testing get a reported event
|
Testing get a reported event
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self._check_fields(channel.json_body)
|
self._check_fields(channel.json_body)
|
||||||
|
@ -434,7 +426,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# `report_id` is negative
|
# `report_id` is negative
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_synapse/admin/v1/event_reports/-123",
|
"/_synapse/admin/v1/event_reports/-123",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -448,7 +440,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# `report_id` is a non-numerical string
|
# `report_id` is a non-numerical string
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_synapse/admin/v1/event_reports/abcdef",
|
"/_synapse/admin/v1/event_reports/abcdef",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -462,7 +454,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# `report_id` is undefined
|
# `report_id` is undefined
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_synapse/admin/v1/event_reports/",
|
"/_synapse/admin/v1/event_reports/",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -480,7 +472,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
||||||
Testing that a not existing `report_id` returns a 404.
|
Testing that a not existing `report_id` returns a 404.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_synapse/admin/v1/event_reports/123",
|
"/_synapse/admin/v1/event_reports/123",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -496,7 +488,7 @@ class EventReportDetailTestCase(unittest.HomeserverTestCase):
|
||||||
resp = self.helper.send(room_id, tok=user_tok)
|
resp = self.helper.send(room_id, tok=user_tok)
|
||||||
event_id = resp["event_id"]
|
event_id = resp["event_id"]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"rooms/%s/report/%s" % (room_id, event_id),
|
"rooms/%s/report/%s" % (room_id, event_id),
|
||||||
json.dumps({"score": -100, "reason": "this makes me sad"}),
|
json.dumps({"score": -100, "reason": "this makes me sad"}),
|
||||||
|
|
|
@ -50,7 +50,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/media/%s/%s" % (self.server_name, "12345")
|
url = "/_synapse/admin/v1/media/%s/%s" % (self.server_name, "12345")
|
||||||
|
|
||||||
request, channel = self.make_request("DELETE", url, b"{}")
|
channel = self.make_request("DELETE", url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -64,9 +64,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
url = "/_synapse/admin/v1/media/%s/%s" % (self.server_name, "12345")
|
url = "/_synapse/admin/v1/media/%s/%s" % (self.server_name, "12345")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("DELETE", url, access_token=self.other_user_token,)
|
||||||
"DELETE", url, access_token=self.other_user_token,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
@ -77,9 +75,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/media/%s/%s" % (self.server_name, "12345")
|
url = "/_synapse/admin/v1/media/%s/%s" % (self.server_name, "12345")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("DELETE", url, access_token=self.admin_user_tok,)
|
||||||
"DELETE", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||||
|
@ -90,9 +86,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/media/%s/%s" % ("unknown_domain", "12345")
|
url = "/_synapse/admin/v1/media/%s/%s" % ("unknown_domain", "12345")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("DELETE", url, access_token=self.admin_user_tok,)
|
||||||
"DELETE", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only delete local media", channel.json_body["error"])
|
self.assertEqual("Can only delete local media", channel.json_body["error"])
|
||||||
|
@ -121,7 +115,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(server_name, self.server_name)
|
self.assertEqual(server_name, self.server_name)
|
||||||
|
|
||||||
# Attempt to access media
|
# Attempt to access media
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(download_resource),
|
FakeSite(download_resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -146,9 +140,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_synapse/admin/v1/media/%s/%s" % (self.server_name, media_id)
|
url = "/_synapse/admin/v1/media/%s/%s" % (self.server_name, media_id)
|
||||||
|
|
||||||
# Delete media
|
# Delete media
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("DELETE", url, access_token=self.admin_user_tok,)
|
||||||
"DELETE", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(1, channel.json_body["total"])
|
self.assertEqual(1, channel.json_body["total"])
|
||||||
|
@ -157,7 +149,7 @@ class DeleteMediaByIDTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Attempt to access media
|
# Attempt to access media
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(download_resource),
|
FakeSite(download_resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -204,7 +196,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
Try to delete media without authentication.
|
Try to delete media without authentication.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request("POST", self.url, b"{}")
|
channel = self.make_request("POST", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -216,7 +208,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
self.other_user = self.register_user("user", "pass")
|
self.other_user = self.register_user("user", "pass")
|
||||||
self.other_user_token = self.login("user", "pass")
|
self.other_user_token = self.login("user", "pass")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", self.url, access_token=self.other_user_token,
|
"POST", self.url, access_token=self.other_user_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -229,7 +221,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/media/%s/delete" % "unknown_domain"
|
url = "/_synapse/admin/v1/media/%s/delete" % "unknown_domain"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", url + "?before_ts=1234", access_token=self.admin_user_tok,
|
"POST", url + "?before_ts=1234", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -240,9 +232,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
If the parameter `before_ts` is missing, an error is returned.
|
If the parameter `before_ts` is missing, an error is returned.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("POST", self.url, access_token=self.admin_user_tok,)
|
||||||
"POST", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_PARAM, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_PARAM, channel.json_body["errcode"])
|
||||||
|
@ -254,7 +244,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
If parameters are invalid, an error is returned.
|
If parameters are invalid, an error is returned.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", self.url + "?before_ts=-1234", access_token=self.admin_user_tok,
|
"POST", self.url + "?before_ts=-1234", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -265,7 +255,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
channel.json_body["error"],
|
channel.json_body["error"],
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=1234&size_gt=-1234",
|
self.url + "?before_ts=1234&size_gt=-1234",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -278,7 +268,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
channel.json_body["error"],
|
channel.json_body["error"],
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=1234&keep_profiles=not_bool",
|
self.url + "?before_ts=1234&keep_profiles=not_bool",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -308,7 +298,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# timestamp after upload/create
|
# timestamp after upload/create
|
||||||
now_ms = self.clock.time_msec()
|
now_ms = self.clock.time_msec()
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=" + str(now_ms),
|
self.url + "?before_ts=" + str(now_ms),
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -332,7 +322,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self._access_media(server_and_media_id)
|
self._access_media(server_and_media_id)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=" + str(now_ms),
|
self.url + "?before_ts=" + str(now_ms),
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -344,7 +334,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# timestamp after upload
|
# timestamp after upload
|
||||||
now_ms = self.clock.time_msec()
|
now_ms = self.clock.time_msec()
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=" + str(now_ms),
|
self.url + "?before_ts=" + str(now_ms),
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -367,7 +357,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
self._access_media(server_and_media_id)
|
self._access_media(server_and_media_id)
|
||||||
|
|
||||||
now_ms = self.clock.time_msec()
|
now_ms = self.clock.time_msec()
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=" + str(now_ms) + "&size_gt=67",
|
self.url + "?before_ts=" + str(now_ms) + "&size_gt=67",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -378,7 +368,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
self._access_media(server_and_media_id)
|
self._access_media(server_and_media_id)
|
||||||
|
|
||||||
now_ms = self.clock.time_msec()
|
now_ms = self.clock.time_msec()
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=" + str(now_ms) + "&size_gt=66",
|
self.url + "?before_ts=" + str(now_ms) + "&size_gt=66",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -401,7 +391,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
self._access_media(server_and_media_id)
|
self._access_media(server_and_media_id)
|
||||||
|
|
||||||
# set media as avatar
|
# set media as avatar
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/profile/%s/avatar_url" % (self.admin_user,),
|
"/profile/%s/avatar_url" % (self.admin_user,),
|
||||||
content=json.dumps({"avatar_url": "mxc://%s" % (server_and_media_id,)}),
|
content=json.dumps({"avatar_url": "mxc://%s" % (server_and_media_id,)}),
|
||||||
|
@ -410,7 +400,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
|
||||||
now_ms = self.clock.time_msec()
|
now_ms = self.clock.time_msec()
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=true",
|
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=true",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -421,7 +411,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
self._access_media(server_and_media_id)
|
self._access_media(server_and_media_id)
|
||||||
|
|
||||||
now_ms = self.clock.time_msec()
|
now_ms = self.clock.time_msec()
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=false",
|
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=false",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -445,7 +435,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# set media as room avatar
|
# set media as room avatar
|
||||||
room_id = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
|
room_id = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/state/m.room.avatar" % (room_id,),
|
"/rooms/%s/state/m.room.avatar" % (room_id,),
|
||||||
content=json.dumps({"url": "mxc://%s" % (server_and_media_id,)}),
|
content=json.dumps({"url": "mxc://%s" % (server_and_media_id,)}),
|
||||||
|
@ -454,7 +444,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
|
||||||
now_ms = self.clock.time_msec()
|
now_ms = self.clock.time_msec()
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=true",
|
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=true",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -465,7 +455,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
self._access_media(server_and_media_id)
|
self._access_media(server_and_media_id)
|
||||||
|
|
||||||
now_ms = self.clock.time_msec()
|
now_ms = self.clock.time_msec()
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=false",
|
self.url + "?before_ts=" + str(now_ms) + "&keep_profiles=false",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -512,7 +502,7 @@ class DeleteMediaByDateSizeTestCase(unittest.HomeserverTestCase):
|
||||||
media_id = server_and_media_id.split("/")[1]
|
media_id = server_and_media_id.split("/")[1]
|
||||||
local_path = self.filepaths.local_media_filepath(media_id)
|
local_path = self.filepaths.local_media_filepath(media_id)
|
||||||
|
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(download_resource),
|
FakeSite(download_resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
|
|
@ -79,7 +79,7 @@ class ShutdownRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Test that the admin can still send shutdown
|
# Test that the admin can still send shutdown
|
||||||
url = "/_synapse/admin/v1/shutdown_room/" + room_id
|
url = "/_synapse/admin/v1/shutdown_room/" + room_id
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url.encode("ascii"),
|
url.encode("ascii"),
|
||||||
json.dumps({"new_room_user_id": self.admin_user}),
|
json.dumps({"new_room_user_id": self.admin_user}),
|
||||||
|
@ -103,7 +103,7 @@ class ShutdownRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Enable world readable
|
# Enable world readable
|
||||||
url = "rooms/%s/state/m.room.history_visibility" % (room_id,)
|
url = "rooms/%s/state/m.room.history_visibility" % (room_id,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url.encode("ascii"),
|
url.encode("ascii"),
|
||||||
json.dumps({"history_visibility": "world_readable"}),
|
json.dumps({"history_visibility": "world_readable"}),
|
||||||
|
@ -113,7 +113,7 @@ class ShutdownRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Test that the admin can still send shutdown
|
# Test that the admin can still send shutdown
|
||||||
url = "/_synapse/admin/v1/shutdown_room/" + room_id
|
url = "/_synapse/admin/v1/shutdown_room/" + room_id
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url.encode("ascii"),
|
url.encode("ascii"),
|
||||||
json.dumps({"new_room_user_id": self.admin_user}),
|
json.dumps({"new_room_user_id": self.admin_user}),
|
||||||
|
@ -130,7 +130,7 @@ class ShutdownRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
url = "rooms/%s/initialSync" % (room_id,)
|
url = "rooms/%s/initialSync" % (room_id,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -138,7 +138,7 @@ class ShutdownRoomTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
url = "events?timeout=0&room_id=" + room_id
|
url = "events?timeout=0&room_id=" + room_id
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -184,7 +184,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
If the user is not a server admin, an error 403 is returned.
|
If the user is not a server admin, an error 403 is returned.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", self.url, json.dumps({}), access_token=self.other_user_tok,
|
"POST", self.url, json.dumps({}), access_token=self.other_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/rooms/!unknown:test/delete"
|
url = "/_synapse/admin/v1/rooms/!unknown:test/delete"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", url, json.dumps({}), access_token=self.admin_user_tok,
|
"POST", url, json.dumps({}), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/rooms/invalidroom/delete"
|
url = "/_synapse/admin/v1/rooms/invalidroom/delete"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", url, json.dumps({}), access_token=self.admin_user_tok,
|
"POST", url, json.dumps({}), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
body = json.dumps({"new_room_user_id": "@unknown:test"})
|
body = json.dumps({"new_room_user_id": "@unknown:test"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -244,7 +244,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
body = json.dumps({"new_room_user_id": "@not:exist.bla"})
|
body = json.dumps({"new_room_user_id": "@not:exist.bla"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -262,7 +262,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
body = json.dumps({"block": "NotBool"})
|
body = json.dumps({"block": "NotBool"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -278,7 +278,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
body = json.dumps({"purge": "NotBool"})
|
body = json.dumps({"purge": "NotBool"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -304,7 +304,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
body = json.dumps({"block": True, "purge": True})
|
body = json.dumps({"block": True, "purge": True})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url.encode("ascii"),
|
self.url.encode("ascii"),
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -337,7 +337,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
body = json.dumps({"block": False, "purge": True})
|
body = json.dumps({"block": False, "purge": True})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url.encode("ascii"),
|
self.url.encode("ascii"),
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -371,7 +371,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
body = json.dumps({"block": False, "purge": False})
|
body = json.dumps({"block": False, "purge": False})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url.encode("ascii"),
|
self.url.encode("ascii"),
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -418,7 +418,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Test that the admin can still send shutdown
|
# Test that the admin can still send shutdown
|
||||||
url = "/_synapse/admin/v1/rooms/%s/delete" % self.room_id
|
url = "/_synapse/admin/v1/rooms/%s/delete" % self.room_id
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url.encode("ascii"),
|
url.encode("ascii"),
|
||||||
json.dumps({"new_room_user_id": self.admin_user}),
|
json.dumps({"new_room_user_id": self.admin_user}),
|
||||||
|
@ -448,7 +448,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Enable world readable
|
# Enable world readable
|
||||||
url = "rooms/%s/state/m.room.history_visibility" % (self.room_id,)
|
url = "rooms/%s/state/m.room.history_visibility" % (self.room_id,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url.encode("ascii"),
|
url.encode("ascii"),
|
||||||
json.dumps({"history_visibility": "world_readable"}),
|
json.dumps({"history_visibility": "world_readable"}),
|
||||||
|
@ -465,7 +465,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Test that the admin can still send shutdown
|
# Test that the admin can still send shutdown
|
||||||
url = "/_synapse/admin/v1/rooms/%s/delete" % self.room_id
|
url = "/_synapse/admin/v1/rooms/%s/delete" % self.room_id
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url.encode("ascii"),
|
url.encode("ascii"),
|
||||||
json.dumps({"new_room_user_id": self.admin_user}),
|
json.dumps({"new_room_user_id": self.admin_user}),
|
||||||
|
@ -530,7 +530,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
url = "rooms/%s/initialSync" % (room_id,)
|
url = "rooms/%s/initialSync" % (room_id,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -538,7 +538,7 @@ class DeleteRoomTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
url = "events?timeout=0&room_id=" + room_id
|
url = "events?timeout=0&room_id=" + room_id
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -569,7 +569,7 @@ class PurgeRoomTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.leave(room_id, user=self.admin_user, tok=self.admin_user_tok)
|
self.helper.leave(room_id, user=self.admin_user, tok=self.admin_user_tok)
|
||||||
|
|
||||||
url = "/_synapse/admin/v1/purge_room"
|
url = "/_synapse/admin/v1/purge_room"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url.encode("ascii"),
|
url.encode("ascii"),
|
||||||
{"room_id": room_id},
|
{"room_id": room_id},
|
||||||
|
@ -623,7 +623,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Request the list of rooms
|
# Request the list of rooms
|
||||||
url = "/_synapse/admin/v1/rooms"
|
url = "/_synapse/admin/v1/rooms"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -704,7 +704,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
limit,
|
limit,
|
||||||
"name",
|
"name",
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -744,7 +744,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(room_ids, returned_room_ids)
|
self.assertEqual(room_ids, returned_room_ids)
|
||||||
|
|
||||||
url = "/_synapse/admin/v1/rooms?from=%d&limit=%d" % (start, limit)
|
url = "/_synapse/admin/v1/rooms?from=%d&limit=%d" % (start, limit)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -764,7 +764,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Create a new alias to this room
|
# Create a new alias to this room
|
||||||
url = "/_matrix/client/r0/directory/room/%s" % (urllib.parse.quote(test_alias),)
|
url = "/_matrix/client/r0/directory/room/%s" % (urllib.parse.quote(test_alias),)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url.encode("ascii"),
|
url.encode("ascii"),
|
||||||
{"room_id": room_id},
|
{"room_id": room_id},
|
||||||
|
@ -794,7 +794,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Request the list of rooms
|
# Request the list of rooms
|
||||||
url = "/_synapse/admin/v1/rooms"
|
url = "/_synapse/admin/v1/rooms"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -835,7 +835,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_matrix/client/r0/directory/room/%s" % (
|
url = "/_matrix/client/r0/directory/room/%s" % (
|
||||||
urllib.parse.quote(test_alias),
|
urllib.parse.quote(test_alias),
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url.encode("ascii"),
|
url.encode("ascii"),
|
||||||
{"room_id": room_id},
|
{"room_id": room_id},
|
||||||
|
@ -875,7 +875,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_synapse/admin/v1/rooms?order_by=%s" % (order_type,)
|
url = "/_synapse/admin/v1/rooms?order_by=%s" % (order_type,)
|
||||||
if reverse:
|
if reverse:
|
||||||
url += "&dir=b"
|
url += "&dir=b"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
@ -1011,7 +1011,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
expected_http_code: The expected http code for the request
|
expected_http_code: The expected http code for the request
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/rooms?search_term=%s" % (search_term,)
|
url = "/_synapse/admin/v1/rooms?search_term=%s" % (search_term,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(expected_http_code, channel.code, msg=channel.json_body)
|
self.assertEqual(expected_http_code, channel.code, msg=channel.json_body)
|
||||||
|
@ -1072,7 +1072,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
@ -1102,7 +1102,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
room_id_1 = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
|
room_id_1 = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
|
||||||
|
|
||||||
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
@ -1114,7 +1114,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.join(room_id_1, user_1, tok=user_tok_1)
|
self.helper.join(room_id_1, user_1, tok=user_tok_1)
|
||||||
|
|
||||||
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
@ -1124,7 +1124,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.leave(room_id_1, self.admin_user, tok=self.admin_user_tok)
|
self.helper.leave(room_id_1, self.admin_user, tok=self.admin_user_tok)
|
||||||
self.helper.leave(room_id_1, user_1, tok=user_tok_1)
|
self.helper.leave(room_id_1, user_1, tok=user_tok_1)
|
||||||
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
url = "/_synapse/admin/v1/rooms/%s" % (room_id_1,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
@ -1153,7 +1153,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.join(room_id_2, user_3, tok=user_tok_3)
|
self.helper.join(room_id_2, user_3, tok=user_tok_3)
|
||||||
|
|
||||||
url = "/_synapse/admin/v1/rooms/%s/members" % (room_id_1,)
|
url = "/_synapse/admin/v1/rooms/%s/members" % (room_id_1,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
@ -1164,7 +1164,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(channel.json_body["total"], 3)
|
self.assertEqual(channel.json_body["total"], 3)
|
||||||
|
|
||||||
url = "/_synapse/admin/v1/rooms/%s/members" % (room_id_2,)
|
url = "/_synapse/admin/v1/rooms/%s/members" % (room_id_2,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
@ -1204,7 +1204,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
body = json.dumps({"user_id": self.second_user_id})
|
body = json.dumps({"user_id": self.second_user_id})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -1220,7 +1220,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
body = json.dumps({"unknown_parameter": "@unknown:test"})
|
body = json.dumps({"unknown_parameter": "@unknown:test"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -1236,7 +1236,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
body = json.dumps({"user_id": "@unknown:test"})
|
body = json.dumps({"user_id": "@unknown:test"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -1252,7 +1252,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
body = json.dumps({"user_id": "@not:exist.bla"})
|
body = json.dumps({"user_id": "@not:exist.bla"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -1272,7 +1272,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
body = json.dumps({"user_id": self.second_user_id})
|
body = json.dumps({"user_id": self.second_user_id})
|
||||||
url = "/_synapse/admin/v1/join/!unknown:test"
|
url = "/_synapse/admin/v1/join/!unknown:test"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url,
|
url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -1289,7 +1289,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
body = json.dumps({"user_id": self.second_user_id})
|
body = json.dumps({"user_id": self.second_user_id})
|
||||||
url = "/_synapse/admin/v1/join/invalidroom"
|
url = "/_synapse/admin/v1/join/invalidroom"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url,
|
url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -1308,7 +1308,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
body = json.dumps({"user_id": self.second_user_id})
|
body = json.dumps({"user_id": self.second_user_id})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
self.url,
|
self.url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -1320,7 +1320,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Validate if user is a member of the room
|
# Validate if user is a member of the room
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.second_tok,
|
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.second_tok,
|
||||||
)
|
)
|
||||||
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -1337,7 +1337,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_synapse/admin/v1/join/{}".format(private_room_id)
|
url = "/_synapse/admin/v1/join/{}".format(private_room_id)
|
||||||
body = json.dumps({"user_id": self.second_user_id})
|
body = json.dumps({"user_id": self.second_user_id})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url,
|
url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -1367,7 +1367,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Validate if server admin is a member of the room
|
# Validate if server admin is a member of the room
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.admin_user_tok,
|
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -1378,7 +1378,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_synapse/admin/v1/join/{}".format(private_room_id)
|
url = "/_synapse/admin/v1/join/{}".format(private_room_id)
|
||||||
body = json.dumps({"user_id": self.second_user_id})
|
body = json.dumps({"user_id": self.second_user_id})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url,
|
url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -1389,7 +1389,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Validate if user is a member of the room
|
# Validate if user is a member of the room
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.second_tok,
|
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.second_tok,
|
||||||
)
|
)
|
||||||
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -1406,7 +1406,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_synapse/admin/v1/join/{}".format(private_room_id)
|
url = "/_synapse/admin/v1/join/{}".format(private_room_id)
|
||||||
body = json.dumps({"user_id": self.second_user_id})
|
body = json.dumps({"user_id": self.second_user_id})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
url,
|
url,
|
||||||
content=body.encode(encoding="utf_8"),
|
content=body.encode(encoding="utf_8"),
|
||||||
|
@ -1418,7 +1418,7 @@ class JoinAliasRoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Validate if user is a member of the room
|
# Validate if user is a member of the room
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.second_tok,
|
"GET", "/_matrix/client/r0/joined_rooms", access_token=self.second_tok,
|
||||||
)
|
)
|
||||||
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEquals(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
|
@ -46,7 +46,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to list users without authentication.
|
Try to list users without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url, b"{}")
|
channel = self.make_request("GET", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -55,7 +55,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
If the user is not a server admin, an error 403 is returned.
|
If the user is not a server admin, an error 403 is returned.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url, json.dumps({}), access_token=self.other_user_tok,
|
"GET", self.url, json.dumps({}), access_token=self.other_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
If parameters are invalid, an error is returned.
|
If parameters are invalid, an error is returned.
|
||||||
"""
|
"""
|
||||||
# unkown order_by
|
# unkown order_by
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?order_by=bar", access_token=self.admin_user_tok,
|
"GET", self.url + "?order_by=bar", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
||||||
|
|
||||||
# negative from
|
# negative from
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=-5", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=-5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
||||||
|
|
||||||
# negative limit
|
# negative limit
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=-5", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=-5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
||||||
|
|
||||||
# negative from_ts
|
# negative from_ts
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from_ts=-1234", access_token=self.admin_user_tok,
|
"GET", self.url + "?from_ts=-1234", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
||||||
|
|
||||||
# negative until_ts
|
# negative until_ts
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?until_ts=-1234", access_token=self.admin_user_tok,
|
"GET", self.url + "?until_ts=-1234", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
||||||
|
|
||||||
# until_ts smaller from_ts
|
# until_ts smaller from_ts
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
self.url + "?from_ts=10&until_ts=5",
|
self.url + "?from_ts=10&until_ts=5",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -117,7 +117,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
||||||
|
|
||||||
# empty search term
|
# empty search term
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?search_term=", access_token=self.admin_user_tok,
|
"GET", self.url + "?search_term=", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
self.assertEqual(Codes.INVALID_PARAM, channel.json_body["errcode"])
|
||||||
|
|
||||||
# invalid search order
|
# invalid search order
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?dir=bar", access_token=self.admin_user_tok,
|
"GET", self.url + "?dir=bar", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
self._create_users_with_media(10, 2)
|
self._create_users_with_media(10, 2)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=5", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
self._create_users_with_media(20, 2)
|
self._create_users_with_media(20, 2)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=5", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
self._create_users_with_media(20, 2)
|
self._create_users_with_media(20, 2)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=5&limit=10", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=5&limit=10", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# `next_token` does not appear
|
# `next_token` does not appear
|
||||||
# Number of results is the number of entries
|
# Number of results is the number of entries
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=20", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=20", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# `next_token` does not appear
|
# `next_token` does not appear
|
||||||
# Number of max results is larger than the number of entries
|
# Number of max results is larger than the number of entries
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=21", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=21", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# `next_token` does appear
|
# `next_token` does appear
|
||||||
# Number of max results is smaller than the number of entries
|
# Number of max results is smaller than the number of entries
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=19", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=19", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Set `from` to value of `next_token` for request remaining entries
|
# Set `from` to value of `next_token` for request remaining entries
|
||||||
# Check `next_token` does not appear
|
# Check `next_token` does not appear
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=19", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=19", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -238,9 +238,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
if users have no media created
|
if users have no media created
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(0, channel.json_body["total"])
|
self.assertEqual(0, channel.json_body["total"])
|
||||||
|
@ -316,15 +314,13 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
ts1 = self.clock.time_msec()
|
ts1 = self.clock.time_msec()
|
||||||
|
|
||||||
# list all media when filter is not set
|
# list all media when filter is not set
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(channel.json_body["users"][0]["media_count"], 3)
|
self.assertEqual(channel.json_body["users"][0]["media_count"], 3)
|
||||||
|
|
||||||
# filter media starting at `ts1` after creating first media
|
# filter media starting at `ts1` after creating first media
|
||||||
# result is 0
|
# result is 0
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from_ts=%s" % (ts1,), access_token=self.admin_user_tok,
|
"GET", self.url + "?from_ts=%s" % (ts1,), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -337,7 +333,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self._create_media(self.other_user_tok, 3)
|
self._create_media(self.other_user_tok, 3)
|
||||||
|
|
||||||
# filter media between `ts1` and `ts2`
|
# filter media between `ts1` and `ts2`
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
self.url + "?from_ts=%s&until_ts=%s" % (ts1, ts2),
|
self.url + "?from_ts=%s&until_ts=%s" % (ts1, ts2),
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -346,7 +342,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(channel.json_body["users"][0]["media_count"], 3)
|
self.assertEqual(channel.json_body["users"][0]["media_count"], 3)
|
||||||
|
|
||||||
# filter media until `ts2` and earlier
|
# filter media until `ts2` and earlier
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?until_ts=%s" % (ts2,), access_token=self.admin_user_tok,
|
"GET", self.url + "?until_ts=%s" % (ts2,), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -356,14 +352,12 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self._create_users_with_media(20, 1)
|
self._create_users_with_media(20, 1)
|
||||||
|
|
||||||
# check without filter get all users
|
# check without filter get all users
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(channel.json_body["total"], 20)
|
self.assertEqual(channel.json_body["total"], 20)
|
||||||
|
|
||||||
# filter user 1 and 10-19 by `user_id`
|
# filter user 1 and 10-19 by `user_id`
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
self.url + "?search_term=foo_user_1",
|
self.url + "?search_term=foo_user_1",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -372,7 +366,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(channel.json_body["total"], 11)
|
self.assertEqual(channel.json_body["total"], 11)
|
||||||
|
|
||||||
# filter on this user in `displayname`
|
# filter on this user in `displayname`
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
self.url + "?search_term=bar_user_10",
|
self.url + "?search_term=bar_user_10",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -382,7 +376,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(channel.json_body["total"], 1)
|
self.assertEqual(channel.json_body["total"], 1)
|
||||||
|
|
||||||
# filter and get empty result
|
# filter and get empty result
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?search_term=foobar", access_token=self.admin_user_tok,
|
"GET", self.url + "?search_term=foobar", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -447,7 +441,7 @@ class UserMediaStatisticsTestCase(unittest.HomeserverTestCase):
|
||||||
url = self.url + "?order_by=%s" % (order_type,)
|
url = self.url + "?order_by=%s" % (order_type,)
|
||||||
if dir is not None and dir in ("b", "f"):
|
if dir is not None and dir in ("b", "f"):
|
||||||
url += "&dir=%s" % (dir,)
|
url += "&dir=%s" % (dir,)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
"GET", url.encode("ascii"), access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
|
|
|
@ -70,7 +70,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
self.hs.config.registration_shared_secret = None
|
self.hs.config.registration_shared_secret = None
|
||||||
|
|
||||||
request, channel = self.make_request("POST", self.url, b"{}")
|
channel = self.make_request("POST", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -87,7 +87,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self.hs.get_secrets = Mock(return_value=secrets)
|
self.hs.get_secrets = Mock(return_value=secrets)
|
||||||
|
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
|
|
||||||
self.assertEqual(channel.json_body, {"nonce": "abcd"})
|
self.assertEqual(channel.json_body, {"nonce": "abcd"})
|
||||||
|
|
||||||
|
@ -96,14 +96,14 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
Calling GET on the endpoint will return a randomised nonce, which will
|
Calling GET on the endpoint will return a randomised nonce, which will
|
||||||
only last for SALT_TIMEOUT (60s).
|
only last for SALT_TIMEOUT (60s).
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
nonce = channel.json_body["nonce"]
|
nonce = channel.json_body["nonce"]
|
||||||
|
|
||||||
# 59 seconds
|
# 59 seconds
|
||||||
self.reactor.advance(59)
|
self.reactor.advance(59)
|
||||||
|
|
||||||
body = json.dumps({"nonce": nonce})
|
body = json.dumps({"nonce": nonce})
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("username must be specified", channel.json_body["error"])
|
self.assertEqual("username must be specified", channel.json_body["error"])
|
||||||
|
@ -111,7 +111,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
# 61 seconds
|
# 61 seconds
|
||||||
self.reactor.advance(2)
|
self.reactor.advance(2)
|
||||||
|
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("unrecognised nonce", channel.json_body["error"])
|
self.assertEqual("unrecognised nonce", channel.json_body["error"])
|
||||||
|
@ -120,7 +120,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Only the provided nonce can be used, as it's checked in the MAC.
|
Only the provided nonce can be used, as it's checked in the MAC.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
nonce = channel.json_body["nonce"]
|
nonce = channel.json_body["nonce"]
|
||||||
|
|
||||||
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
||||||
|
@ -136,7 +136,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"mac": want_mac,
|
"mac": want_mac,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("HMAC incorrect", channel.json_body["error"])
|
self.assertEqual("HMAC incorrect", channel.json_body["error"])
|
||||||
|
@ -146,7 +146,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
When the correct nonce is provided, and the right key is provided, the
|
When the correct nonce is provided, and the right key is provided, the
|
||||||
user is registered.
|
user is registered.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
nonce = channel.json_body["nonce"]
|
nonce = channel.json_body["nonce"]
|
||||||
|
|
||||||
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
||||||
|
@ -165,7 +165,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"mac": want_mac,
|
"mac": want_mac,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob:test", channel.json_body["user_id"])
|
self.assertEqual("@bob:test", channel.json_body["user_id"])
|
||||||
|
@ -174,7 +174,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
A valid unrecognised nonce.
|
A valid unrecognised nonce.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
nonce = channel.json_body["nonce"]
|
nonce = channel.json_body["nonce"]
|
||||||
|
|
||||||
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
||||||
|
@ -190,13 +190,13 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"mac": want_mac,
|
"mac": want_mac,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob:test", channel.json_body["user_id"])
|
self.assertEqual("@bob:test", channel.json_body["user_id"])
|
||||||
|
|
||||||
# Now, try and reuse it
|
# Now, try and reuse it
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("unrecognised nonce", channel.json_body["error"])
|
self.assertEqual("unrecognised nonce", channel.json_body["error"])
|
||||||
|
@ -209,7 +209,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def nonce():
|
def nonce():
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
return channel.json_body["nonce"]
|
return channel.json_body["nonce"]
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -218,7 +218,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Must be present
|
# Must be present
|
||||||
body = json.dumps({})
|
body = json.dumps({})
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("nonce must be specified", channel.json_body["error"])
|
self.assertEqual("nonce must be specified", channel.json_body["error"])
|
||||||
|
@ -229,28 +229,28 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Must be present
|
# Must be present
|
||||||
body = json.dumps({"nonce": nonce()})
|
body = json.dumps({"nonce": nonce()})
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("username must be specified", channel.json_body["error"])
|
self.assertEqual("username must be specified", channel.json_body["error"])
|
||||||
|
|
||||||
# Must be a string
|
# Must be a string
|
||||||
body = json.dumps({"nonce": nonce(), "username": 1234})
|
body = json.dumps({"nonce": nonce(), "username": 1234})
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("Invalid username", channel.json_body["error"])
|
self.assertEqual("Invalid username", channel.json_body["error"])
|
||||||
|
|
||||||
# Must not have null bytes
|
# Must not have null bytes
|
||||||
body = json.dumps({"nonce": nonce(), "username": "abcd\u0000"})
|
body = json.dumps({"nonce": nonce(), "username": "abcd\u0000"})
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("Invalid username", channel.json_body["error"])
|
self.assertEqual("Invalid username", channel.json_body["error"])
|
||||||
|
|
||||||
# Must not have null bytes
|
# Must not have null bytes
|
||||||
body = json.dumps({"nonce": nonce(), "username": "a" * 1000})
|
body = json.dumps({"nonce": nonce(), "username": "a" * 1000})
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("Invalid username", channel.json_body["error"])
|
self.assertEqual("Invalid username", channel.json_body["error"])
|
||||||
|
@ -261,28 +261,28 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Must be present
|
# Must be present
|
||||||
body = json.dumps({"nonce": nonce(), "username": "a"})
|
body = json.dumps({"nonce": nonce(), "username": "a"})
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("password must be specified", channel.json_body["error"])
|
self.assertEqual("password must be specified", channel.json_body["error"])
|
||||||
|
|
||||||
# Must be a string
|
# Must be a string
|
||||||
body = json.dumps({"nonce": nonce(), "username": "a", "password": 1234})
|
body = json.dumps({"nonce": nonce(), "username": "a", "password": 1234})
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("Invalid password", channel.json_body["error"])
|
self.assertEqual("Invalid password", channel.json_body["error"])
|
||||||
|
|
||||||
# Must not have null bytes
|
# Must not have null bytes
|
||||||
body = json.dumps({"nonce": nonce(), "username": "a", "password": "abcd\u0000"})
|
body = json.dumps({"nonce": nonce(), "username": "a", "password": "abcd\u0000"})
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("Invalid password", channel.json_body["error"])
|
self.assertEqual("Invalid password", channel.json_body["error"])
|
||||||
|
|
||||||
# Super long
|
# Super long
|
||||||
body = json.dumps({"nonce": nonce(), "username": "a", "password": "A" * 1000})
|
body = json.dumps({"nonce": nonce(), "username": "a", "password": "A" * 1000})
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("Invalid password", channel.json_body["error"])
|
self.assertEqual("Invalid password", channel.json_body["error"])
|
||||||
|
@ -300,7 +300,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"user_type": "invalid",
|
"user_type": "invalid",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("Invalid user type", channel.json_body["error"])
|
self.assertEqual("Invalid user type", channel.json_body["error"])
|
||||||
|
@ -311,7 +311,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# set no displayname
|
# set no displayname
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
nonce = channel.json_body["nonce"]
|
nonce = channel.json_body["nonce"]
|
||||||
|
|
||||||
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
||||||
|
@ -321,17 +321,17 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
body = json.dumps(
|
body = json.dumps(
|
||||||
{"nonce": nonce, "username": "bob1", "password": "abc123", "mac": want_mac}
|
{"nonce": nonce, "username": "bob1", "password": "abc123", "mac": want_mac}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob1:test", channel.json_body["user_id"])
|
self.assertEqual("@bob1:test", channel.json_body["user_id"])
|
||||||
|
|
||||||
request, channel = self.make_request("GET", "/profile/@bob1:test/displayname")
|
channel = self.make_request("GET", "/profile/@bob1:test/displayname")
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("bob1", channel.json_body["displayname"])
|
self.assertEqual("bob1", channel.json_body["displayname"])
|
||||||
|
|
||||||
# displayname is None
|
# displayname is None
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
nonce = channel.json_body["nonce"]
|
nonce = channel.json_body["nonce"]
|
||||||
|
|
||||||
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
||||||
|
@ -347,17 +347,17 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"mac": want_mac,
|
"mac": want_mac,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob2:test", channel.json_body["user_id"])
|
self.assertEqual("@bob2:test", channel.json_body["user_id"])
|
||||||
|
|
||||||
request, channel = self.make_request("GET", "/profile/@bob2:test/displayname")
|
channel = self.make_request("GET", "/profile/@bob2:test/displayname")
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("bob2", channel.json_body["displayname"])
|
self.assertEqual("bob2", channel.json_body["displayname"])
|
||||||
|
|
||||||
# displayname is empty
|
# displayname is empty
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
nonce = channel.json_body["nonce"]
|
nonce = channel.json_body["nonce"]
|
||||||
|
|
||||||
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
||||||
|
@ -373,16 +373,16 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"mac": want_mac,
|
"mac": want_mac,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob3:test", channel.json_body["user_id"])
|
self.assertEqual("@bob3:test", channel.json_body["user_id"])
|
||||||
|
|
||||||
request, channel = self.make_request("GET", "/profile/@bob3:test/displayname")
|
channel = self.make_request("GET", "/profile/@bob3:test/displayname")
|
||||||
self.assertEqual(404, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(404, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# set displayname
|
# set displayname
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
nonce = channel.json_body["nonce"]
|
nonce = channel.json_body["nonce"]
|
||||||
|
|
||||||
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
||||||
|
@ -398,12 +398,12 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"mac": want_mac,
|
"mac": want_mac,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob4:test", channel.json_body["user_id"])
|
self.assertEqual("@bob4:test", channel.json_body["user_id"])
|
||||||
|
|
||||||
request, channel = self.make_request("GET", "/profile/@bob4:test/displayname")
|
channel = self.make_request("GET", "/profile/@bob4:test/displayname")
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("Bob's Name", channel.json_body["displayname"])
|
self.assertEqual("Bob's Name", channel.json_body["displayname"])
|
||||||
|
|
||||||
|
@ -429,7 +429,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Register new user with admin API
|
# Register new user with admin API
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
nonce = channel.json_body["nonce"]
|
nonce = channel.json_body["nonce"]
|
||||||
|
|
||||||
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
want_mac = hmac.new(key=b"shared", digestmod=hashlib.sha1)
|
||||||
|
@ -448,7 +448,7 @@ class UserRegisterTestCase(unittest.HomeserverTestCase):
|
||||||
"mac": want_mac,
|
"mac": want_mac,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("POST", self.url, body.encode("utf8"))
|
channel = self.make_request("POST", self.url, body.encode("utf8"))
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob:test", channel.json_body["user_id"])
|
self.assertEqual("@bob:test", channel.json_body["user_id"])
|
||||||
|
@ -473,7 +473,7 @@ class UsersListTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to list users without authentication.
|
Try to list users without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url, b"{}")
|
channel = self.make_request("GET", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("M_MISSING_TOKEN", channel.json_body["errcode"])
|
self.assertEqual("M_MISSING_TOKEN", channel.json_body["errcode"])
|
||||||
|
@ -482,7 +482,7 @@ class UsersListTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
List all users, including deactivated users.
|
List all users, including deactivated users.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
self.url + "?deactivated=true",
|
self.url + "?deactivated=true",
|
||||||
b"{}",
|
b"{}",
|
||||||
|
@ -520,14 +520,12 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v2/users/@bob:test"
|
url = "/_synapse/admin/v2/users/@bob:test"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.other_user_token,)
|
||||||
"GET", url, access_token=self.other_user_token,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("You are not a server admin", channel.json_body["error"])
|
self.assertEqual("You are not a server admin", channel.json_body["error"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", url, access_token=self.other_user_token, content=b"{}",
|
"PUT", url, access_token=self.other_user_token, content=b"{}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -539,7 +537,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
Tests that a lookup for a user that does not exist returns a 404
|
Tests that a lookup for a user that does not exist returns a 404
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_synapse/admin/v2/users/@unknown_person:test",
|
"/_synapse/admin/v2/users/@unknown_person:test",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -565,7 +563,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url,
|
url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -581,9 +579,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual("mxc://fibble/wibble", channel.json_body["avatar_url"])
|
self.assertEqual("mxc://fibble/wibble", channel.json_body["avatar_url"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob:test", channel.json_body["name"])
|
self.assertEqual("@bob:test", channel.json_body["name"])
|
||||||
|
@ -612,7 +608,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url,
|
url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -628,9 +624,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual("mxc://fibble/wibble", channel.json_body["avatar_url"])
|
self.assertEqual("mxc://fibble/wibble", channel.json_body["avatar_url"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob:test", channel.json_body["name"])
|
self.assertEqual("@bob:test", channel.json_body["name"])
|
||||||
|
@ -656,9 +650,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Sync to set admin user to active
|
# Sync to set admin user to active
|
||||||
# before limit of monthly active users is reached
|
# before limit of monthly active users is reached
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "/sync", access_token=self.admin_user_tok)
|
||||||
"GET", "/sync", access_token=self.admin_user_tok
|
|
||||||
)
|
|
||||||
|
|
||||||
if channel.code != 200:
|
if channel.code != 200:
|
||||||
raise HttpResponseException(
|
raise HttpResponseException(
|
||||||
|
@ -681,7 +673,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
# Create user
|
# Create user
|
||||||
body = json.dumps({"password": "abc123", "admin": False})
|
body = json.dumps({"password": "abc123", "admin": False})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url,
|
url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -720,7 +712,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
# Create user
|
# Create user
|
||||||
body = json.dumps({"password": "abc123", "admin": False})
|
body = json.dumps({"password": "abc123", "admin": False})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url,
|
url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -757,7 +749,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url,
|
url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -801,7 +793,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url,
|
url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -827,7 +819,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
# Change password
|
# Change password
|
||||||
body = json.dumps({"password": "hahaha"})
|
body = json.dumps({"password": "hahaha"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
self.url_other_user,
|
self.url_other_user,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -844,7 +836,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
# Modify user
|
# Modify user
|
||||||
body = json.dumps({"displayname": "foobar"})
|
body = json.dumps({"displayname": "foobar"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
self.url_other_user,
|
self.url_other_user,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -856,7 +848,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual("foobar", channel.json_body["displayname"])
|
self.assertEqual("foobar", channel.json_body["displayname"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_other_user, access_token=self.admin_user_tok,
|
"GET", self.url_other_user, access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -874,7 +866,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
{"threepids": [{"medium": "email", "address": "bob3@bob.bob"}]}
|
{"threepids": [{"medium": "email", "address": "bob3@bob.bob"}]}
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
self.url_other_user,
|
self.url_other_user,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -887,7 +879,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual("bob3@bob.bob", channel.json_body["threepids"][0]["address"])
|
self.assertEqual("bob3@bob.bob", channel.json_body["threepids"][0]["address"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_other_user, access_token=self.admin_user_tok,
|
"GET", self.url_other_user, access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -904,7 +896,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
# Deactivate user
|
# Deactivate user
|
||||||
body = json.dumps({"deactivated": True})
|
body = json.dumps({"deactivated": True})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
self.url_other_user,
|
self.url_other_user,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -917,7 +909,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
# the user is deactivated, the threepid will be deleted
|
# the user is deactivated, the threepid will be deleted
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_other_user, access_token=self.admin_user_tok,
|
"GET", self.url_other_user, access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -931,7 +923,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Deactivate the user.
|
# Deactivate the user.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
self.url_other_user,
|
self.url_other_user,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -944,7 +936,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
self._is_erased("@user:test", True)
|
self._is_erased("@user:test", True)
|
||||||
|
|
||||||
# Attempt to reactivate the user (without a password).
|
# Attempt to reactivate the user (without a password).
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
self.url_other_user,
|
self.url_other_user,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -953,7 +945,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# Reactivate the user.
|
# Reactivate the user.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
self.url_other_user,
|
self.url_other_user,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -964,7 +956,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_other_user, access_token=self.admin_user_tok,
|
"GET", self.url_other_user, access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -981,7 +973,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
# Set a user as an admin
|
# Set a user as an admin
|
||||||
body = json.dumps({"admin": True})
|
body = json.dumps({"admin": True})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
self.url_other_user,
|
self.url_other_user,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -993,7 +985,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(True, channel.json_body["admin"])
|
self.assertEqual(True, channel.json_body["admin"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_other_user, access_token=self.admin_user_tok,
|
"GET", self.url_other_user, access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1011,7 +1003,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
# Create user
|
# Create user
|
||||||
body = json.dumps({"password": "abc123"})
|
body = json.dumps({"password": "abc123"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url,
|
url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -1023,9 +1015,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual("bob", channel.json_body["displayname"])
|
self.assertEqual("bob", channel.json_body["displayname"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob:test", channel.json_body["name"])
|
self.assertEqual("@bob:test", channel.json_body["name"])
|
||||||
|
@ -1035,7 +1025,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
# Change password (and use a str for deactivate instead of a bool)
|
# Change password (and use a str for deactivate instead of a bool)
|
||||||
body = json.dumps({"password": "abc123", "deactivated": "false"}) # oops!
|
body = json.dumps({"password": "abc123", "deactivated": "false"}) # oops!
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
url,
|
url,
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
|
@ -1045,9 +1035,7 @@ class UserRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(400, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# Check user is not deactivated
|
# Check user is not deactivated
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual("@bob:test", channel.json_body["name"])
|
self.assertEqual("@bob:test", channel.json_body["name"])
|
||||||
|
@ -1089,7 +1077,7 @@ class UserMembershipRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to list rooms of an user without authentication.
|
Try to list rooms of an user without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url, b"{}")
|
channel = self.make_request("GET", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -1100,9 +1088,7 @@ class UserMembershipRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
other_user_token = self.login("user", "pass")
|
other_user_token = self.login("user", "pass")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=other_user_token,)
|
||||||
"GET", self.url, access_token=other_user_token,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
@ -1112,9 +1098,7 @@ class UserMembershipRestTestCase(unittest.HomeserverTestCase):
|
||||||
Tests that a lookup for a user that does not exist returns a 404
|
Tests that a lookup for a user that does not exist returns a 404
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/users/@unknown_person:test/joined_rooms"
|
url = "/_synapse/admin/v1/users/@unknown_person:test/joined_rooms"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||||
|
@ -1125,9 +1109,7 @@ class UserMembershipRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/users/@unknown_person:unknown_domain/joined_rooms"
|
url = "/_synapse/admin/v1/users/@unknown_person:unknown_domain/joined_rooms"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
||||||
|
@ -1138,9 +1120,7 @@ class UserMembershipRestTestCase(unittest.HomeserverTestCase):
|
||||||
if user has no memberships
|
if user has no memberships
|
||||||
"""
|
"""
|
||||||
# Get rooms
|
# Get rooms
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(0, channel.json_body["total"])
|
self.assertEqual(0, channel.json_body["total"])
|
||||||
|
@ -1157,9 +1137,7 @@ class UserMembershipRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.create_room_as(self.other_user, tok=other_user_tok)
|
self.helper.create_room_as(self.other_user, tok=other_user_tok)
|
||||||
|
|
||||||
# Get rooms
|
# Get rooms
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(number_rooms, channel.json_body["total"])
|
self.assertEqual(number_rooms, channel.json_body["total"])
|
||||||
|
@ -1188,7 +1166,7 @@ class PushersRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to list pushers of an user without authentication.
|
Try to list pushers of an user without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url, b"{}")
|
channel = self.make_request("GET", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -1199,9 +1177,7 @@ class PushersRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
other_user_token = self.login("user", "pass")
|
other_user_token = self.login("user", "pass")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=other_user_token,)
|
||||||
"GET", self.url, access_token=other_user_token,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
@ -1211,9 +1187,7 @@ class PushersRestTestCase(unittest.HomeserverTestCase):
|
||||||
Tests that a lookup for a user that does not exist returns a 404
|
Tests that a lookup for a user that does not exist returns a 404
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/users/@unknown_person:test/pushers"
|
url = "/_synapse/admin/v1/users/@unknown_person:test/pushers"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||||
|
@ -1224,9 +1198,7 @@ class PushersRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/users/@unknown_person:unknown_domain/pushers"
|
url = "/_synapse/admin/v1/users/@unknown_person:unknown_domain/pushers"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
||||||
|
@ -1237,9 +1209,7 @@ class PushersRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Get pushers
|
# Get pushers
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(0, channel.json_body["total"])
|
self.assertEqual(0, channel.json_body["total"])
|
||||||
|
@ -1266,9 +1236,7 @@ class PushersRestTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get pushers
|
# Get pushers
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(1, channel.json_body["total"])
|
self.assertEqual(1, channel.json_body["total"])
|
||||||
|
@ -1307,7 +1275,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to list media of an user without authentication.
|
Try to list media of an user without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url, b"{}")
|
channel = self.make_request("GET", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -1318,9 +1286,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
other_user_token = self.login("user", "pass")
|
other_user_token = self.login("user", "pass")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=other_user_token,)
|
||||||
"GET", self.url, access_token=other_user_token,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
@ -1330,9 +1296,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
Tests that a lookup for a user that does not exist returns a 404
|
Tests that a lookup for a user that does not exist returns a 404
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/users/@unknown_person:test/media"
|
url = "/_synapse/admin/v1/users/@unknown_person:test/media"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(404, channel.code, msg=channel.json_body)
|
self.assertEqual(404, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])
|
||||||
|
@ -1343,9 +1307,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
url = "/_synapse/admin/v1/users/@unknown_person:unknown_domain/media"
|
url = "/_synapse/admin/v1/users/@unknown_person:unknown_domain/media"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url, access_token=self.admin_user_tok,)
|
||||||
"GET", url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
self.assertEqual("Can only lookup local users", channel.json_body["error"])
|
||||||
|
@ -1359,7 +1321,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
other_user_tok = self.login("user", "pass")
|
other_user_tok = self.login("user", "pass")
|
||||||
self._create_media(other_user_tok, number_media)
|
self._create_media(other_user_tok, number_media)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=5", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1378,7 +1340,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
other_user_tok = self.login("user", "pass")
|
other_user_tok = self.login("user", "pass")
|
||||||
self._create_media(other_user_tok, number_media)
|
self._create_media(other_user_tok, number_media)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=5", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1397,7 +1359,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
other_user_tok = self.login("user", "pass")
|
other_user_tok = self.login("user", "pass")
|
||||||
self._create_media(other_user_tok, number_media)
|
self._create_media(other_user_tok, number_media)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=5&limit=10", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=5&limit=10", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1412,7 +1374,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
Testing that a negative limit parameter returns a 400
|
Testing that a negative limit parameter returns a 400
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=-5", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=-5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1424,7 +1386,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
Testing that a negative from parameter returns a 400
|
Testing that a negative from parameter returns a 400
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=-5", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=-5", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1442,7 +1404,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# `next_token` does not appear
|
# `next_token` does not appear
|
||||||
# Number of results is the number of entries
|
# Number of results is the number of entries
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=20", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=20", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1453,7 +1415,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# `next_token` does not appear
|
# `next_token` does not appear
|
||||||
# Number of max results is larger than the number of entries
|
# Number of max results is larger than the number of entries
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=21", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=21", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1464,7 +1426,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# `next_token` does appear
|
# `next_token` does appear
|
||||||
# Number of max results is smaller than the number of entries
|
# Number of max results is smaller than the number of entries
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?limit=19", access_token=self.admin_user_tok,
|
"GET", self.url + "?limit=19", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1476,7 +1438,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
# Check
|
# Check
|
||||||
# Set `from` to value of `next_token` for request remaining entries
|
# Set `from` to value of `next_token` for request remaining entries
|
||||||
# `next_token` does not appear
|
# `next_token` does not appear
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url + "?from=19", access_token=self.admin_user_tok,
|
"GET", self.url + "?from=19", access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1491,9 +1453,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
if user has no media created
|
if user has no media created
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(0, channel.json_body["total"])
|
self.assertEqual(0, channel.json_body["total"])
|
||||||
|
@ -1508,9 +1468,7 @@ class UserMediaRestTestCase(unittest.HomeserverTestCase):
|
||||||
other_user_tok = self.login("user", "pass")
|
other_user_tok = self.login("user", "pass")
|
||||||
self._create_media(other_user_tok, number_media)
|
self._create_media(other_user_tok, number_media)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(number_media, channel.json_body["total"])
|
self.assertEqual(number_media, channel.json_body["total"])
|
||||||
|
@ -1576,7 +1534,7 @@ class UserTokenRestTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_token(self) -> str:
|
def _get_token(self) -> str:
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", self.url, b"{}", access_token=self.admin_user_tok
|
"POST", self.url, b"{}", access_token=self.admin_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -1585,7 +1543,7 @@ class UserTokenRestTestCase(unittest.HomeserverTestCase):
|
||||||
def test_no_auth(self):
|
def test_no_auth(self):
|
||||||
"""Try to login as a user without authentication.
|
"""Try to login as a user without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("POST", self.url, b"{}")
|
channel = self.make_request("POST", self.url, b"{}")
|
||||||
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
@ -1593,7 +1551,7 @@ class UserTokenRestTestCase(unittest.HomeserverTestCase):
|
||||||
def test_not_admin(self):
|
def test_not_admin(self):
|
||||||
"""Try to login as a user as a non-admin user.
|
"""Try to login as a user as a non-admin user.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", self.url, b"{}", access_token=self.other_user_tok
|
"POST", self.url, b"{}", access_token=self.other_user_tok
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1621,7 +1579,7 @@ class UserTokenRestTestCase(unittest.HomeserverTestCase):
|
||||||
self._get_token()
|
self._get_token()
|
||||||
|
|
||||||
# Check that we don't see a new device in our devices list
|
# Check that we don't see a new device in our devices list
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "devices", b"{}", access_token=self.other_user_tok
|
"GET", "devices", b"{}", access_token=self.other_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -1636,25 +1594,19 @@ class UserTokenRestTestCase(unittest.HomeserverTestCase):
|
||||||
puppet_token = self._get_token()
|
puppet_token = self._get_token()
|
||||||
|
|
||||||
# Test that we can successfully make a request
|
# Test that we can successfully make a request
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "devices", b"{}", access_token=puppet_token)
|
||||||
"GET", "devices", b"{}", access_token=puppet_token
|
|
||||||
)
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# Logout with the puppet token
|
# Logout with the puppet token
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("POST", "logout", b"{}", access_token=puppet_token)
|
||||||
"POST", "logout", b"{}", access_token=puppet_token
|
|
||||||
)
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# The puppet token should no longer work
|
# The puppet token should no longer work
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "devices", b"{}", access_token=puppet_token)
|
||||||
"GET", "devices", b"{}", access_token=puppet_token
|
|
||||||
)
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# .. but the real user's tokens should still work
|
# .. but the real user's tokens should still work
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "devices", b"{}", access_token=self.other_user_tok
|
"GET", "devices", b"{}", access_token=self.other_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -1667,25 +1619,21 @@ class UserTokenRestTestCase(unittest.HomeserverTestCase):
|
||||||
puppet_token = self._get_token()
|
puppet_token = self._get_token()
|
||||||
|
|
||||||
# Test that we can successfully make a request
|
# Test that we can successfully make a request
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "devices", b"{}", access_token=puppet_token)
|
||||||
"GET", "devices", b"{}", access_token=puppet_token
|
|
||||||
)
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# Logout all with the real user token
|
# Logout all with the real user token
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "logout/all", b"{}", access_token=self.other_user_tok
|
"POST", "logout/all", b"{}", access_token=self.other_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# The puppet token should still work
|
# The puppet token should still work
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "devices", b"{}", access_token=puppet_token)
|
||||||
"GET", "devices", b"{}", access_token=puppet_token
|
|
||||||
)
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# .. but the real user's tokens shouldn't
|
# .. but the real user's tokens shouldn't
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "devices", b"{}", access_token=self.other_user_tok
|
"GET", "devices", b"{}", access_token=self.other_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -1698,25 +1646,21 @@ class UserTokenRestTestCase(unittest.HomeserverTestCase):
|
||||||
puppet_token = self._get_token()
|
puppet_token = self._get_token()
|
||||||
|
|
||||||
# Test that we can successfully make a request
|
# Test that we can successfully make a request
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "devices", b"{}", access_token=puppet_token)
|
||||||
"GET", "devices", b"{}", access_token=puppet_token
|
|
||||||
)
|
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# Logout all with the admin user token
|
# Logout all with the admin user token
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "logout/all", b"{}", access_token=self.admin_user_tok
|
"POST", "logout/all", b"{}", access_token=self.admin_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# The puppet token should no longer work
|
# The puppet token should no longer work
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "devices", b"{}", access_token=puppet_token)
|
||||||
"GET", "devices", b"{}", access_token=puppet_token
|
|
||||||
)
|
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# .. but the real user's tokens should still work
|
# .. but the real user's tokens should still work
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "devices", b"{}", access_token=self.other_user_tok
|
"GET", "devices", b"{}", access_token=self.other_user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
@ -1798,11 +1742,11 @@ class WhoisRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Try to get information of an user without authentication.
|
Try to get information of an user without authentication.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request("GET", self.url1, b"{}")
|
channel = self.make_request("GET", self.url1, b"{}")
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
|
||||||
request, channel = self.make_request("GET", self.url2, b"{}")
|
channel = self.make_request("GET", self.url2, b"{}")
|
||||||
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(401, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.MISSING_TOKEN, channel.json_body["errcode"])
|
||||||
|
|
||||||
|
@ -1813,15 +1757,11 @@ class WhoisRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.register_user("user2", "pass")
|
self.register_user("user2", "pass")
|
||||||
other_user2_token = self.login("user2", "pass")
|
other_user2_token = self.login("user2", "pass")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url1, access_token=other_user2_token,)
|
||||||
"GET", self.url1, access_token=other_user2_token,
|
|
||||||
)
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url2, access_token=other_user2_token,)
|
||||||
"GET", self.url2, access_token=other_user2_token,
|
|
||||||
)
|
|
||||||
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(403, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
|
||||||
|
@ -1832,15 +1772,11 @@ class WhoisRestTestCase(unittest.HomeserverTestCase):
|
||||||
url1 = "/_synapse/admin/v1/whois/@unknown_person:unknown_domain"
|
url1 = "/_synapse/admin/v1/whois/@unknown_person:unknown_domain"
|
||||||
url2 = "/_matrix/client/r0/admin/whois/@unknown_person:unknown_domain"
|
url2 = "/_matrix/client/r0/admin/whois/@unknown_person:unknown_domain"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url1, access_token=self.admin_user_tok,)
|
||||||
"GET", url1, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only whois a local user", channel.json_body["error"])
|
self.assertEqual("Can only whois a local user", channel.json_body["error"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", url2, access_token=self.admin_user_tok,)
|
||||||
"GET", url2, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
self.assertEqual(400, channel.code, msg=channel.json_body)
|
self.assertEqual(400, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual("Can only whois a local user", channel.json_body["error"])
|
self.assertEqual("Can only whois a local user", channel.json_body["error"])
|
||||||
|
|
||||||
|
@ -1848,16 +1784,12 @@ class WhoisRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
The lookup should succeed for an admin.
|
The lookup should succeed for an admin.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url1, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url1, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
||||||
self.assertIn("devices", channel.json_body)
|
self.assertIn("devices", channel.json_body)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url2, access_token=self.admin_user_tok,)
|
||||||
"GET", self.url2, access_token=self.admin_user_tok,
|
|
||||||
)
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
||||||
self.assertIn("devices", channel.json_body)
|
self.assertIn("devices", channel.json_body)
|
||||||
|
@ -1868,16 +1800,12 @@ class WhoisRestTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
other_user_token = self.login("user", "pass")
|
other_user_token = self.login("user", "pass")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url1, access_token=other_user_token,)
|
||||||
"GET", self.url1, access_token=other_user_token,
|
|
||||||
)
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
||||||
self.assertIn("devices", channel.json_body)
|
self.assertIn("devices", channel.json_body)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", self.url2, access_token=other_user_token,)
|
||||||
"GET", self.url2, access_token=other_user_token,
|
|
||||||
)
|
|
||||||
self.assertEqual(200, channel.code, msg=channel.json_body)
|
self.assertEqual(200, channel.code, msg=channel.json_body)
|
||||||
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
self.assertEqual(self.other_user, channel.json_body["user_id"])
|
||||||
self.assertIn("devices", channel.json_body)
|
self.assertIn("devices", channel.json_body)
|
||||||
|
|
|
@ -61,7 +61,7 @@ class ConsentResourceTestCase(unittest.HomeserverTestCase):
|
||||||
def test_render_public_consent(self):
|
def test_render_public_consent(self):
|
||||||
"""You can observe the terms form without specifying a user"""
|
"""You can observe the terms form without specifying a user"""
|
||||||
resource = consent_resource.ConsentResource(self.hs)
|
resource = consent_resource.ConsentResource(self.hs)
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor, FakeSite(resource), "GET", "/consent?v=1", shorthand=False
|
self.reactor, FakeSite(resource), "GET", "/consent?v=1", shorthand=False
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -82,7 +82,7 @@ class ConsentResourceTestCase(unittest.HomeserverTestCase):
|
||||||
uri_builder.build_user_consent_uri(user_id).replace("_matrix/", "")
|
uri_builder.build_user_consent_uri(user_id).replace("_matrix/", "")
|
||||||
+ "&u=user"
|
+ "&u=user"
|
||||||
)
|
)
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(resource),
|
FakeSite(resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -97,7 +97,7 @@ class ConsentResourceTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(consented, "False")
|
self.assertEqual(consented, "False")
|
||||||
|
|
||||||
# POST to the consent page, saying we've agreed
|
# POST to the consent page, saying we've agreed
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(resource),
|
FakeSite(resource),
|
||||||
"POST",
|
"POST",
|
||||||
|
@ -109,7 +109,7 @@ class ConsentResourceTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Fetch the consent page, to get the consent version -- it should have
|
# Fetch the consent page, to get the consent version -- it should have
|
||||||
# changed
|
# changed
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(resource),
|
FakeSite(resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
|
|
@ -93,7 +93,7 @@ class EphemeralMessageTestCase(unittest.HomeserverTestCase):
|
||||||
def get_event(self, room_id, event_id, expected_code=200):
|
def get_event(self, room_id, event_id, expected_code=200):
|
||||||
url = "/_matrix/client/r0/rooms/%s/event/%s" % (room_id, event_id)
|
url = "/_matrix/client/r0/rooms/%s/event/%s" % (room_id, event_id)
|
||||||
|
|
||||||
request, channel = self.make_request("GET", url)
|
channel = self.make_request("GET", url)
|
||||||
|
|
||||||
self.assertEqual(channel.code, expected_code, channel.result)
|
self.assertEqual(channel.code, expected_code, channel.result)
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,7 @@ class IdentityTestCase(unittest.HomeserverTestCase):
|
||||||
self.register_user("kermit", "monkey")
|
self.register_user("kermit", "monkey")
|
||||||
tok = self.login("kermit", "monkey")
|
tok = self.login("kermit", "monkey")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"POST", "/createRoom", b"{}", access_token=tok)
|
||||||
b"POST", "/createRoom", b"{}", access_token=tok
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
room_id = channel.json_body["room_id"]
|
room_id = channel.json_body["room_id"]
|
||||||
|
|
||||||
|
@ -56,7 +54,7 @@ class IdentityTestCase(unittest.HomeserverTestCase):
|
||||||
}
|
}
|
||||||
request_data = json.dumps(params)
|
request_data = json.dumps(params)
|
||||||
request_url = ("/rooms/%s/invite" % (room_id)).encode("ascii")
|
request_url = ("/rooms/%s/invite" % (room_id)).encode("ascii")
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"POST", request_url, request_data, access_token=tok
|
b"POST", request_url, request_data, access_token=tok
|
||||||
)
|
)
|
||||||
self.assertEquals(channel.result["code"], b"403", channel.result)
|
self.assertEquals(channel.result["code"], b"403", channel.result)
|
||||||
|
|
|
@ -69,16 +69,12 @@ class RedactionsTestCase(HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
path = "/_matrix/client/r0/rooms/%s/redact/%s" % (room_id, event_id)
|
path = "/_matrix/client/r0/rooms/%s/redact/%s" % (room_id, event_id)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("POST", path, content={}, access_token=access_token)
|
||||||
"POST", path, content={}, access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEqual(int(channel.result["code"]), expect_code)
|
self.assertEqual(int(channel.result["code"]), expect_code)
|
||||||
return channel.json_body
|
return channel.json_body
|
||||||
|
|
||||||
def _sync_room_timeline(self, access_token, room_id):
|
def _sync_room_timeline(self, access_token, room_id):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "sync", access_token=self.mod_access_token)
|
||||||
"GET", "sync", access_token=self.mod_access_token
|
|
||||||
)
|
|
||||||
self.assertEqual(channel.result["code"], b"200")
|
self.assertEqual(channel.result["code"], b"200")
|
||||||
room_sync = channel.json_body["rooms"]["join"][room_id]
|
room_sync = channel.json_body["rooms"]["join"][room_id]
|
||||||
return room_sync["timeline"]["events"]
|
return room_sync["timeline"]["events"]
|
||||||
|
|
|
@ -325,7 +325,7 @@ class RetentionNoDefaultPolicyTestCase(unittest.HomeserverTestCase):
|
||||||
def get_event(self, room_id, event_id, expected_code=200):
|
def get_event(self, room_id, event_id, expected_code=200):
|
||||||
url = "/_matrix/client/r0/rooms/%s/event/%s" % (room_id, event_id)
|
url = "/_matrix/client/r0/rooms/%s/event/%s" % (room_id, event_id)
|
||||||
|
|
||||||
request, channel = self.make_request("GET", url, access_token=self.token)
|
channel = self.make_request("GET", url, access_token=self.token)
|
||||||
|
|
||||||
self.assertEqual(channel.code, expected_code, channel.result)
|
self.assertEqual(channel.code, expected_code, channel.result)
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ class RoomTestCase(_ShadowBannedBase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Inviting the user completes successfully.
|
# Inviting the user completes successfully.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/rooms/%s/invite" % (room_id,),
|
"/rooms/%s/invite" % (room_id,),
|
||||||
{"id_server": "test", "medium": "email", "address": "test@test.test"},
|
{"id_server": "test", "medium": "email", "address": "test@test.test"},
|
||||||
|
@ -103,7 +103,7 @@ class RoomTestCase(_ShadowBannedBase):
|
||||||
def test_create_room(self):
|
def test_create_room(self):
|
||||||
"""Invitations during a room creation should be discarded, but the room still gets created."""
|
"""Invitations during a room creation should be discarded, but the room still gets created."""
|
||||||
# The room creation is successful.
|
# The room creation is successful.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/createRoom",
|
"/_matrix/client/r0/createRoom",
|
||||||
{"visibility": "public", "invite": [self.other_user_id]},
|
{"visibility": "public", "invite": [self.other_user_id]},
|
||||||
|
@ -158,7 +158,7 @@ class RoomTestCase(_ShadowBannedBase):
|
||||||
self.banned_user_id, tok=self.banned_access_token
|
self.banned_user_id, tok=self.banned_access_token
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/rooms/%s/upgrade" % (room_id,),
|
"/_matrix/client/r0/rooms/%s/upgrade" % (room_id,),
|
||||||
{"new_version": "6"},
|
{"new_version": "6"},
|
||||||
|
@ -183,7 +183,7 @@ class RoomTestCase(_ShadowBannedBase):
|
||||||
self.banned_user_id, tok=self.banned_access_token
|
self.banned_user_id, tok=self.banned_access_token
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/typing/%s" % (room_id, self.banned_user_id),
|
"/rooms/%s/typing/%s" % (room_id, self.banned_user_id),
|
||||||
{"typing": True, "timeout": 30000},
|
{"typing": True, "timeout": 30000},
|
||||||
|
@ -198,7 +198,7 @@ class RoomTestCase(_ShadowBannedBase):
|
||||||
# The other user can join and send typing events.
|
# The other user can join and send typing events.
|
||||||
self.helper.join(room_id, self.other_user_id, tok=self.other_access_token)
|
self.helper.join(room_id, self.other_user_id, tok=self.other_access_token)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/typing/%s" % (room_id, self.other_user_id),
|
"/rooms/%s/typing/%s" % (room_id, self.other_user_id),
|
||||||
{"typing": True, "timeout": 30000},
|
{"typing": True, "timeout": 30000},
|
||||||
|
@ -244,7 +244,7 @@ class ProfileTestCase(_ShadowBannedBase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# The update should succeed.
|
# The update should succeed.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/_matrix/client/r0/profile/%s/displayname" % (self.banned_user_id,),
|
"/_matrix/client/r0/profile/%s/displayname" % (self.banned_user_id,),
|
||||||
{"displayname": new_display_name},
|
{"displayname": new_display_name},
|
||||||
|
@ -254,7 +254,7 @@ class ProfileTestCase(_ShadowBannedBase):
|
||||||
self.assertEqual(channel.json_body, {})
|
self.assertEqual(channel.json_body, {})
|
||||||
|
|
||||||
# The user's display name should be updated.
|
# The user's display name should be updated.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/profile/%s/displayname" % (self.banned_user_id,)
|
"GET", "/profile/%s/displayname" % (self.banned_user_id,)
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
|
@ -282,7 +282,7 @@ class ProfileTestCase(_ShadowBannedBase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# The update should succeed.
|
# The update should succeed.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/_matrix/client/r0/rooms/%s/state/m.room.member/%s"
|
"/_matrix/client/r0/rooms/%s/state/m.room.member/%s"
|
||||||
% (room_id, self.banned_user_id),
|
% (room_id, self.banned_user_id),
|
||||||
|
|
|
@ -86,7 +86,7 @@ class ThirdPartyRulesTestCase(unittest.HomeserverTestCase):
|
||||||
callback = Mock(spec=[], side_effect=check)
|
callback = Mock(spec=[], side_effect=check)
|
||||||
current_rules_module().check_event_allowed = callback
|
current_rules_module().check_event_allowed = callback
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/_matrix/client/r0/rooms/%s/send/foo.bar.allowed/1" % self.room_id,
|
"/_matrix/client/r0/rooms/%s/send/foo.bar.allowed/1" % self.room_id,
|
||||||
{},
|
{},
|
||||||
|
@ -104,7 +104,7 @@ class ThirdPartyRulesTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(ev.type, k[0])
|
self.assertEqual(ev.type, k[0])
|
||||||
self.assertEqual(ev.state_key, k[1])
|
self.assertEqual(ev.state_key, k[1])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/_matrix/client/r0/rooms/%s/send/foo.bar.forbidden/2" % self.room_id,
|
"/_matrix/client/r0/rooms/%s/send/foo.bar.forbidden/2" % self.room_id,
|
||||||
{},
|
{},
|
||||||
|
@ -123,7 +123,7 @@ class ThirdPartyRulesTestCase(unittest.HomeserverTestCase):
|
||||||
current_rules_module().check_event_allowed = check
|
current_rules_module().check_event_allowed = check
|
||||||
|
|
||||||
# now send the event
|
# now send the event
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/_matrix/client/r0/rooms/%s/send/modifyme/1" % self.room_id,
|
"/_matrix/client/r0/rooms/%s/send/modifyme/1" % self.room_id,
|
||||||
{"x": "x"},
|
{"x": "x"},
|
||||||
|
@ -142,7 +142,7 @@ class ThirdPartyRulesTestCase(unittest.HomeserverTestCase):
|
||||||
current_rules_module().check_event_allowed = check
|
current_rules_module().check_event_allowed = check
|
||||||
|
|
||||||
# now send the event
|
# now send the event
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/_matrix/client/r0/rooms/%s/send/modifyme/1" % self.room_id,
|
"/_matrix/client/r0/rooms/%s/send/modifyme/1" % self.room_id,
|
||||||
{"x": "x"},
|
{"x": "x"},
|
||||||
|
@ -152,7 +152,7 @@ class ThirdPartyRulesTestCase(unittest.HomeserverTestCase):
|
||||||
event_id = channel.json_body["event_id"]
|
event_id = channel.json_body["event_id"]
|
||||||
|
|
||||||
# ... and check that it got modified
|
# ... and check that it got modified
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/r0/rooms/%s/event/%s" % (self.room_id, event_id),
|
"/_matrix/client/r0/rooms/%s/event/%s" % (self.room_id, event_id),
|
||||||
access_token=self.tok,
|
access_token=self.tok,
|
||||||
|
|
|
@ -91,7 +91,7 @@ class DirectoryTestCase(unittest.HomeserverTestCase):
|
||||||
# that we can make sure that the check is done on the whole alias.
|
# that we can make sure that the check is done on the whole alias.
|
||||||
data = {"room_alias_name": random_string(256 - len(self.hs.hostname))}
|
data = {"room_alias_name": random_string(256 - len(self.hs.hostname))}
|
||||||
request_data = json.dumps(data)
|
request_data = json.dumps(data)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", url, request_data, access_token=self.user_tok
|
"POST", url, request_data, access_token=self.user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 400, channel.result)
|
self.assertEqual(channel.code, 400, channel.result)
|
||||||
|
@ -104,7 +104,7 @@ class DirectoryTestCase(unittest.HomeserverTestCase):
|
||||||
# as cautious as possible here.
|
# as cautious as possible here.
|
||||||
data = {"room_alias_name": random_string(5)}
|
data = {"room_alias_name": random_string(5)}
|
||||||
request_data = json.dumps(data)
|
request_data = json.dumps(data)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", url, request_data, access_token=self.user_tok
|
"POST", url, request_data, access_token=self.user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
|
@ -118,7 +118,7 @@ class DirectoryTestCase(unittest.HomeserverTestCase):
|
||||||
data = {"aliases": [self.random_alias(alias_length)]}
|
data = {"aliases": [self.random_alias(alias_length)]}
|
||||||
request_data = json.dumps(data)
|
request_data = json.dumps(data)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", url, request_data, access_token=self.user_tok
|
"PUT", url, request_data, access_token=self.user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, expected_code, channel.result)
|
self.assertEqual(channel.code, expected_code, channel.result)
|
||||||
|
@ -128,7 +128,7 @@ class DirectoryTestCase(unittest.HomeserverTestCase):
|
||||||
data = {"room_id": self.room_id}
|
data = {"room_id": self.room_id}
|
||||||
request_data = json.dumps(data)
|
request_data = json.dumps(data)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", url, request_data, access_token=self.user_tok
|
"PUT", url, request_data, access_token=self.user_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, expected_code, channel.result)
|
self.assertEqual(channel.code, expected_code, channel.result)
|
||||||
|
|
|
@ -63,13 +63,13 @@ class EventStreamPermissionsTestCase(unittest.HomeserverTestCase):
|
||||||
# implementation is now part of the r0 implementation, the newer
|
# implementation is now part of the r0 implementation, the newer
|
||||||
# behaviour is used instead to be consistent with the r0 spec.
|
# behaviour is used instead to be consistent with the r0 spec.
|
||||||
# see issue #2602
|
# see issue #2602
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/events?access_token=%s" % ("invalid" + self.token,)
|
"GET", "/events?access_token=%s" % ("invalid" + self.token,)
|
||||||
)
|
)
|
||||||
self.assertEquals(channel.code, 401, msg=channel.result)
|
self.assertEquals(channel.code, 401, msg=channel.result)
|
||||||
|
|
||||||
# valid token, expect content
|
# valid token, expect content
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/events?access_token=%s&timeout=0" % (self.token,)
|
"GET", "/events?access_token=%s&timeout=0" % (self.token,)
|
||||||
)
|
)
|
||||||
self.assertEquals(channel.code, 200, msg=channel.result)
|
self.assertEquals(channel.code, 200, msg=channel.result)
|
||||||
|
@ -87,7 +87,7 @@ class EventStreamPermissionsTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# valid token, expect content
|
# valid token, expect content
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/events?access_token=%s&timeout=0" % (self.token,)
|
"GET", "/events?access_token=%s&timeout=0" % (self.token,)
|
||||||
)
|
)
|
||||||
self.assertEquals(channel.code, 200, msg=channel.result)
|
self.assertEquals(channel.code, 200, msg=channel.result)
|
||||||
|
@ -149,7 +149,7 @@ class GetEventsTestCase(unittest.HomeserverTestCase):
|
||||||
resp = self.helper.send(self.room_id, tok=self.token)
|
resp = self.helper.send(self.room_id, tok=self.token)
|
||||||
event_id = resp["event_id"]
|
event_id = resp["event_id"]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/events/" + event_id, access_token=self.token,
|
"GET", "/events/" + event_id, access_token=self.token,
|
||||||
)
|
)
|
||||||
self.assertEquals(channel.code, 200, msg=channel.result)
|
self.assertEquals(channel.code, 200, msg=channel.result)
|
||||||
|
|
|
@ -63,7 +63,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"identifier": {"type": "m.id.user", "user": "kermit" + str(i)},
|
"identifier": {"type": "m.id.user", "user": "kermit" + str(i)},
|
||||||
"password": "monkey",
|
"password": "monkey",
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
|
|
||||||
if i == 5:
|
if i == 5:
|
||||||
self.assertEquals(channel.result["code"], b"429", channel.result)
|
self.assertEquals(channel.result["code"], b"429", channel.result)
|
||||||
|
@ -82,7 +82,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"identifier": {"type": "m.id.user", "user": "kermit" + str(i)},
|
"identifier": {"type": "m.id.user", "user": "kermit" + str(i)},
|
||||||
"password": "monkey",
|
"password": "monkey",
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"identifier": {"type": "m.id.user", "user": "kermit"},
|
"identifier": {"type": "m.id.user", "user": "kermit"},
|
||||||
"password": "monkey",
|
"password": "monkey",
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
|
|
||||||
if i == 5:
|
if i == 5:
|
||||||
self.assertEquals(channel.result["code"], b"429", channel.result)
|
self.assertEquals(channel.result["code"], b"429", channel.result)
|
||||||
|
@ -127,7 +127,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"identifier": {"type": "m.id.user", "user": "kermit"},
|
"identifier": {"type": "m.id.user", "user": "kermit"},
|
||||||
"password": "monkey",
|
"password": "monkey",
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"identifier": {"type": "m.id.user", "user": "kermit"},
|
"identifier": {"type": "m.id.user", "user": "kermit"},
|
||||||
"password": "notamonkey",
|
"password": "notamonkey",
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
|
|
||||||
if i == 5:
|
if i == 5:
|
||||||
self.assertEquals(channel.result["code"], b"429", channel.result)
|
self.assertEquals(channel.result["code"], b"429", channel.result)
|
||||||
|
@ -172,7 +172,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"identifier": {"type": "m.id.user", "user": "kermit"},
|
"identifier": {"type": "m.id.user", "user": "kermit"},
|
||||||
"password": "notamonkey",
|
"password": "notamonkey",
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"403", channel.result)
|
self.assertEquals(channel.result["code"], b"403", channel.result)
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
self.register_user("kermit", "monkey")
|
self.register_user("kermit", "monkey")
|
||||||
|
|
||||||
# we shouldn't be able to make requests without an access token
|
# we shouldn't be able to make requests without an access token
|
||||||
request, channel = self.make_request(b"GET", TEST_URL)
|
channel = self.make_request(b"GET", TEST_URL)
|
||||||
self.assertEquals(channel.result["code"], b"401", channel.result)
|
self.assertEquals(channel.result["code"], b"401", channel.result)
|
||||||
self.assertEquals(channel.json_body["errcode"], "M_MISSING_TOKEN")
|
self.assertEquals(channel.json_body["errcode"], "M_MISSING_TOKEN")
|
||||||
|
|
||||||
|
@ -191,25 +191,21 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"identifier": {"type": "m.id.user", "user": "kermit"},
|
"identifier": {"type": "m.id.user", "user": "kermit"},
|
||||||
"password": "monkey",
|
"password": "monkey",
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
|
|
||||||
self.assertEquals(channel.code, 200, channel.result)
|
self.assertEquals(channel.code, 200, channel.result)
|
||||||
access_token = channel.json_body["access_token"]
|
access_token = channel.json_body["access_token"]
|
||||||
device_id = channel.json_body["device_id"]
|
device_id = channel.json_body["device_id"]
|
||||||
|
|
||||||
# we should now be able to make requests with the access token
|
# we should now be able to make requests with the access token
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||||
b"GET", TEST_URL, access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.code, 200, channel.result)
|
self.assertEquals(channel.code, 200, channel.result)
|
||||||
|
|
||||||
# time passes
|
# time passes
|
||||||
self.reactor.advance(24 * 3600)
|
self.reactor.advance(24 * 3600)
|
||||||
|
|
||||||
# ... and we should be soft-logouted
|
# ... and we should be soft-logouted
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||||
b"GET", TEST_URL, access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.code, 401, channel.result)
|
self.assertEquals(channel.code, 401, channel.result)
|
||||||
self.assertEquals(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
self.assertEquals(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
||||||
self.assertEquals(channel.json_body["soft_logout"], True)
|
self.assertEquals(channel.json_body["soft_logout"], True)
|
||||||
|
@ -223,9 +219,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# more requests with the expired token should still return a soft-logout
|
# more requests with the expired token should still return a soft-logout
|
||||||
self.reactor.advance(3600)
|
self.reactor.advance(3600)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||||
b"GET", TEST_URL, access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.code, 401, channel.result)
|
self.assertEquals(channel.code, 401, channel.result)
|
||||||
self.assertEquals(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
self.assertEquals(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
||||||
self.assertEquals(channel.json_body["soft_logout"], True)
|
self.assertEquals(channel.json_body["soft_logout"], True)
|
||||||
|
@ -233,16 +227,14 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
# ... but if we delete that device, it will be a proper logout
|
# ... but if we delete that device, it will be a proper logout
|
||||||
self._delete_device(access_token_2, "kermit", "monkey", device_id)
|
self._delete_device(access_token_2, "kermit", "monkey", device_id)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||||
b"GET", TEST_URL, access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.code, 401, channel.result)
|
self.assertEquals(channel.code, 401, channel.result)
|
||||||
self.assertEquals(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
self.assertEquals(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
||||||
self.assertEquals(channel.json_body["soft_logout"], False)
|
self.assertEquals(channel.json_body["soft_logout"], False)
|
||||||
|
|
||||||
def _delete_device(self, access_token, user_id, password, device_id):
|
def _delete_device(self, access_token, user_id, password, device_id):
|
||||||
"""Perform the UI-Auth to delete a device"""
|
"""Perform the UI-Auth to delete a device"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"DELETE", "devices/" + device_id, access_token=access_token
|
b"DELETE", "devices/" + device_id, access_token=access_token
|
||||||
)
|
)
|
||||||
self.assertEquals(channel.code, 401, channel.result)
|
self.assertEquals(channel.code, 401, channel.result)
|
||||||
|
@ -262,7 +254,7 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"session": channel.json_body["session"],
|
"session": channel.json_body["session"],
|
||||||
}
|
}
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"DELETE",
|
b"DELETE",
|
||||||
"devices/" + device_id,
|
"devices/" + device_id,
|
||||||
access_token=access_token,
|
access_token=access_token,
|
||||||
|
@ -278,26 +270,20 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
access_token = self.login("kermit", "monkey")
|
access_token = self.login("kermit", "monkey")
|
||||||
|
|
||||||
# we should now be able to make requests with the access token
|
# we should now be able to make requests with the access token
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||||
b"GET", TEST_URL, access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.code, 200, channel.result)
|
self.assertEquals(channel.code, 200, channel.result)
|
||||||
|
|
||||||
# time passes
|
# time passes
|
||||||
self.reactor.advance(24 * 3600)
|
self.reactor.advance(24 * 3600)
|
||||||
|
|
||||||
# ... and we should be soft-logouted
|
# ... and we should be soft-logouted
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||||
b"GET", TEST_URL, access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.code, 401, channel.result)
|
self.assertEquals(channel.code, 401, channel.result)
|
||||||
self.assertEquals(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
self.assertEquals(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
||||||
self.assertEquals(channel.json_body["soft_logout"], True)
|
self.assertEquals(channel.json_body["soft_logout"], True)
|
||||||
|
|
||||||
# Now try to hard logout this session
|
# Now try to hard logout this session
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"POST", "/logout", access_token=access_token)
|
||||||
b"POST", "/logout", access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
@override_config({"session_lifetime": "24h"})
|
@override_config({"session_lifetime": "24h"})
|
||||||
|
@ -308,26 +294,20 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
access_token = self.login("kermit", "monkey")
|
access_token = self.login("kermit", "monkey")
|
||||||
|
|
||||||
# we should now be able to make requests with the access token
|
# we should now be able to make requests with the access token
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||||
b"GET", TEST_URL, access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.code, 200, channel.result)
|
self.assertEquals(channel.code, 200, channel.result)
|
||||||
|
|
||||||
# time passes
|
# time passes
|
||||||
self.reactor.advance(24 * 3600)
|
self.reactor.advance(24 * 3600)
|
||||||
|
|
||||||
# ... and we should be soft-logouted
|
# ... and we should be soft-logouted
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"GET", TEST_URL, access_token=access_token)
|
||||||
b"GET", TEST_URL, access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.code, 401, channel.result)
|
self.assertEquals(channel.code, 401, channel.result)
|
||||||
self.assertEquals(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
self.assertEquals(channel.json_body["errcode"], "M_UNKNOWN_TOKEN")
|
||||||
self.assertEquals(channel.json_body["soft_logout"], True)
|
self.assertEquals(channel.json_body["soft_logout"], True)
|
||||||
|
|
||||||
# Now try to hard log out all of the user's sessions
|
# Now try to hard log out all of the user's sessions
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"POST", "/logout/all", access_token=access_token)
|
||||||
b"POST", "/logout/all", access_token=access_token
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
|
|
||||||
|
@ -402,7 +382,7 @@ class CASTestCase(unittest.HomeserverTestCase):
|
||||||
cas_ticket_url = urllib.parse.urlunparse(url_parts)
|
cas_ticket_url = urllib.parse.urlunparse(url_parts)
|
||||||
|
|
||||||
# Get Synapse to call the fake CAS and serve the template.
|
# Get Synapse to call the fake CAS and serve the template.
|
||||||
request, channel = self.make_request("GET", cas_ticket_url)
|
channel = self.make_request("GET", cas_ticket_url)
|
||||||
|
|
||||||
# Test that the response is HTML.
|
# Test that the response is HTML.
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -446,7 +426,7 @@ class CASTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get Synapse to call the fake CAS and serve the template.
|
# Get Synapse to call the fake CAS and serve the template.
|
||||||
request, channel = self.make_request("GET", cas_ticket_url)
|
channel = self.make_request("GET", cas_ticket_url)
|
||||||
|
|
||||||
self.assertEqual(channel.code, 302)
|
self.assertEqual(channel.code, 302)
|
||||||
location_headers = channel.headers.getRawHeaders("Location")
|
location_headers = channel.headers.getRawHeaders("Location")
|
||||||
|
@ -472,7 +452,7 @@ class CASTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get Synapse to call the fake CAS and serve the template.
|
# Get Synapse to call the fake CAS and serve the template.
|
||||||
request, channel = self.make_request("GET", cas_ticket_url)
|
channel = self.make_request("GET", cas_ticket_url)
|
||||||
|
|
||||||
# Because the user is deactivated they are served an error template.
|
# Because the user is deactivated they are served an error template.
|
||||||
self.assertEqual(channel.code, 403)
|
self.assertEqual(channel.code, 403)
|
||||||
|
@ -502,7 +482,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
||||||
params = json.dumps(
|
params = json.dumps(
|
||||||
{"type": "org.matrix.login.jwt", "token": self.jwt_encode(*args)}
|
{"type": "org.matrix.login.jwt", "token": self.jwt_encode(*args)}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
def test_login_jwt_valid_registered(self):
|
def test_login_jwt_valid_registered(self):
|
||||||
|
@ -634,7 +614,7 @@ class JWTTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_login_no_token(self):
|
def test_login_no_token(self):
|
||||||
params = json.dumps({"type": "org.matrix.login.jwt"})
|
params = json.dumps({"type": "org.matrix.login.jwt"})
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
self.assertEqual(channel.result["code"], b"403", channel.result)
|
self.assertEqual(channel.result["code"], b"403", channel.result)
|
||||||
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
self.assertEqual(channel.json_body["errcode"], "M_FORBIDDEN")
|
||||||
self.assertEqual(channel.json_body["error"], "Token field for JWT is missing")
|
self.assertEqual(channel.json_body["error"], "Token field for JWT is missing")
|
||||||
|
@ -707,7 +687,7 @@ class JWTPubKeyTestCase(unittest.HomeserverTestCase):
|
||||||
params = json.dumps(
|
params = json.dumps(
|
||||||
{"type": "org.matrix.login.jwt", "token": self.jwt_encode(*args)}
|
{"type": "org.matrix.login.jwt", "token": self.jwt_encode(*args)}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
def test_login_jwt_valid(self):
|
def test_login_jwt_valid(self):
|
||||||
|
@ -735,7 +715,7 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
]
|
]
|
||||||
|
|
||||||
def register_as_user(self, username):
|
def register_as_user(self, username):
|
||||||
request, channel = self.make_request(
|
self.make_request(
|
||||||
b"POST",
|
b"POST",
|
||||||
"/_matrix/client/r0/register?access_token=%s" % (self.service.token,),
|
"/_matrix/client/r0/register?access_token=%s" % (self.service.token,),
|
||||||
{"username": username},
|
{"username": username},
|
||||||
|
@ -784,7 +764,7 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"type": login.LoginRestServlet.APPSERVICE_TYPE,
|
"type": login.LoginRestServlet.APPSERVICE_TYPE,
|
||||||
"identifier": {"type": "m.id.user", "user": AS_USER},
|
"identifier": {"type": "m.id.user", "user": AS_USER},
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"POST", LOGIN_URL, params, access_token=self.service.token
|
b"POST", LOGIN_URL, params, access_token=self.service.token
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -799,7 +779,7 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"type": login.LoginRestServlet.APPSERVICE_TYPE,
|
"type": login.LoginRestServlet.APPSERVICE_TYPE,
|
||||||
"identifier": {"type": "m.id.user", "user": self.service.sender},
|
"identifier": {"type": "m.id.user", "user": self.service.sender},
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"POST", LOGIN_URL, params, access_token=self.service.token
|
b"POST", LOGIN_URL, params, access_token=self.service.token
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -814,7 +794,7 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"type": login.LoginRestServlet.APPSERVICE_TYPE,
|
"type": login.LoginRestServlet.APPSERVICE_TYPE,
|
||||||
"identifier": {"type": "m.id.user", "user": "fibble_wibble"},
|
"identifier": {"type": "m.id.user", "user": "fibble_wibble"},
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"POST", LOGIN_URL, params, access_token=self.service.token
|
b"POST", LOGIN_URL, params, access_token=self.service.token
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -829,7 +809,7 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"type": login.LoginRestServlet.APPSERVICE_TYPE,
|
"type": login.LoginRestServlet.APPSERVICE_TYPE,
|
||||||
"identifier": {"type": "m.id.user", "user": AS_USER},
|
"identifier": {"type": "m.id.user", "user": AS_USER},
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"POST", LOGIN_URL, params, access_token=self.another_service.token
|
b"POST", LOGIN_URL, params, access_token=self.another_service.token
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -845,6 +825,6 @@ class AppserviceLoginRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"type": login.LoginRestServlet.APPSERVICE_TYPE,
|
"type": login.LoginRestServlet.APPSERVICE_TYPE,
|
||||||
"identifier": {"type": "m.id.user", "user": AS_USER},
|
"identifier": {"type": "m.id.user", "user": AS_USER},
|
||||||
}
|
}
|
||||||
request, channel = self.make_request(b"POST", LOGIN_URL, params)
|
channel = self.make_request(b"POST", LOGIN_URL, params)
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"401", channel.result)
|
self.assertEquals(channel.result["code"], b"401", channel.result)
|
||||||
|
|
|
@ -53,7 +53,7 @@ class PresenceTestCase(unittest.HomeserverTestCase):
|
||||||
self.hs.config.use_presence = True
|
self.hs.config.use_presence = True
|
||||||
|
|
||||||
body = {"presence": "here", "status_msg": "beep boop"}
|
body = {"presence": "here", "status_msg": "beep boop"}
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/presence/%s/status" % (self.user_id,), body
|
"PUT", "/presence/%s/status" % (self.user_id,), body
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class PresenceTestCase(unittest.HomeserverTestCase):
|
||||||
self.hs.config.use_presence = False
|
self.hs.config.use_presence = False
|
||||||
|
|
||||||
body = {"presence": "here", "status_msg": "beep boop"}
|
body = {"presence": "here", "status_msg": "beep boop"}
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/presence/%s/status" % (self.user_id,), body
|
"PUT", "/presence/%s/status" % (self.user_id,), body
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -189,7 +189,7 @@ class ProfileTestCase(unittest.HomeserverTestCase):
|
||||||
self.owner_tok = self.login("owner", "pass")
|
self.owner_tok = self.login("owner", "pass")
|
||||||
|
|
||||||
def test_set_displayname(self):
|
def test_set_displayname(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/profile/%s/displayname" % (self.owner,),
|
"/profile/%s/displayname" % (self.owner,),
|
||||||
content=json.dumps({"displayname": "test"}),
|
content=json.dumps({"displayname": "test"}),
|
||||||
|
@ -202,7 +202,7 @@ class ProfileTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_set_displayname_too_long(self):
|
def test_set_displayname_too_long(self):
|
||||||
"""Attempts to set a stupid displayname should get a 400"""
|
"""Attempts to set a stupid displayname should get a 400"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/profile/%s/displayname" % (self.owner,),
|
"/profile/%s/displayname" % (self.owner,),
|
||||||
content=json.dumps({"displayname": "test" * 100}),
|
content=json.dumps({"displayname": "test" * 100}),
|
||||||
|
@ -214,9 +214,7 @@ class ProfileTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(res, "owner")
|
self.assertEqual(res, "owner")
|
||||||
|
|
||||||
def get_displayname(self):
|
def get_displayname(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "/profile/%s/displayname" % (self.owner,))
|
||||||
"GET", "/profile/%s/displayname" % (self.owner,)
|
|
||||||
)
|
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
return channel.json_body["displayname"]
|
return channel.json_body["displayname"]
|
||||||
|
|
||||||
|
@ -278,7 +276,7 @@ class ProfilesRestrictedTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def request_profile(self, expected_code, url_suffix="", access_token=None):
|
def request_profile(self, expected_code, url_suffix="", access_token=None):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.profile_url + url_suffix, access_token=access_token
|
"GET", self.profile_url + url_suffix, access_token=access_token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, expected_code, channel.result)
|
self.assertEqual(channel.code, expected_code, channel.result)
|
||||||
|
@ -320,19 +318,19 @@ class OwnProfileUnrestrictedTestCase(unittest.HomeserverTestCase):
|
||||||
"""Tests that a user can lookup their own profile without having to be in a room
|
"""Tests that a user can lookup their own profile without having to be in a room
|
||||||
if 'require_auth_for_profile_requests' is set to true in the server's config.
|
if 'require_auth_for_profile_requests' is set to true in the server's config.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/profile/" + self.requester, access_token=self.requester_tok
|
"GET", "/profile/" + self.requester, access_token=self.requester_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/profile/" + self.requester + "/displayname",
|
"/profile/" + self.requester + "/displayname",
|
||||||
access_token=self.requester_tok,
|
access_token=self.requester_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/profile/" + self.requester + "/avatar_url",
|
"/profile/" + self.requester + "/avatar_url",
|
||||||
access_token=self.requester_tok,
|
access_token=self.requester_tok,
|
||||||
|
|
|
@ -45,13 +45,13 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
# PUT a new rule
|
# PUT a new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# GET enabled for that new rule
|
# GET enabled for that new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -74,13 +74,13 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
# PUT a new rule
|
# PUT a new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# disable the rule
|
# disable the rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/pushrules/global/override/best.friend/enabled",
|
"/pushrules/global/override/best.friend/enabled",
|
||||||
{"enabled": False},
|
{"enabled": False},
|
||||||
|
@ -89,26 +89,26 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# check rule disabled
|
# check rule disabled
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
self.assertEqual(channel.json_body["enabled"], False)
|
self.assertEqual(channel.json_body["enabled"], False)
|
||||||
|
|
||||||
# DELETE the rule
|
# DELETE the rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"DELETE", "/pushrules/global/override/best.friend", access_token=token
|
"DELETE", "/pushrules/global/override/best.friend", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# PUT a new rule
|
# PUT a new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# GET enabled for that new rule
|
# GET enabled for that new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -130,13 +130,13 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
# PUT a new rule
|
# PUT a new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# disable the rule
|
# disable the rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/pushrules/global/override/best.friend/enabled",
|
"/pushrules/global/override/best.friend/enabled",
|
||||||
{"enabled": False},
|
{"enabled": False},
|
||||||
|
@ -145,14 +145,14 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# check rule disabled
|
# check rule disabled
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
self.assertEqual(channel.json_body["enabled"], False)
|
self.assertEqual(channel.json_body["enabled"], False)
|
||||||
|
|
||||||
# re-enable the rule
|
# re-enable the rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/pushrules/global/override/best.friend/enabled",
|
"/pushrules/global/override/best.friend/enabled",
|
||||||
{"enabled": True},
|
{"enabled": True},
|
||||||
|
@ -161,7 +161,7 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# check rule enabled
|
# check rule enabled
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -182,32 +182,32 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
# check 404 for never-heard-of rule
|
# check 404 for never-heard-of rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 404)
|
self.assertEqual(channel.code, 404)
|
||||||
self.assertEqual(channel.json_body["errcode"], Codes.NOT_FOUND)
|
self.assertEqual(channel.json_body["errcode"], Codes.NOT_FOUND)
|
||||||
|
|
||||||
# PUT a new rule
|
# PUT a new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# GET enabled for that new rule
|
# GET enabled for that new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# DELETE the rule
|
# DELETE the rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"DELETE", "/pushrules/global/override/best.friend", access_token=token
|
"DELETE", "/pushrules/global/override/best.friend", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# check 404 for deleted rule
|
# check 404 for deleted rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 404)
|
self.assertEqual(channel.code, 404)
|
||||||
|
@ -221,7 +221,7 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
token = self.login("user", "pass")
|
token = self.login("user", "pass")
|
||||||
|
|
||||||
# check 404 for never-heard-of rule
|
# check 404 for never-heard-of rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/.m.muahahaha/enabled", access_token=token
|
"GET", "/pushrules/global/override/.m.muahahaha/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 404)
|
self.assertEqual(channel.code, 404)
|
||||||
|
@ -235,7 +235,7 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
token = self.login("user", "pass")
|
token = self.login("user", "pass")
|
||||||
|
|
||||||
# enable & check 404 for never-heard-of rule
|
# enable & check 404 for never-heard-of rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/pushrules/global/override/best.friend/enabled",
|
"/pushrules/global/override/best.friend/enabled",
|
||||||
{"enabled": True},
|
{"enabled": True},
|
||||||
|
@ -252,7 +252,7 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
token = self.login("user", "pass")
|
token = self.login("user", "pass")
|
||||||
|
|
||||||
# enable & check 404 for never-heard-of rule
|
# enable & check 404 for never-heard-of rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/pushrules/global/override/.m.muahahah/enabled",
|
"/pushrules/global/override/.m.muahahah/enabled",
|
||||||
{"enabled": True},
|
{"enabled": True},
|
||||||
|
@ -276,13 +276,13 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
# PUT a new rule
|
# PUT a new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# GET actions for that new rule
|
# GET actions for that new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/actions", access_token=token
|
"GET", "/pushrules/global/override/best.friend/actions", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -305,13 +305,13 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
# PUT a new rule
|
# PUT a new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# change the rule actions
|
# change the rule actions
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/pushrules/global/override/best.friend/actions",
|
"/pushrules/global/override/best.friend/actions",
|
||||||
{"actions": ["dont_notify"]},
|
{"actions": ["dont_notify"]},
|
||||||
|
@ -320,7 +320,7 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# GET actions for that new rule
|
# GET actions for that new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/actions", access_token=token
|
"GET", "/pushrules/global/override/best.friend/actions", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -341,26 +341,26 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
}
|
}
|
||||||
|
|
||||||
# check 404 for never-heard-of rule
|
# check 404 for never-heard-of rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 404)
|
self.assertEqual(channel.code, 404)
|
||||||
self.assertEqual(channel.json_body["errcode"], Codes.NOT_FOUND)
|
self.assertEqual(channel.json_body["errcode"], Codes.NOT_FOUND)
|
||||||
|
|
||||||
# PUT a new rule
|
# PUT a new rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
"PUT", "/pushrules/global/override/best.friend", body, access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# DELETE the rule
|
# DELETE the rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"DELETE", "/pushrules/global/override/best.friend", access_token=token
|
"DELETE", "/pushrules/global/override/best.friend", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# check 404 for deleted rule
|
# check 404 for deleted rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
"GET", "/pushrules/global/override/best.friend/enabled", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 404)
|
self.assertEqual(channel.code, 404)
|
||||||
|
@ -374,7 +374,7 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
token = self.login("user", "pass")
|
token = self.login("user", "pass")
|
||||||
|
|
||||||
# check 404 for never-heard-of rule
|
# check 404 for never-heard-of rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/pushrules/global/override/.m.muahahaha/actions", access_token=token
|
"GET", "/pushrules/global/override/.m.muahahaha/actions", access_token=token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 404)
|
self.assertEqual(channel.code, 404)
|
||||||
|
@ -388,7 +388,7 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
token = self.login("user", "pass")
|
token = self.login("user", "pass")
|
||||||
|
|
||||||
# enable & check 404 for never-heard-of rule
|
# enable & check 404 for never-heard-of rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/pushrules/global/override/best.friend/actions",
|
"/pushrules/global/override/best.friend/actions",
|
||||||
{"actions": ["dont_notify"]},
|
{"actions": ["dont_notify"]},
|
||||||
|
@ -405,7 +405,7 @@ class PushRuleAttributesTestCase(HomeserverTestCase):
|
||||||
token = self.login("user", "pass")
|
token = self.login("user", "pass")
|
||||||
|
|
||||||
# enable & check 404 for never-heard-of rule
|
# enable & check 404 for never-heard-of rule
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/pushrules/global/override/.m.muahahah/actions",
|
"/pushrules/global/override/.m.muahahah/actions",
|
||||||
{"actions": ["dont_notify"]},
|
{"actions": ["dont_notify"]},
|
||||||
|
|
|
@ -84,13 +84,13 @@ class RoomPermissionsTestCase(RoomBase):
|
||||||
self.created_rmid_msg_path = (
|
self.created_rmid_msg_path = (
|
||||||
"rooms/%s/send/m.room.message/a1" % (self.created_rmid)
|
"rooms/%s/send/m.room.message/a1" % (self.created_rmid)
|
||||||
).encode("ascii")
|
).encode("ascii")
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", self.created_rmid_msg_path, b'{"msgtype":"m.text","body":"test msg"}'
|
"PUT", self.created_rmid_msg_path, b'{"msgtype":"m.text","body":"test msg"}'
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
|
|
||||||
# set topic for public room
|
# set topic for public room
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
("rooms/%s/state/m.room.topic" % self.created_public_rmid).encode("ascii"),
|
("rooms/%s/state/m.room.topic" % self.created_public_rmid).encode("ascii"),
|
||||||
b'{"topic":"Public Room Topic"}',
|
b'{"topic":"Public Room Topic"}',
|
||||||
|
@ -112,7 +112,7 @@ class RoomPermissionsTestCase(RoomBase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# send message in uncreated room, expect 403
|
# send message in uncreated room, expect 403
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/send/m.room.message/mid2" % (self.uncreated_rmid,),
|
"/rooms/%s/send/m.room.message/mid2" % (self.uncreated_rmid,),
|
||||||
msg_content,
|
msg_content,
|
||||||
|
@ -120,24 +120,24 @@ class RoomPermissionsTestCase(RoomBase):
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# send message in created room not joined (no state), expect 403
|
# send message in created room not joined (no state), expect 403
|
||||||
request, channel = self.make_request("PUT", send_msg_path(), msg_content)
|
channel = self.make_request("PUT", send_msg_path(), msg_content)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# send message in created room and invited, expect 403
|
# send message in created room and invited, expect 403
|
||||||
self.helper.invite(
|
self.helper.invite(
|
||||||
room=self.created_rmid, src=self.rmcreator_id, targ=self.user_id
|
room=self.created_rmid, src=self.rmcreator_id, targ=self.user_id
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("PUT", send_msg_path(), msg_content)
|
channel = self.make_request("PUT", send_msg_path(), msg_content)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# send message in created room and joined, expect 200
|
# send message in created room and joined, expect 200
|
||||||
self.helper.join(room=self.created_rmid, user=self.user_id)
|
self.helper.join(room=self.created_rmid, user=self.user_id)
|
||||||
request, channel = self.make_request("PUT", send_msg_path(), msg_content)
|
channel = self.make_request("PUT", send_msg_path(), msg_content)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# send message in created room and left, expect 403
|
# send message in created room and left, expect 403
|
||||||
self.helper.leave(room=self.created_rmid, user=self.user_id)
|
self.helper.leave(room=self.created_rmid, user=self.user_id)
|
||||||
request, channel = self.make_request("PUT", send_msg_path(), msg_content)
|
channel = self.make_request("PUT", send_msg_path(), msg_content)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
def test_topic_perms(self):
|
def test_topic_perms(self):
|
||||||
|
@ -145,30 +145,30 @@ class RoomPermissionsTestCase(RoomBase):
|
||||||
topic_path = "/rooms/%s/state/m.room.topic" % self.created_rmid
|
topic_path = "/rooms/%s/state/m.room.topic" % self.created_rmid
|
||||||
|
|
||||||
# set/get topic in uncreated room, expect 403
|
# set/get topic in uncreated room, expect 403
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", "/rooms/%s/state/m.room.topic" % self.uncreated_rmid, topic_content
|
"PUT", "/rooms/%s/state/m.room.topic" % self.uncreated_rmid, topic_content
|
||||||
)
|
)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/rooms/%s/state/m.room.topic" % self.uncreated_rmid
|
"GET", "/rooms/%s/state/m.room.topic" % self.uncreated_rmid
|
||||||
)
|
)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# set/get topic in created PRIVATE room not joined, expect 403
|
# set/get topic in created PRIVATE room not joined, expect 403
|
||||||
request, channel = self.make_request("PUT", topic_path, topic_content)
|
channel = self.make_request("PUT", topic_path, topic_content)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
request, channel = self.make_request("GET", topic_path)
|
channel = self.make_request("GET", topic_path)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# set topic in created PRIVATE room and invited, expect 403
|
# set topic in created PRIVATE room and invited, expect 403
|
||||||
self.helper.invite(
|
self.helper.invite(
|
||||||
room=self.created_rmid, src=self.rmcreator_id, targ=self.user_id
|
room=self.created_rmid, src=self.rmcreator_id, targ=self.user_id
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("PUT", topic_path, topic_content)
|
channel = self.make_request("PUT", topic_path, topic_content)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# get topic in created PRIVATE room and invited, expect 403
|
# get topic in created PRIVATE room and invited, expect 403
|
||||||
request, channel = self.make_request("GET", topic_path)
|
channel = self.make_request("GET", topic_path)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# set/get topic in created PRIVATE room and joined, expect 200
|
# set/get topic in created PRIVATE room and joined, expect 200
|
||||||
|
@ -176,29 +176,29 @@ class RoomPermissionsTestCase(RoomBase):
|
||||||
|
|
||||||
# Only room ops can set topic by default
|
# Only room ops can set topic by default
|
||||||
self.helper.auth_user_id = self.rmcreator_id
|
self.helper.auth_user_id = self.rmcreator_id
|
||||||
request, channel = self.make_request("PUT", topic_path, topic_content)
|
channel = self.make_request("PUT", topic_path, topic_content)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
self.helper.auth_user_id = self.user_id
|
self.helper.auth_user_id = self.user_id
|
||||||
|
|
||||||
request, channel = self.make_request("GET", topic_path)
|
channel = self.make_request("GET", topic_path)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
self.assert_dict(json.loads(topic_content.decode("utf8")), channel.json_body)
|
self.assert_dict(json.loads(topic_content.decode("utf8")), channel.json_body)
|
||||||
|
|
||||||
# set/get topic in created PRIVATE room and left, expect 403
|
# set/get topic in created PRIVATE room and left, expect 403
|
||||||
self.helper.leave(room=self.created_rmid, user=self.user_id)
|
self.helper.leave(room=self.created_rmid, user=self.user_id)
|
||||||
request, channel = self.make_request("PUT", topic_path, topic_content)
|
channel = self.make_request("PUT", topic_path, topic_content)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
request, channel = self.make_request("GET", topic_path)
|
channel = self.make_request("GET", topic_path)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# get topic in PUBLIC room, not joined, expect 403
|
# get topic in PUBLIC room, not joined, expect 403
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/rooms/%s/state/m.room.topic" % self.created_public_rmid
|
"GET", "/rooms/%s/state/m.room.topic" % self.created_public_rmid
|
||||||
)
|
)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# set topic in PUBLIC room, not joined, expect 403
|
# set topic in PUBLIC room, not joined, expect 403
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/state/m.room.topic" % self.created_public_rmid,
|
"/rooms/%s/state/m.room.topic" % self.created_public_rmid,
|
||||||
topic_content,
|
topic_content,
|
||||||
|
@ -208,7 +208,7 @@ class RoomPermissionsTestCase(RoomBase):
|
||||||
def _test_get_membership(self, room=None, members=[], expect_code=None):
|
def _test_get_membership(self, room=None, members=[], expect_code=None):
|
||||||
for member in members:
|
for member in members:
|
||||||
path = "/rooms/%s/state/m.room.member/%s" % (room, member)
|
path = "/rooms/%s/state/m.room.member/%s" % (room, member)
|
||||||
request, channel = self.make_request("GET", path)
|
channel = self.make_request("GET", path)
|
||||||
self.assertEquals(expect_code, channel.code)
|
self.assertEquals(expect_code, channel.code)
|
||||||
|
|
||||||
def test_membership_basic_room_perms(self):
|
def test_membership_basic_room_perms(self):
|
||||||
|
@ -380,16 +380,16 @@ class RoomsMemberListTestCase(RoomBase):
|
||||||
|
|
||||||
def test_get_member_list(self):
|
def test_get_member_list(self):
|
||||||
room_id = self.helper.create_room_as(self.user_id)
|
room_id = self.helper.create_room_as(self.user_id)
|
||||||
request, channel = self.make_request("GET", "/rooms/%s/members" % room_id)
|
channel = self.make_request("GET", "/rooms/%s/members" % room_id)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
def test_get_member_list_no_room(self):
|
def test_get_member_list_no_room(self):
|
||||||
request, channel = self.make_request("GET", "/rooms/roomdoesnotexist/members")
|
channel = self.make_request("GET", "/rooms/roomdoesnotexist/members")
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
def test_get_member_list_no_permission(self):
|
def test_get_member_list_no_permission(self):
|
||||||
room_id = self.helper.create_room_as("@some_other_guy:red")
|
room_id = self.helper.create_room_as("@some_other_guy:red")
|
||||||
request, channel = self.make_request("GET", "/rooms/%s/members" % room_id)
|
channel = self.make_request("GET", "/rooms/%s/members" % room_id)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
def test_get_member_list_mixed_memberships(self):
|
def test_get_member_list_mixed_memberships(self):
|
||||||
|
@ -398,17 +398,17 @@ class RoomsMemberListTestCase(RoomBase):
|
||||||
room_path = "/rooms/%s/members" % room_id
|
room_path = "/rooms/%s/members" % room_id
|
||||||
self.helper.invite(room=room_id, src=room_creator, targ=self.user_id)
|
self.helper.invite(room=room_id, src=room_creator, targ=self.user_id)
|
||||||
# can't see list if you're just invited.
|
# can't see list if you're just invited.
|
||||||
request, channel = self.make_request("GET", room_path)
|
channel = self.make_request("GET", room_path)
|
||||||
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
self.assertEquals(403, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
self.helper.join(room=room_id, user=self.user_id)
|
self.helper.join(room=room_id, user=self.user_id)
|
||||||
# can see list now joined
|
# can see list now joined
|
||||||
request, channel = self.make_request("GET", room_path)
|
channel = self.make_request("GET", room_path)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
self.helper.leave(room=room_id, user=self.user_id)
|
self.helper.leave(room=room_id, user=self.user_id)
|
||||||
# can see old list once left
|
# can see old list once left
|
||||||
request, channel = self.make_request("GET", room_path)
|
channel = self.make_request("GET", room_path)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
|
|
||||||
|
@ -419,30 +419,26 @@ class RoomsCreateTestCase(RoomBase):
|
||||||
|
|
||||||
def test_post_room_no_keys(self):
|
def test_post_room_no_keys(self):
|
||||||
# POST with no config keys, expect new room id
|
# POST with no config keys, expect new room id
|
||||||
request, channel = self.make_request("POST", "/createRoom", "{}")
|
channel = self.make_request("POST", "/createRoom", "{}")
|
||||||
|
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
self.assertTrue("room_id" in channel.json_body)
|
self.assertTrue("room_id" in channel.json_body)
|
||||||
|
|
||||||
def test_post_room_visibility_key(self):
|
def test_post_room_visibility_key(self):
|
||||||
# POST with visibility config key, expect new room id
|
# POST with visibility config key, expect new room id
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("POST", "/createRoom", b'{"visibility":"private"}')
|
||||||
"POST", "/createRoom", b'{"visibility":"private"}'
|
|
||||||
)
|
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
self.assertTrue("room_id" in channel.json_body)
|
self.assertTrue("room_id" in channel.json_body)
|
||||||
|
|
||||||
def test_post_room_custom_key(self):
|
def test_post_room_custom_key(self):
|
||||||
# POST with custom config keys, expect new room id
|
# POST with custom config keys, expect new room id
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("POST", "/createRoom", b'{"custom":"stuff"}')
|
||||||
"POST", "/createRoom", b'{"custom":"stuff"}'
|
|
||||||
)
|
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
self.assertTrue("room_id" in channel.json_body)
|
self.assertTrue("room_id" in channel.json_body)
|
||||||
|
|
||||||
def test_post_room_known_and_unknown_keys(self):
|
def test_post_room_known_and_unknown_keys(self):
|
||||||
# POST with custom + known config keys, expect new room id
|
# POST with custom + known config keys, expect new room id
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "/createRoom", b'{"visibility":"private","custom":"things"}'
|
"POST", "/createRoom", b'{"visibility":"private","custom":"things"}'
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
@ -450,16 +446,16 @@ class RoomsCreateTestCase(RoomBase):
|
||||||
|
|
||||||
def test_post_room_invalid_content(self):
|
def test_post_room_invalid_content(self):
|
||||||
# POST with invalid content / paths, expect 400
|
# POST with invalid content / paths, expect 400
|
||||||
request, channel = self.make_request("POST", "/createRoom", b'{"visibili')
|
channel = self.make_request("POST", "/createRoom", b'{"visibili')
|
||||||
self.assertEquals(400, channel.code)
|
self.assertEquals(400, channel.code)
|
||||||
|
|
||||||
request, channel = self.make_request("POST", "/createRoom", b'["hello"]')
|
channel = self.make_request("POST", "/createRoom", b'["hello"]')
|
||||||
self.assertEquals(400, channel.code)
|
self.assertEquals(400, channel.code)
|
||||||
|
|
||||||
def test_post_room_invitees_invalid_mxid(self):
|
def test_post_room_invitees_invalid_mxid(self):
|
||||||
# POST with invalid invitee, see https://github.com/matrix-org/synapse/issues/4088
|
# POST with invalid invitee, see https://github.com/matrix-org/synapse/issues/4088
|
||||||
# Note the trailing space in the MXID here!
|
# Note the trailing space in the MXID here!
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "/createRoom", b'{"invite":["@alice:example.com "]}'
|
"POST", "/createRoom", b'{"invite":["@alice:example.com "]}'
|
||||||
)
|
)
|
||||||
self.assertEquals(400, channel.code)
|
self.assertEquals(400, channel.code)
|
||||||
|
@ -477,54 +473,54 @@ class RoomTopicTestCase(RoomBase):
|
||||||
|
|
||||||
def test_invalid_puts(self):
|
def test_invalid_puts(self):
|
||||||
# missing keys or invalid json
|
# missing keys or invalid json
|
||||||
request, channel = self.make_request("PUT", self.path, "{}")
|
channel = self.make_request("PUT", self.path, "{}")
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", self.path, '{"_name":"bo"}')
|
channel = self.make_request("PUT", self.path, '{"_name":"bo"}')
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", self.path, '{"nao')
|
channel = self.make_request("PUT", self.path, '{"nao')
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", self.path, '[{"_name":"bo"},{"_name":"jill"}]'
|
"PUT", self.path, '[{"_name":"bo"},{"_name":"jill"}]'
|
||||||
)
|
)
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", self.path, "text only")
|
channel = self.make_request("PUT", self.path, "text only")
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", self.path, "")
|
channel = self.make_request("PUT", self.path, "")
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# valid key, wrong type
|
# valid key, wrong type
|
||||||
content = '{"topic":["Topic name"]}'
|
content = '{"topic":["Topic name"]}'
|
||||||
request, channel = self.make_request("PUT", self.path, content)
|
channel = self.make_request("PUT", self.path, content)
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
def test_rooms_topic(self):
|
def test_rooms_topic(self):
|
||||||
# nothing should be there
|
# nothing should be there
|
||||||
request, channel = self.make_request("GET", self.path)
|
channel = self.make_request("GET", self.path)
|
||||||
self.assertEquals(404, channel.code, msg=channel.result["body"])
|
self.assertEquals(404, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# valid put
|
# valid put
|
||||||
content = '{"topic":"Topic name"}'
|
content = '{"topic":"Topic name"}'
|
||||||
request, channel = self.make_request("PUT", self.path, content)
|
channel = self.make_request("PUT", self.path, content)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# valid get
|
# valid get
|
||||||
request, channel = self.make_request("GET", self.path)
|
channel = self.make_request("GET", self.path)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
self.assert_dict(json.loads(content), channel.json_body)
|
self.assert_dict(json.loads(content), channel.json_body)
|
||||||
|
|
||||||
def test_rooms_topic_with_extra_keys(self):
|
def test_rooms_topic_with_extra_keys(self):
|
||||||
# valid put with extra keys
|
# valid put with extra keys
|
||||||
content = '{"topic":"Seasons","subtopic":"Summer"}'
|
content = '{"topic":"Seasons","subtopic":"Summer"}'
|
||||||
request, channel = self.make_request("PUT", self.path, content)
|
channel = self.make_request("PUT", self.path, content)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# valid get
|
# valid get
|
||||||
request, channel = self.make_request("GET", self.path)
|
channel = self.make_request("GET", self.path)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
self.assert_dict(json.loads(content), channel.json_body)
|
self.assert_dict(json.loads(content), channel.json_body)
|
||||||
|
|
||||||
|
@ -540,24 +536,22 @@ class RoomMemberStateTestCase(RoomBase):
|
||||||
def test_invalid_puts(self):
|
def test_invalid_puts(self):
|
||||||
path = "/rooms/%s/state/m.room.member/%s" % (self.room_id, self.user_id)
|
path = "/rooms/%s/state/m.room.member/%s" % (self.room_id, self.user_id)
|
||||||
# missing keys or invalid json
|
# missing keys or invalid json
|
||||||
request, channel = self.make_request("PUT", path, "{}")
|
channel = self.make_request("PUT", path, "{}")
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", path, '{"_name":"bo"}')
|
channel = self.make_request("PUT", path, '{"_name":"bo"}')
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", path, '{"nao')
|
channel = self.make_request("PUT", path, '{"nao')
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("PUT", path, b'[{"_name":"bo"},{"_name":"jill"}]')
|
||||||
"PUT", path, b'[{"_name":"bo"},{"_name":"jill"}]'
|
|
||||||
)
|
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", path, "text only")
|
channel = self.make_request("PUT", path, "text only")
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", path, "")
|
channel = self.make_request("PUT", path, "")
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# valid keys, wrong types
|
# valid keys, wrong types
|
||||||
|
@ -566,7 +560,7 @@ class RoomMemberStateTestCase(RoomBase):
|
||||||
Membership.JOIN,
|
Membership.JOIN,
|
||||||
Membership.LEAVE,
|
Membership.LEAVE,
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("PUT", path, content.encode("ascii"))
|
channel = self.make_request("PUT", path, content.encode("ascii"))
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
def test_rooms_members_self(self):
|
def test_rooms_members_self(self):
|
||||||
|
@ -577,10 +571,10 @@ class RoomMemberStateTestCase(RoomBase):
|
||||||
|
|
||||||
# valid join message (NOOP since we made the room)
|
# valid join message (NOOP since we made the room)
|
||||||
content = '{"membership":"%s"}' % Membership.JOIN
|
content = '{"membership":"%s"}' % Membership.JOIN
|
||||||
request, channel = self.make_request("PUT", path, content.encode("ascii"))
|
channel = self.make_request("PUT", path, content.encode("ascii"))
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("GET", path, None)
|
channel = self.make_request("GET", path, None)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
expected_response = {"membership": Membership.JOIN}
|
expected_response = {"membership": Membership.JOIN}
|
||||||
|
@ -595,10 +589,10 @@ class RoomMemberStateTestCase(RoomBase):
|
||||||
|
|
||||||
# valid invite message
|
# valid invite message
|
||||||
content = '{"membership":"%s"}' % Membership.INVITE
|
content = '{"membership":"%s"}' % Membership.INVITE
|
||||||
request, channel = self.make_request("PUT", path, content)
|
channel = self.make_request("PUT", path, content)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("GET", path, None)
|
channel = self.make_request("GET", path, None)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
self.assertEquals(json.loads(content), channel.json_body)
|
self.assertEquals(json.loads(content), channel.json_body)
|
||||||
|
|
||||||
|
@ -614,10 +608,10 @@ class RoomMemberStateTestCase(RoomBase):
|
||||||
Membership.INVITE,
|
Membership.INVITE,
|
||||||
"Join us!",
|
"Join us!",
|
||||||
)
|
)
|
||||||
request, channel = self.make_request("PUT", path, content)
|
channel = self.make_request("PUT", path, content)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("GET", path, None)
|
channel = self.make_request("GET", path, None)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
self.assertEquals(json.loads(content), channel.json_body)
|
self.assertEquals(json.loads(content), channel.json_body)
|
||||||
|
|
||||||
|
@ -668,7 +662,7 @@ class RoomJoinRatelimitTestCase(RoomBase):
|
||||||
|
|
||||||
# Update the display name for the user.
|
# Update the display name for the user.
|
||||||
path = "/_matrix/client/r0/profile/%s/displayname" % self.user_id
|
path = "/_matrix/client/r0/profile/%s/displayname" % self.user_id
|
||||||
request, channel = self.make_request("PUT", path, {"displayname": "John Doe"})
|
channel = self.make_request("PUT", path, {"displayname": "John Doe"})
|
||||||
self.assertEquals(channel.code, 200, channel.json_body)
|
self.assertEquals(channel.code, 200, channel.json_body)
|
||||||
|
|
||||||
# Check that all the rooms have been sent a profile update into.
|
# Check that all the rooms have been sent a profile update into.
|
||||||
|
@ -678,7 +672,7 @@ class RoomJoinRatelimitTestCase(RoomBase):
|
||||||
self.user_id,
|
self.user_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request("GET", path)
|
channel = self.make_request("GET", path)
|
||||||
self.assertEquals(channel.code, 200)
|
self.assertEquals(channel.code, 200)
|
||||||
|
|
||||||
self.assertIn("displayname", channel.json_body)
|
self.assertIn("displayname", channel.json_body)
|
||||||
|
@ -702,7 +696,7 @@ class RoomJoinRatelimitTestCase(RoomBase):
|
||||||
# Make sure we send more requests than the rate-limiting config would allow
|
# Make sure we send more requests than the rate-limiting config would allow
|
||||||
# if all of these requests ended up joining the user to a room.
|
# if all of these requests ended up joining the user to a room.
|
||||||
for i in range(4):
|
for i in range(4):
|
||||||
request, channel = self.make_request("POST", path % room_id, {})
|
channel = self.make_request("POST", path % room_id, {})
|
||||||
self.assertEquals(channel.code, 200)
|
self.assertEquals(channel.code, 200)
|
||||||
|
|
||||||
@unittest.override_config(
|
@unittest.override_config(
|
||||||
|
@ -731,42 +725,40 @@ class RoomMessagesTestCase(RoomBase):
|
||||||
def test_invalid_puts(self):
|
def test_invalid_puts(self):
|
||||||
path = "/rooms/%s/send/m.room.message/mid1" % (urlparse.quote(self.room_id))
|
path = "/rooms/%s/send/m.room.message/mid1" % (urlparse.quote(self.room_id))
|
||||||
# missing keys or invalid json
|
# missing keys or invalid json
|
||||||
request, channel = self.make_request("PUT", path, b"{}")
|
channel = self.make_request("PUT", path, b"{}")
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", path, b'{"_name":"bo"}')
|
channel = self.make_request("PUT", path, b'{"_name":"bo"}')
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", path, b'{"nao')
|
channel = self.make_request("PUT", path, b'{"nao')
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("PUT", path, b'[{"_name":"bo"},{"_name":"jill"}]')
|
||||||
"PUT", path, b'[{"_name":"bo"},{"_name":"jill"}]'
|
|
||||||
)
|
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", path, b"text only")
|
channel = self.make_request("PUT", path, b"text only")
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
request, channel = self.make_request("PUT", path, b"")
|
channel = self.make_request("PUT", path, b"")
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
def test_rooms_messages_sent(self):
|
def test_rooms_messages_sent(self):
|
||||||
path = "/rooms/%s/send/m.room.message/mid1" % (urlparse.quote(self.room_id))
|
path = "/rooms/%s/send/m.room.message/mid1" % (urlparse.quote(self.room_id))
|
||||||
|
|
||||||
content = b'{"body":"test","msgtype":{"type":"a"}}'
|
content = b'{"body":"test","msgtype":{"type":"a"}}'
|
||||||
request, channel = self.make_request("PUT", path, content)
|
channel = self.make_request("PUT", path, content)
|
||||||
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
self.assertEquals(400, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# custom message types
|
# custom message types
|
||||||
content = b'{"body":"test","msgtype":"test.custom.text"}'
|
content = b'{"body":"test","msgtype":"test.custom.text"}'
|
||||||
request, channel = self.make_request("PUT", path, content)
|
channel = self.make_request("PUT", path, content)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
# m.text message type
|
# m.text message type
|
||||||
path = "/rooms/%s/send/m.room.message/mid2" % (urlparse.quote(self.room_id))
|
path = "/rooms/%s/send/m.room.message/mid2" % (urlparse.quote(self.room_id))
|
||||||
content = b'{"body":"test2","msgtype":"m.text"}'
|
content = b'{"body":"test2","msgtype":"m.text"}'
|
||||||
request, channel = self.make_request("PUT", path, content)
|
channel = self.make_request("PUT", path, content)
|
||||||
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
self.assertEquals(200, channel.code, msg=channel.result["body"])
|
||||||
|
|
||||||
|
|
||||||
|
@ -780,9 +772,7 @@ class RoomInitialSyncTestCase(RoomBase):
|
||||||
self.room_id = self.helper.create_room_as(self.user_id)
|
self.room_id = self.helper.create_room_as(self.user_id)
|
||||||
|
|
||||||
def test_initial_sync(self):
|
def test_initial_sync(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "/rooms/%s/initialSync" % self.room_id)
|
||||||
"GET", "/rooms/%s/initialSync" % self.room_id
|
|
||||||
)
|
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
|
||||||
self.assertEquals(self.room_id, channel.json_body["room_id"])
|
self.assertEquals(self.room_id, channel.json_body["room_id"])
|
||||||
|
@ -823,7 +813,7 @@ class RoomMessageListTestCase(RoomBase):
|
||||||
|
|
||||||
def test_topo_token_is_accepted(self):
|
def test_topo_token_is_accepted(self):
|
||||||
token = "t1-0_0_0_0_0_0_0_0_0"
|
token = "t1-0_0_0_0_0_0_0_0_0"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/rooms/%s/messages?access_token=x&from=%s" % (self.room_id, token)
|
"GET", "/rooms/%s/messages?access_token=x&from=%s" % (self.room_id, token)
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
@ -834,7 +824,7 @@ class RoomMessageListTestCase(RoomBase):
|
||||||
|
|
||||||
def test_stream_token_is_accepted_for_fwd_pagianation(self):
|
def test_stream_token_is_accepted_for_fwd_pagianation(self):
|
||||||
token = "s0_0_0_0_0_0_0_0_0"
|
token = "s0_0_0_0_0_0_0_0_0"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/rooms/%s/messages?access_token=x&from=%s" % (self.room_id, token)
|
"GET", "/rooms/%s/messages?access_token=x&from=%s" % (self.room_id, token)
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
@ -867,7 +857,7 @@ class RoomMessageListTestCase(RoomBase):
|
||||||
self.helper.send(self.room_id, "message 3")
|
self.helper.send(self.room_id, "message 3")
|
||||||
|
|
||||||
# Check that we get the first and second message when querying /messages.
|
# Check that we get the first and second message when querying /messages.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/messages?access_token=x&from=%s&dir=b&filter=%s"
|
"/rooms/%s/messages?access_token=x&from=%s&dir=b&filter=%s"
|
||||||
% (
|
% (
|
||||||
|
@ -895,7 +885,7 @@ class RoomMessageListTestCase(RoomBase):
|
||||||
|
|
||||||
# Check that we only get the second message through /message now that the first
|
# Check that we only get the second message through /message now that the first
|
||||||
# has been purged.
|
# has been purged.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/messages?access_token=x&from=%s&dir=b&filter=%s"
|
"/rooms/%s/messages?access_token=x&from=%s&dir=b&filter=%s"
|
||||||
% (
|
% (
|
||||||
|
@ -912,7 +902,7 @@ class RoomMessageListTestCase(RoomBase):
|
||||||
# Check that we get no event, but also no error, when querying /messages with
|
# Check that we get no event, but also no error, when querying /messages with
|
||||||
# the token that was pointing at the first event, because we don't have it
|
# the token that was pointing at the first event, because we don't have it
|
||||||
# anymore.
|
# anymore.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/messages?access_token=x&from=%s&dir=b&filter=%s"
|
"/rooms/%s/messages?access_token=x&from=%s&dir=b&filter=%s"
|
||||||
% (
|
% (
|
||||||
|
@ -971,7 +961,7 @@ class RoomSearchTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.send(self.room, body="Hi!", tok=self.other_access_token)
|
self.helper.send(self.room, body="Hi!", tok=self.other_access_token)
|
||||||
self.helper.send(self.room, body="There!", tok=self.other_access_token)
|
self.helper.send(self.room, body="There!", tok=self.other_access_token)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/search?access_token=%s" % (self.access_token,),
|
"/search?access_token=%s" % (self.access_token,),
|
||||||
{
|
{
|
||||||
|
@ -1000,7 +990,7 @@ class RoomSearchTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.send(self.room, body="Hi!", tok=self.other_access_token)
|
self.helper.send(self.room, body="Hi!", tok=self.other_access_token)
|
||||||
self.helper.send(self.room, body="There!", tok=self.other_access_token)
|
self.helper.send(self.room, body="There!", tok=self.other_access_token)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/search?access_token=%s" % (self.access_token,),
|
"/search?access_token=%s" % (self.access_token,),
|
||||||
{
|
{
|
||||||
|
@ -1048,14 +1038,14 @@ class PublicRoomsRestrictedTestCase(unittest.HomeserverTestCase):
|
||||||
return self.hs
|
return self.hs
|
||||||
|
|
||||||
def test_restricted_no_auth(self):
|
def test_restricted_no_auth(self):
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
self.assertEqual(channel.code, 401, channel.result)
|
self.assertEqual(channel.code, 401, channel.result)
|
||||||
|
|
||||||
def test_restricted_auth(self):
|
def test_restricted_auth(self):
|
||||||
self.register_user("user", "pass")
|
self.register_user("user", "pass")
|
||||||
tok = self.login("user", "pass")
|
tok = self.login("user", "pass")
|
||||||
|
|
||||||
request, channel = self.make_request("GET", self.url, access_token=tok)
|
channel = self.make_request("GET", self.url, access_token=tok)
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1083,7 +1073,7 @@ class PerRoomProfilesForbiddenTestCase(unittest.HomeserverTestCase):
|
||||||
self.displayname = "test user"
|
self.displayname = "test user"
|
||||||
data = {"displayname": self.displayname}
|
data = {"displayname": self.displayname}
|
||||||
request_data = json.dumps(data)
|
request_data = json.dumps(data)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/_matrix/client/r0/profile/%s/displayname" % (self.user_id,),
|
"/_matrix/client/r0/profile/%s/displayname" % (self.user_id,),
|
||||||
request_data,
|
request_data,
|
||||||
|
@ -1096,7 +1086,7 @@ class PerRoomProfilesForbiddenTestCase(unittest.HomeserverTestCase):
|
||||||
def test_per_room_profile_forbidden(self):
|
def test_per_room_profile_forbidden(self):
|
||||||
data = {"membership": "join", "displayname": "other test user"}
|
data = {"membership": "join", "displayname": "other test user"}
|
||||||
request_data = json.dumps(data)
|
request_data = json.dumps(data)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/_matrix/client/r0/rooms/%s/state/m.room.member/%s"
|
"/_matrix/client/r0/rooms/%s/state/m.room.member/%s"
|
||||||
% (self.room_id, self.user_id),
|
% (self.room_id, self.user_id),
|
||||||
|
@ -1106,7 +1096,7 @@ class PerRoomProfilesForbiddenTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
event_id = channel.json_body["event_id"]
|
event_id = channel.json_body["event_id"]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/r0/rooms/%s/event/%s" % (self.room_id, event_id),
|
"/_matrix/client/r0/rooms/%s/event/%s" % (self.room_id, event_id),
|
||||||
access_token=self.tok,
|
access_token=self.tok,
|
||||||
|
@ -1139,7 +1129,7 @@ class RoomMembershipReasonTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_join_reason(self):
|
def test_join_reason(self):
|
||||||
reason = "hello"
|
reason = "hello"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/rooms/{}/join".format(self.room_id),
|
"/_matrix/client/r0/rooms/{}/join".format(self.room_id),
|
||||||
content={"reason": reason},
|
content={"reason": reason},
|
||||||
|
@ -1153,7 +1143,7 @@ class RoomMembershipReasonTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.join(self.room_id, user=self.second_user_id, tok=self.second_tok)
|
self.helper.join(self.room_id, user=self.second_user_id, tok=self.second_tok)
|
||||||
|
|
||||||
reason = "hello"
|
reason = "hello"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/rooms/{}/leave".format(self.room_id),
|
"/_matrix/client/r0/rooms/{}/leave".format(self.room_id),
|
||||||
content={"reason": reason},
|
content={"reason": reason},
|
||||||
|
@ -1167,7 +1157,7 @@ class RoomMembershipReasonTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.join(self.room_id, user=self.second_user_id, tok=self.second_tok)
|
self.helper.join(self.room_id, user=self.second_user_id, tok=self.second_tok)
|
||||||
|
|
||||||
reason = "hello"
|
reason = "hello"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/rooms/{}/kick".format(self.room_id),
|
"/_matrix/client/r0/rooms/{}/kick".format(self.room_id),
|
||||||
content={"reason": reason, "user_id": self.second_user_id},
|
content={"reason": reason, "user_id": self.second_user_id},
|
||||||
|
@ -1181,7 +1171,7 @@ class RoomMembershipReasonTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.join(self.room_id, user=self.second_user_id, tok=self.second_tok)
|
self.helper.join(self.room_id, user=self.second_user_id, tok=self.second_tok)
|
||||||
|
|
||||||
reason = "hello"
|
reason = "hello"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/rooms/{}/ban".format(self.room_id),
|
"/_matrix/client/r0/rooms/{}/ban".format(self.room_id),
|
||||||
content={"reason": reason, "user_id": self.second_user_id},
|
content={"reason": reason, "user_id": self.second_user_id},
|
||||||
|
@ -1193,7 +1183,7 @@ class RoomMembershipReasonTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_unban_reason(self):
|
def test_unban_reason(self):
|
||||||
reason = "hello"
|
reason = "hello"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/rooms/{}/unban".format(self.room_id),
|
"/_matrix/client/r0/rooms/{}/unban".format(self.room_id),
|
||||||
content={"reason": reason, "user_id": self.second_user_id},
|
content={"reason": reason, "user_id": self.second_user_id},
|
||||||
|
@ -1205,7 +1195,7 @@ class RoomMembershipReasonTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_invite_reason(self):
|
def test_invite_reason(self):
|
||||||
reason = "hello"
|
reason = "hello"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/rooms/{}/invite".format(self.room_id),
|
"/_matrix/client/r0/rooms/{}/invite".format(self.room_id),
|
||||||
content={"reason": reason, "user_id": self.second_user_id},
|
content={"reason": reason, "user_id": self.second_user_id},
|
||||||
|
@ -1224,7 +1214,7 @@ class RoomMembershipReasonTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
reason = "hello"
|
reason = "hello"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/rooms/{}/leave".format(self.room_id),
|
"/_matrix/client/r0/rooms/{}/leave".format(self.room_id),
|
||||||
content={"reason": reason},
|
content={"reason": reason},
|
||||||
|
@ -1235,7 +1225,7 @@ class RoomMembershipReasonTestCase(unittest.HomeserverTestCase):
|
||||||
self._check_for_reason(reason)
|
self._check_for_reason(reason)
|
||||||
|
|
||||||
def _check_for_reason(self, reason):
|
def _check_for_reason(self, reason):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/r0/rooms/{}/state/m.room.member/{}".format(
|
"/_matrix/client/r0/rooms/{}/state/m.room.member/{}".format(
|
||||||
self.room_id, self.second_user_id
|
self.room_id, self.second_user_id
|
||||||
|
@ -1284,7 +1274,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
|
||||||
"""Test that we can filter by a label on a /context request."""
|
"""Test that we can filter by a label on a /context request."""
|
||||||
event_id = self._send_labelled_messages_in_room()
|
event_id = self._send_labelled_messages_in_room()
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/context/%s?filter=%s"
|
"/rooms/%s/context/%s?filter=%s"
|
||||||
% (self.room_id, event_id, json.dumps(self.FILTER_LABELS)),
|
% (self.room_id, event_id, json.dumps(self.FILTER_LABELS)),
|
||||||
|
@ -1314,7 +1304,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
|
||||||
"""Test that we can filter by the absence of a label on a /context request."""
|
"""Test that we can filter by the absence of a label on a /context request."""
|
||||||
event_id = self._send_labelled_messages_in_room()
|
event_id = self._send_labelled_messages_in_room()
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/context/%s?filter=%s"
|
"/rooms/%s/context/%s?filter=%s"
|
||||||
% (self.room_id, event_id, json.dumps(self.FILTER_NOT_LABELS)),
|
% (self.room_id, event_id, json.dumps(self.FILTER_NOT_LABELS)),
|
||||||
|
@ -1349,7 +1339,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
event_id = self._send_labelled_messages_in_room()
|
event_id = self._send_labelled_messages_in_room()
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/context/%s?filter=%s"
|
"/rooms/%s/context/%s?filter=%s"
|
||||||
% (self.room_id, event_id, json.dumps(self.FILTER_LABELS_NOT_LABELS)),
|
% (self.room_id, event_id, json.dumps(self.FILTER_LABELS_NOT_LABELS)),
|
||||||
|
@ -1377,7 +1367,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
|
||||||
self._send_labelled_messages_in_room()
|
self._send_labelled_messages_in_room()
|
||||||
|
|
||||||
token = "s0_0_0_0_0_0_0_0_0"
|
token = "s0_0_0_0_0_0_0_0_0"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/messages?access_token=%s&from=%s&filter=%s"
|
"/rooms/%s/messages?access_token=%s&from=%s&filter=%s"
|
||||||
% (self.room_id, self.tok, token, json.dumps(self.FILTER_LABELS)),
|
% (self.room_id, self.tok, token, json.dumps(self.FILTER_LABELS)),
|
||||||
|
@ -1394,7 +1384,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
|
||||||
self._send_labelled_messages_in_room()
|
self._send_labelled_messages_in_room()
|
||||||
|
|
||||||
token = "s0_0_0_0_0_0_0_0_0"
|
token = "s0_0_0_0_0_0_0_0_0"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/messages?access_token=%s&from=%s&filter=%s"
|
"/rooms/%s/messages?access_token=%s&from=%s&filter=%s"
|
||||||
% (self.room_id, self.tok, token, json.dumps(self.FILTER_NOT_LABELS)),
|
% (self.room_id, self.tok, token, json.dumps(self.FILTER_NOT_LABELS)),
|
||||||
|
@ -1417,7 +1407,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
|
||||||
self._send_labelled_messages_in_room()
|
self._send_labelled_messages_in_room()
|
||||||
|
|
||||||
token = "s0_0_0_0_0_0_0_0_0"
|
token = "s0_0_0_0_0_0_0_0_0"
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/messages?access_token=%s&from=%s&filter=%s"
|
"/rooms/%s/messages?access_token=%s&from=%s&filter=%s"
|
||||||
% (
|
% (
|
||||||
|
@ -1448,7 +1438,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self._send_labelled_messages_in_room()
|
self._send_labelled_messages_in_room()
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "/search?access_token=%s" % self.tok, request_data
|
"POST", "/search?access_token=%s" % self.tok, request_data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1483,7 +1473,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self._send_labelled_messages_in_room()
|
self._send_labelled_messages_in_room()
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "/search?access_token=%s" % self.tok, request_data
|
"POST", "/search?access_token=%s" % self.tok, request_data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1530,7 +1520,7 @@ class LabelsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self._send_labelled_messages_in_room()
|
self._send_labelled_messages_in_room()
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "/search?access_token=%s" % self.tok, request_data
|
"POST", "/search?access_token=%s" % self.tok, request_data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1651,7 +1641,7 @@ class ContextTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Check that we can still see the messages before the erasure request.
|
# Check that we can still see the messages before the erasure request.
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
'/rooms/%s/context/%s?filter={"types":["m.room.message"]}'
|
'/rooms/%s/context/%s?filter={"types":["m.room.message"]}'
|
||||||
% (self.room_id, event_id),
|
% (self.room_id, event_id),
|
||||||
|
@ -1715,7 +1705,7 @@ class ContextTestCase(unittest.HomeserverTestCase):
|
||||||
# Check that a user that joined the room after the erasure request can't see
|
# Check that a user that joined the room after the erasure request can't see
|
||||||
# the messages anymore.
|
# the messages anymore.
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
'/rooms/%s/context/%s?filter={"types":["m.room.message"]}'
|
'/rooms/%s/context/%s?filter={"types":["m.room.message"]}'
|
||||||
% (self.room_id, event_id),
|
% (self.room_id, event_id),
|
||||||
|
@ -1805,7 +1795,7 @@ class RoomAliasListTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def _get_aliases(self, access_token: str, expected_code: int = 200) -> JsonDict:
|
def _get_aliases(self, access_token: str, expected_code: int = 200) -> JsonDict:
|
||||||
"""Calls the endpoint under test. returns the json response object."""
|
"""Calls the endpoint under test. returns the json response object."""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/org.matrix.msc2432/rooms/%s/aliases"
|
"/_matrix/client/unstable/org.matrix.msc2432/rooms/%s/aliases"
|
||||||
% (self.room_id,),
|
% (self.room_id,),
|
||||||
|
@ -1826,7 +1816,7 @@ class RoomAliasListTestCase(unittest.HomeserverTestCase):
|
||||||
data = {"room_id": self.room_id}
|
data = {"room_id": self.room_id}
|
||||||
request_data = json.dumps(data)
|
request_data = json.dumps(data)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", url, request_data, access_token=self.room_owner_tok
|
"PUT", url, request_data, access_token=self.room_owner_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, expected_code, channel.result)
|
self.assertEqual(channel.code, expected_code, channel.result)
|
||||||
|
@ -1856,14 +1846,14 @@ class RoomCanonicalAliasTestCase(unittest.HomeserverTestCase):
|
||||||
data = {"room_id": self.room_id}
|
data = {"room_id": self.room_id}
|
||||||
request_data = json.dumps(data)
|
request_data = json.dumps(data)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT", url, request_data, access_token=self.room_owner_tok
|
"PUT", url, request_data, access_token=self.room_owner_tok
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, expected_code, channel.result)
|
self.assertEqual(channel.code, expected_code, channel.result)
|
||||||
|
|
||||||
def _get_canonical_alias(self, expected_code: int = 200) -> JsonDict:
|
def _get_canonical_alias(self, expected_code: int = 200) -> JsonDict:
|
||||||
"""Calls the endpoint under test. returns the json response object."""
|
"""Calls the endpoint under test. returns the json response object."""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"rooms/%s/state/m.room.canonical_alias" % (self.room_id,),
|
"rooms/%s/state/m.room.canonical_alias" % (self.room_id,),
|
||||||
access_token=self.room_owner_tok,
|
access_token=self.room_owner_tok,
|
||||||
|
@ -1875,7 +1865,7 @@ class RoomCanonicalAliasTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def _set_canonical_alias(self, content: str, expected_code: int = 200) -> JsonDict:
|
def _set_canonical_alias(self, content: str, expected_code: int = 200) -> JsonDict:
|
||||||
"""Calls the endpoint under test. returns the json response object."""
|
"""Calls the endpoint under test. returns the json response object."""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"rooms/%s/state/m.room.canonical_alias" % (self.room_id,),
|
"rooms/%s/state/m.room.canonical_alias" % (self.room_id,),
|
||||||
json.dumps(content),
|
json.dumps(content),
|
||||||
|
|
|
@ -94,7 +94,7 @@ class RoomTypingTestCase(unittest.HomeserverTestCase):
|
||||||
self.helper.join(self.room_id, user="@jim:red")
|
self.helper.join(self.room_id, user="@jim:red")
|
||||||
|
|
||||||
def test_set_typing(self):
|
def test_set_typing(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
||||||
b'{"typing": true, "timeout": 30000}',
|
b'{"typing": true, "timeout": 30000}',
|
||||||
|
@ -117,7 +117,7 @@ class RoomTypingTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_set_not_typing(self):
|
def test_set_not_typing(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
||||||
b'{"typing": false}',
|
b'{"typing": false}',
|
||||||
|
@ -125,7 +125,7 @@ class RoomTypingTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
|
||||||
def test_typing_timeout(self):
|
def test_typing_timeout(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
||||||
b'{"typing": true, "timeout": 30000}',
|
b'{"typing": true, "timeout": 30000}',
|
||||||
|
@ -138,7 +138,7 @@ class RoomTypingTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self.assertEquals(self.event_source.get_current_key(), 2)
|
self.assertEquals(self.event_source.get_current_key(), 2)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
"/rooms/%s/typing/%s" % (self.room_id, self.user_id),
|
||||||
b'{"typing": true, "timeout": 30000}',
|
b'{"typing": true, "timeout": 30000}',
|
||||||
|
|
|
@ -81,7 +81,7 @@ class RestHelper:
|
||||||
if tok:
|
if tok:
|
||||||
path = path + "?access_token=%s" % tok
|
path = path + "?access_token=%s" % tok
|
||||||
|
|
||||||
_, channel = make_request(
|
channel = make_request(
|
||||||
self.hs.get_reactor(),
|
self.hs.get_reactor(),
|
||||||
self.site,
|
self.site,
|
||||||
"POST",
|
"POST",
|
||||||
|
@ -157,7 +157,7 @@ class RestHelper:
|
||||||
data = {"membership": membership}
|
data = {"membership": membership}
|
||||||
data.update(extra_data)
|
data.update(extra_data)
|
||||||
|
|
||||||
_, channel = make_request(
|
channel = make_request(
|
||||||
self.hs.get_reactor(),
|
self.hs.get_reactor(),
|
||||||
self.site,
|
self.site,
|
||||||
"PUT",
|
"PUT",
|
||||||
|
@ -192,7 +192,7 @@ class RestHelper:
|
||||||
if tok:
|
if tok:
|
||||||
path = path + "?access_token=%s" % tok
|
path = path + "?access_token=%s" % tok
|
||||||
|
|
||||||
_, channel = make_request(
|
channel = make_request(
|
||||||
self.hs.get_reactor(),
|
self.hs.get_reactor(),
|
||||||
self.site,
|
self.site,
|
||||||
"PUT",
|
"PUT",
|
||||||
|
@ -248,9 +248,7 @@ class RestHelper:
|
||||||
if body is not None:
|
if body is not None:
|
||||||
content = json.dumps(body).encode("utf8")
|
content = json.dumps(body).encode("utf8")
|
||||||
|
|
||||||
_, channel = make_request(
|
channel = make_request(self.hs.get_reactor(), self.site, method, path, content)
|
||||||
self.hs.get_reactor(), self.site, method, path, content
|
|
||||||
)
|
|
||||||
|
|
||||||
assert int(channel.result["code"]) == expect_code, (
|
assert int(channel.result["code"]) == expect_code, (
|
||||||
"Expected: %d, got: %d, resp: %r"
|
"Expected: %d, got: %d, resp: %r"
|
||||||
|
@ -333,7 +331,7 @@ class RestHelper:
|
||||||
"""
|
"""
|
||||||
image_length = len(image_data)
|
image_length = len(image_data)
|
||||||
path = "/_matrix/media/r0/upload?filename=%s" % (filename,)
|
path = "/_matrix/media/r0/upload?filename=%s" % (filename,)
|
||||||
_, channel = make_request(
|
channel = make_request(
|
||||||
self.hs.get_reactor(),
|
self.hs.get_reactor(),
|
||||||
FakeSite(resource),
|
FakeSite(resource),
|
||||||
"POST",
|
"POST",
|
||||||
|
@ -366,7 +364,7 @@ class RestHelper:
|
||||||
client_redirect_url = "https://x"
|
client_redirect_url = "https://x"
|
||||||
|
|
||||||
# first hit the redirect url (which will issue a cookie and state)
|
# first hit the redirect url (which will issue a cookie and state)
|
||||||
_, channel = make_request(
|
channel = make_request(
|
||||||
self.hs.get_reactor(),
|
self.hs.get_reactor(),
|
||||||
self.site,
|
self.site,
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -411,7 +409,7 @@ class RestHelper:
|
||||||
|
|
||||||
with patch.object(self.hs.get_proxied_http_client(), "request", mock_req):
|
with patch.object(self.hs.get_proxied_http_client(), "request", mock_req):
|
||||||
# now hit the callback URI with the right params and a made-up code
|
# now hit the callback URI with the right params and a made-up code
|
||||||
_, channel = make_request(
|
channel = make_request(
|
||||||
self.hs.get_reactor(),
|
self.hs.get_reactor(),
|
||||||
self.site,
|
self.site,
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -434,7 +432,7 @@ class RestHelper:
|
||||||
|
|
||||||
# finally, submit the matrix login token to the login API, which gives us our
|
# finally, submit the matrix login token to the login API, which gives us our
|
||||||
# matrix access token and device id.
|
# matrix access token and device id.
|
||||||
_, channel = make_request(
|
channel = make_request(
|
||||||
self.hs.get_reactor(),
|
self.hs.get_reactor(),
|
||||||
self.site,
|
self.site,
|
||||||
"POST",
|
"POST",
|
||||||
|
|
|
@ -19,7 +19,6 @@ import os
|
||||||
import re
|
import re
|
||||||
from email.parser import Parser
|
from email.parser import Parser
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from urllib.parse import urlencode
|
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
|
@ -241,7 +240,7 @@ class PasswordResetTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertIsNotNone(session_id)
|
self.assertIsNotNone(session_id)
|
||||||
|
|
||||||
def _request_token(self, email, client_secret):
|
def _request_token(self, email, client_secret):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
b"account/password/email/requestToken",
|
b"account/password/email/requestToken",
|
||||||
{"client_secret": client_secret, "email": email, "send_attempt": 1},
|
{"client_secret": client_secret, "email": email, "send_attempt": 1},
|
||||||
|
@ -255,7 +254,7 @@ class PasswordResetTestCase(unittest.HomeserverTestCase):
|
||||||
path = link.replace("https://example.com", "")
|
path = link.replace("https://example.com", "")
|
||||||
|
|
||||||
# Load the password reset confirmation page
|
# Load the password reset confirmation page
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(self.submit_token_resource),
|
FakeSite(self.submit_token_resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -268,20 +267,13 @@ class PasswordResetTestCase(unittest.HomeserverTestCase):
|
||||||
# Now POST to the same endpoint, mimicking the same behaviour as clicking the
|
# Now POST to the same endpoint, mimicking the same behaviour as clicking the
|
||||||
# password reset confirm button
|
# password reset confirm button
|
||||||
|
|
||||||
# Send arguments as url-encoded form data, matching the template's behaviour
|
|
||||||
form_args = []
|
|
||||||
for key, value_list in request.args.items():
|
|
||||||
for value in value_list:
|
|
||||||
arg = (key, value)
|
|
||||||
form_args.append(arg)
|
|
||||||
|
|
||||||
# Confirm the password reset
|
# Confirm the password reset
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(self.submit_token_resource),
|
FakeSite(self.submit_token_resource),
|
||||||
"POST",
|
"POST",
|
||||||
path,
|
path,
|
||||||
content=urlencode(form_args).encode("utf8"),
|
content=b"",
|
||||||
shorthand=False,
|
shorthand=False,
|
||||||
content_is_form=True,
|
content_is_form=True,
|
||||||
)
|
)
|
||||||
|
@ -310,7 +302,7 @@ class PasswordResetTestCase(unittest.HomeserverTestCase):
|
||||||
def _reset_password(
|
def _reset_password(
|
||||||
self, new_password, session_id, client_secret, expected_code=200
|
self, new_password, session_id, client_secret, expected_code=200
|
||||||
):
|
):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
b"account/password",
|
b"account/password",
|
||||||
{
|
{
|
||||||
|
@ -352,8 +344,8 @@ class DeactivateTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertTrue(self.get_success(store.get_user_deactivated_status(user_id)))
|
self.assertTrue(self.get_success(store.get_user_deactivated_status(user_id)))
|
||||||
|
|
||||||
# Check that this access token has been invalidated.
|
# Check that this access token has been invalidated.
|
||||||
request, channel = self.make_request("GET", "account/whoami")
|
channel = self.make_request("GET", "account/whoami")
|
||||||
self.assertEqual(request.code, 401)
|
self.assertEqual(channel.code, 401)
|
||||||
|
|
||||||
def test_pending_invites(self):
|
def test_pending_invites(self):
|
||||||
"""Tests that deactivating a user rejects every pending invite for them."""
|
"""Tests that deactivating a user rejects every pending invite for them."""
|
||||||
|
@ -407,10 +399,10 @@ class DeactivateTestCase(unittest.HomeserverTestCase):
|
||||||
"erase": False,
|
"erase": False,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "account/deactivate", request_data, access_token=tok
|
"POST", "account/deactivate", request_data, access_token=tok
|
||||||
)
|
)
|
||||||
self.assertEqual(request.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
|
|
||||||
class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
|
@ -530,7 +522,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self._validate_token(link)
|
self._validate_token(link)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
b"/_matrix/client/unstable/account/3pid/add",
|
b"/_matrix/client/unstable/account/3pid/add",
|
||||||
{
|
{
|
||||||
|
@ -548,7 +540,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_3pid, access_token=self.user_id_tok,
|
"GET", self.url_3pid, access_token=self.user_id_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -569,7 +561,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
b"account/3pid/delete",
|
b"account/3pid/delete",
|
||||||
{"medium": "email", "address": self.email},
|
{"medium": "email", "address": self.email},
|
||||||
|
@ -578,7 +570,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_3pid, access_token=self.user_id_tok,
|
"GET", self.url_3pid, access_token=self.user_id_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -601,7 +593,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
b"account/3pid/delete",
|
b"account/3pid/delete",
|
||||||
{"medium": "email", "address": self.email},
|
{"medium": "email", "address": self.email},
|
||||||
|
@ -612,7 +604,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_3pid, access_token=self.user_id_tok,
|
"GET", self.url_3pid, access_token=self.user_id_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -629,7 +621,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(len(self.email_attempts), 1)
|
self.assertEquals(len(self.email_attempts), 1)
|
||||||
|
|
||||||
# Attempt to add email without clicking the link
|
# Attempt to add email without clicking the link
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
b"/_matrix/client/unstable/account/3pid/add",
|
b"/_matrix/client/unstable/account/3pid/add",
|
||||||
{
|
{
|
||||||
|
@ -647,7 +639,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.THREEPID_AUTH_FAILED, channel.json_body["errcode"])
|
self.assertEqual(Codes.THREEPID_AUTH_FAILED, channel.json_body["errcode"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_3pid, access_token=self.user_id_tok,
|
"GET", self.url_3pid, access_token=self.user_id_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -662,7 +654,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
session_id = "weasle"
|
session_id = "weasle"
|
||||||
|
|
||||||
# Attempt to add email without even requesting an email
|
# Attempt to add email without even requesting an email
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
b"/_matrix/client/unstable/account/3pid/add",
|
b"/_matrix/client/unstable/account/3pid/add",
|
||||||
{
|
{
|
||||||
|
@ -680,7 +672,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(Codes.THREEPID_AUTH_FAILED, channel.json_body["errcode"])
|
self.assertEqual(Codes.THREEPID_AUTH_FAILED, channel.json_body["errcode"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_3pid, access_token=self.user_id_tok,
|
"GET", self.url_3pid, access_token=self.user_id_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -784,9 +776,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
if next_link:
|
if next_link:
|
||||||
body["next_link"] = next_link
|
body["next_link"] = next_link
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("POST", b"account/3pid/email/requestToken", body,)
|
||||||
"POST", b"account/3pid/email/requestToken", body,
|
|
||||||
)
|
|
||||||
self.assertEquals(expect_code, channel.code, channel.result)
|
self.assertEquals(expect_code, channel.code, channel.result)
|
||||||
|
|
||||||
return channel.json_body.get("sid")
|
return channel.json_body.get("sid")
|
||||||
|
@ -794,7 +784,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
def _request_token_invalid_email(
|
def _request_token_invalid_email(
|
||||||
self, email, expected_errcode, expected_error, client_secret="foobar",
|
self, email, expected_errcode, expected_error, client_secret="foobar",
|
||||||
):
|
):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
b"account/3pid/email/requestToken",
|
b"account/3pid/email/requestToken",
|
||||||
{"client_secret": client_secret, "email": email, "send_attempt": 1},
|
{"client_secret": client_secret, "email": email, "send_attempt": 1},
|
||||||
|
@ -807,7 +797,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
# Remove the host
|
# Remove the host
|
||||||
path = link.replace("https://example.com", "")
|
path = link.replace("https://example.com", "")
|
||||||
|
|
||||||
request, channel = self.make_request("GET", path, shorthand=False)
|
channel = self.make_request("GET", path, shorthand=False)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
|
|
||||||
def _get_link_from_email(self):
|
def _get_link_from_email(self):
|
||||||
|
@ -841,7 +831,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self._validate_token(link)
|
self._validate_token(link)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
b"/_matrix/client/unstable/account/3pid/add",
|
b"/_matrix/client/unstable/account/3pid/add",
|
||||||
{
|
{
|
||||||
|
@ -859,7 +849,7 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
self.assertEqual(200, int(channel.result["code"]), msg=channel.result["body"])
|
||||||
|
|
||||||
# Get user
|
# Get user
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url_3pid, access_token=self.user_id_tok,
|
"GET", self.url_3pid, access_token=self.user_id_tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ from twisted.internet.defer import succeed
|
||||||
import synapse.rest.admin
|
import synapse.rest.admin
|
||||||
from synapse.api.constants import LoginType
|
from synapse.api.constants import LoginType
|
||||||
from synapse.handlers.ui_auth.checkers import UserInteractiveAuthChecker
|
from synapse.handlers.ui_auth.checkers import UserInteractiveAuthChecker
|
||||||
from synapse.http.site import SynapseRequest
|
|
||||||
from synapse.rest.client.v1 import login
|
from synapse.rest.client.v1 import login
|
||||||
from synapse.rest.client.v2_alpha import auth, devices, register
|
from synapse.rest.client.v2_alpha import auth, devices, register
|
||||||
from synapse.rest.oidc import OIDCResource
|
from synapse.rest.oidc import OIDCResource
|
||||||
|
@ -67,11 +66,9 @@ class FallbackAuthTests(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def register(self, expected_response: int, body: JsonDict) -> FakeChannel:
|
def register(self, expected_response: int, body: JsonDict) -> FakeChannel:
|
||||||
"""Make a register request."""
|
"""Make a register request."""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("POST", "register", body)
|
||||||
"POST", "register", body
|
|
||||||
) # type: SynapseRequest, FakeChannel
|
|
||||||
|
|
||||||
self.assertEqual(request.code, expected_response)
|
self.assertEqual(channel.code, expected_response)
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
def recaptcha(
|
def recaptcha(
|
||||||
|
@ -81,18 +78,18 @@ class FallbackAuthTests(unittest.HomeserverTestCase):
|
||||||
if post_session is None:
|
if post_session is None:
|
||||||
post_session = session
|
post_session = session
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "auth/m.login.recaptcha/fallback/web?session=" + session
|
"GET", "auth/m.login.recaptcha/fallback/web?session=" + session
|
||||||
) # type: SynapseRequest, FakeChannel
|
)
|
||||||
self.assertEqual(request.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"auth/m.login.recaptcha/fallback/web?session="
|
"auth/m.login.recaptcha/fallback/web?session="
|
||||||
+ post_session
|
+ post_session
|
||||||
+ "&g-recaptcha-response=a",
|
+ "&g-recaptcha-response=a",
|
||||||
)
|
)
|
||||||
self.assertEqual(request.code, expected_post_response)
|
self.assertEqual(channel.code, expected_post_response)
|
||||||
|
|
||||||
# The recaptcha handler is called with the response given
|
# The recaptcha handler is called with the response given
|
||||||
attempts = self.recaptcha_checker.recaptcha_attempts
|
attempts = self.recaptcha_checker.recaptcha_attempts
|
||||||
|
@ -184,7 +181,7 @@ class UIAuthTests(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def get_device_ids(self, access_token: str) -> List[str]:
|
def get_device_ids(self, access_token: str) -> List[str]:
|
||||||
# Get the list of devices so one can be deleted.
|
# Get the list of devices so one can be deleted.
|
||||||
_, channel = self.make_request("GET", "devices", access_token=access_token,)
|
channel = self.make_request("GET", "devices", access_token=access_token,)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
return [d["device_id"] for d in channel.json_body["devices"]]
|
return [d["device_id"] for d in channel.json_body["devices"]]
|
||||||
|
|
||||||
|
@ -196,12 +193,12 @@ class UIAuthTests(unittest.HomeserverTestCase):
|
||||||
body: Union[bytes, JsonDict] = b"",
|
body: Union[bytes, JsonDict] = b"",
|
||||||
) -> FakeChannel:
|
) -> FakeChannel:
|
||||||
"""Delete an individual device."""
|
"""Delete an individual device."""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"DELETE", "devices/" + device, body, access_token=access_token,
|
"DELETE", "devices/" + device, body, access_token=access_token,
|
||||||
) # type: SynapseRequest, FakeChannel
|
)
|
||||||
|
|
||||||
# Ensure the response is sane.
|
# Ensure the response is sane.
|
||||||
self.assertEqual(request.code, expected_response)
|
self.assertEqual(channel.code, expected_response)
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
|
@ -209,12 +206,12 @@ class UIAuthTests(unittest.HomeserverTestCase):
|
||||||
"""Delete 1 or more devices."""
|
"""Delete 1 or more devices."""
|
||||||
# Note that this uses the delete_devices endpoint so that we can modify
|
# Note that this uses the delete_devices endpoint so that we can modify
|
||||||
# the payload half-way through some tests.
|
# the payload half-way through some tests.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "delete_devices", body, access_token=self.user_tok,
|
"POST", "delete_devices", body, access_token=self.user_tok,
|
||||||
) # type: SynapseRequest, FakeChannel
|
)
|
||||||
|
|
||||||
# Ensure the response is sane.
|
# Ensure the response is sane.
|
||||||
self.assertEqual(request.code, expected_response)
|
self.assertEqual(channel.code, expected_response)
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
|
||||||
return hs
|
return hs
|
||||||
|
|
||||||
def test_check_auth_required(self):
|
def test_check_auth_required(self):
|
||||||
request, channel = self.make_request("GET", self.url)
|
channel = self.make_request("GET", self.url)
|
||||||
|
|
||||||
self.assertEqual(channel.code, 401)
|
self.assertEqual(channel.code, 401)
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
|
||||||
self.register_user("user", "pass")
|
self.register_user("user", "pass")
|
||||||
access_token = self.login("user", "pass")
|
access_token = self.login("user", "pass")
|
||||||
|
|
||||||
request, channel = self.make_request("GET", self.url, access_token=access_token)
|
channel = self.make_request("GET", self.url, access_token=access_token)
|
||||||
capabilities = channel.json_body["capabilities"]
|
capabilities = channel.json_body["capabilities"]
|
||||||
|
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -62,7 +62,7 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
|
||||||
user = self.register_user(localpart, password)
|
user = self.register_user(localpart, password)
|
||||||
access_token = self.login(user, password)
|
access_token = self.login(user, password)
|
||||||
|
|
||||||
request, channel = self.make_request("GET", self.url, access_token=access_token)
|
channel = self.make_request("GET", self.url, access_token=access_token)
|
||||||
capabilities = channel.json_body["capabilities"]
|
capabilities = channel.json_body["capabilities"]
|
||||||
|
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -70,7 +70,7 @@ class CapabilitiesTestCase(unittest.HomeserverTestCase):
|
||||||
# Test case where password is handled outside of Synapse
|
# Test case where password is handled outside of Synapse
|
||||||
self.assertTrue(capabilities["m.change_password"]["enabled"])
|
self.assertTrue(capabilities["m.change_password"]["enabled"])
|
||||||
self.get_success(self.store.user_set_password_hash(user, None))
|
self.get_success(self.store.user_set_password_hash(user, None))
|
||||||
request, channel = self.make_request("GET", self.url, access_token=access_token)
|
channel = self.make_request("GET", self.url, access_token=access_token)
|
||||||
capabilities = channel.json_body["capabilities"]
|
capabilities = channel.json_body["capabilities"]
|
||||||
|
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
|
@ -36,7 +36,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
||||||
self.store = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
|
|
||||||
def test_add_filter(self):
|
def test_add_filter(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/user/%s/filter" % (self.user_id),
|
"/_matrix/client/r0/user/%s/filter" % (self.user_id),
|
||||||
self.EXAMPLE_FILTER_JSON,
|
self.EXAMPLE_FILTER_JSON,
|
||||||
|
@ -49,7 +49,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(filter.result, self.EXAMPLE_FILTER)
|
self.assertEquals(filter.result, self.EXAMPLE_FILTER)
|
||||||
|
|
||||||
def test_add_filter_for_other_user(self):
|
def test_add_filter_for_other_user(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/user/%s/filter" % ("@watermelon:test"),
|
"/_matrix/client/r0/user/%s/filter" % ("@watermelon:test"),
|
||||||
self.EXAMPLE_FILTER_JSON,
|
self.EXAMPLE_FILTER_JSON,
|
||||||
|
@ -61,7 +61,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
||||||
def test_add_filter_non_local_user(self):
|
def test_add_filter_non_local_user(self):
|
||||||
_is_mine = self.hs.is_mine
|
_is_mine = self.hs.is_mine
|
||||||
self.hs.is_mine = lambda target_user: False
|
self.hs.is_mine = lambda target_user: False
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/user/%s/filter" % (self.user_id),
|
"/_matrix/client/r0/user/%s/filter" % (self.user_id),
|
||||||
self.EXAMPLE_FILTER_JSON,
|
self.EXAMPLE_FILTER_JSON,
|
||||||
|
@ -79,7 +79,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
self.reactor.advance(1)
|
self.reactor.advance(1)
|
||||||
filter_id = filter_id.result
|
filter_id = filter_id.result
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/client/r0/user/%s/filter/%s" % (self.user_id, filter_id)
|
"GET", "/_matrix/client/r0/user/%s/filter/%s" % (self.user_id, filter_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(channel.json_body, self.EXAMPLE_FILTER)
|
self.assertEquals(channel.json_body, self.EXAMPLE_FILTER)
|
||||||
|
|
||||||
def test_get_filter_non_existant(self):
|
def test_get_filter_non_existant(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/client/r0/user/%s/filter/12382148321" % (self.user_id)
|
"GET", "/_matrix/client/r0/user/%s/filter/12382148321" % (self.user_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
||||||
# Currently invalid params do not have an appropriate errcode
|
# Currently invalid params do not have an appropriate errcode
|
||||||
# in errors.py
|
# in errors.py
|
||||||
def test_get_filter_invalid_id(self):
|
def test_get_filter_invalid_id(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/client/r0/user/%s/filter/foobar" % (self.user_id)
|
"GET", "/_matrix/client/r0/user/%s/filter/foobar" % (self.user_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# No ID also returns an invalid_id error
|
# No ID also returns an invalid_id error
|
||||||
def test_get_filter_no_id(self):
|
def test_get_filter_no_id(self):
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/client/r0/user/%s/filter/" % (self.user_id)
|
"GET", "/_matrix/client/r0/user/%s/filter/" % (self.user_id)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -70,9 +70,7 @@ class PasswordPolicyTestCase(unittest.HomeserverTestCase):
|
||||||
def test_get_policy(self):
|
def test_get_policy(self):
|
||||||
"""Tests if the /password_policy endpoint returns the configured policy."""
|
"""Tests if the /password_policy endpoint returns the configured policy."""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "/_matrix/client/r0/password_policy")
|
||||||
"GET", "/_matrix/client/r0/password_policy"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -89,7 +87,7 @@ class PasswordPolicyTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_password_too_short(self):
|
def test_password_too_short(self):
|
||||||
request_data = json.dumps({"username": "kermit", "password": "shorty"})
|
request_data = json.dumps({"username": "kermit", "password": "shorty"})
|
||||||
request, channel = self.make_request("POST", self.register_url, request_data)
|
channel = self.make_request("POST", self.register_url, request_data)
|
||||||
|
|
||||||
self.assertEqual(channel.code, 400, channel.result)
|
self.assertEqual(channel.code, 400, channel.result)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -98,7 +96,7 @@ class PasswordPolicyTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_password_no_digit(self):
|
def test_password_no_digit(self):
|
||||||
request_data = json.dumps({"username": "kermit", "password": "longerpassword"})
|
request_data = json.dumps({"username": "kermit", "password": "longerpassword"})
|
||||||
request, channel = self.make_request("POST", self.register_url, request_data)
|
channel = self.make_request("POST", self.register_url, request_data)
|
||||||
|
|
||||||
self.assertEqual(channel.code, 400, channel.result)
|
self.assertEqual(channel.code, 400, channel.result)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -107,7 +105,7 @@ class PasswordPolicyTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_password_no_symbol(self):
|
def test_password_no_symbol(self):
|
||||||
request_data = json.dumps({"username": "kermit", "password": "l0ngerpassword"})
|
request_data = json.dumps({"username": "kermit", "password": "l0ngerpassword"})
|
||||||
request, channel = self.make_request("POST", self.register_url, request_data)
|
channel = self.make_request("POST", self.register_url, request_data)
|
||||||
|
|
||||||
self.assertEqual(channel.code, 400, channel.result)
|
self.assertEqual(channel.code, 400, channel.result)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -116,7 +114,7 @@ class PasswordPolicyTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_password_no_uppercase(self):
|
def test_password_no_uppercase(self):
|
||||||
request_data = json.dumps({"username": "kermit", "password": "l0ngerpassword!"})
|
request_data = json.dumps({"username": "kermit", "password": "l0ngerpassword!"})
|
||||||
request, channel = self.make_request("POST", self.register_url, request_data)
|
channel = self.make_request("POST", self.register_url, request_data)
|
||||||
|
|
||||||
self.assertEqual(channel.code, 400, channel.result)
|
self.assertEqual(channel.code, 400, channel.result)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -125,7 +123,7 @@ class PasswordPolicyTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_password_no_lowercase(self):
|
def test_password_no_lowercase(self):
|
||||||
request_data = json.dumps({"username": "kermit", "password": "L0NGERPASSWORD!"})
|
request_data = json.dumps({"username": "kermit", "password": "L0NGERPASSWORD!"})
|
||||||
request, channel = self.make_request("POST", self.register_url, request_data)
|
channel = self.make_request("POST", self.register_url, request_data)
|
||||||
|
|
||||||
self.assertEqual(channel.code, 400, channel.result)
|
self.assertEqual(channel.code, 400, channel.result)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
@ -134,7 +132,7 @@ class PasswordPolicyTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_password_compliant(self):
|
def test_password_compliant(self):
|
||||||
request_data = json.dumps({"username": "kermit", "password": "L0ngerpassword!"})
|
request_data = json.dumps({"username": "kermit", "password": "L0ngerpassword!"})
|
||||||
request, channel = self.make_request("POST", self.register_url, request_data)
|
channel = self.make_request("POST", self.register_url, request_data)
|
||||||
|
|
||||||
# Getting a 401 here means the password has passed validation and the server has
|
# Getting a 401 here means the password has passed validation and the server has
|
||||||
# responded with a list of registration flows.
|
# responded with a list of registration flows.
|
||||||
|
@ -160,7 +158,7 @@ class PasswordPolicyTestCase(unittest.HomeserverTestCase):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/account/password",
|
"/_matrix/client/r0/account/password",
|
||||||
request_data,
|
request_data,
|
||||||
|
|
|
@ -61,7 +61,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
self.hs.get_datastore().services_cache.append(appservice)
|
self.hs.get_datastore().services_cache.append(appservice)
|
||||||
request_data = json.dumps({"username": "as_user_kermit"})
|
request_data = json.dumps({"username": "as_user_kermit"})
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"POST", self.url + b"?access_token=i_am_an_app_service", request_data
|
b"POST", self.url + b"?access_token=i_am_an_app_service", request_data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
def test_POST_appservice_registration_invalid(self):
|
def test_POST_appservice_registration_invalid(self):
|
||||||
self.appservice = None # no application service exists
|
self.appservice = None # no application service exists
|
||||||
request_data = json.dumps({"username": "kermit"})
|
request_data = json.dumps({"username": "kermit"})
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"POST", self.url + b"?access_token=i_am_an_app_service", request_data
|
b"POST", self.url + b"?access_token=i_am_an_app_service", request_data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,14 +80,14 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def test_POST_bad_password(self):
|
def test_POST_bad_password(self):
|
||||||
request_data = json.dumps({"username": "kermit", "password": 666})
|
request_data = json.dumps({"username": "kermit", "password": 666})
|
||||||
request, channel = self.make_request(b"POST", self.url, request_data)
|
channel = self.make_request(b"POST", self.url, request_data)
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"400", channel.result)
|
self.assertEquals(channel.result["code"], b"400", channel.result)
|
||||||
self.assertEquals(channel.json_body["error"], "Invalid password")
|
self.assertEquals(channel.json_body["error"], "Invalid password")
|
||||||
|
|
||||||
def test_POST_bad_username(self):
|
def test_POST_bad_username(self):
|
||||||
request_data = json.dumps({"username": 777, "password": "monkey"})
|
request_data = json.dumps({"username": 777, "password": "monkey"})
|
||||||
request, channel = self.make_request(b"POST", self.url, request_data)
|
channel = self.make_request(b"POST", self.url, request_data)
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"400", channel.result)
|
self.assertEquals(channel.result["code"], b"400", channel.result)
|
||||||
self.assertEquals(channel.json_body["error"], "Invalid username")
|
self.assertEquals(channel.json_body["error"], "Invalid username")
|
||||||
|
@ -102,7 +102,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"auth": {"type": LoginType.DUMMY},
|
"auth": {"type": LoginType.DUMMY},
|
||||||
}
|
}
|
||||||
request_data = json.dumps(params)
|
request_data = json.dumps(params)
|
||||||
request, channel = self.make_request(b"POST", self.url, request_data)
|
channel = self.make_request(b"POST", self.url, request_data)
|
||||||
|
|
||||||
det_data = {
|
det_data = {
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
|
@ -117,7 +117,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
request_data = json.dumps({"username": "kermit", "password": "monkey"})
|
request_data = json.dumps({"username": "kermit", "password": "monkey"})
|
||||||
self.auth_result = (None, {"username": "kermit", "password": "monkey"}, None)
|
self.auth_result = (None, {"username": "kermit", "password": "monkey"}, None)
|
||||||
|
|
||||||
request, channel = self.make_request(b"POST", self.url, request_data)
|
channel = self.make_request(b"POST", self.url, request_data)
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"403", channel.result)
|
self.assertEquals(channel.result["code"], b"403", channel.result)
|
||||||
self.assertEquals(channel.json_body["error"], "Registration has been disabled")
|
self.assertEquals(channel.json_body["error"], "Registration has been disabled")
|
||||||
|
@ -127,7 +127,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
self.hs.config.macaroon_secret_key = "test"
|
self.hs.config.macaroon_secret_key = "test"
|
||||||
self.hs.config.allow_guest_access = True
|
self.hs.config.allow_guest_access = True
|
||||||
|
|
||||||
request, channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
||||||
|
|
||||||
det_data = {"home_server": self.hs.hostname, "device_id": "guest_device"}
|
det_data = {"home_server": self.hs.hostname, "device_id": "guest_device"}
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
@ -136,7 +136,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
def test_POST_disabled_guest_registration(self):
|
def test_POST_disabled_guest_registration(self):
|
||||||
self.hs.config.allow_guest_access = False
|
self.hs.config.allow_guest_access = False
|
||||||
|
|
||||||
request, channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"403", channel.result)
|
self.assertEquals(channel.result["code"], b"403", channel.result)
|
||||||
self.assertEquals(channel.json_body["error"], "Guest access is disabled")
|
self.assertEquals(channel.json_body["error"], "Guest access is disabled")
|
||||||
|
@ -145,7 +145,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
def test_POST_ratelimiting_guest(self):
|
def test_POST_ratelimiting_guest(self):
|
||||||
for i in range(0, 6):
|
for i in range(0, 6):
|
||||||
url = self.url + b"?kind=guest"
|
url = self.url + b"?kind=guest"
|
||||||
request, channel = self.make_request(b"POST", url, b"{}")
|
channel = self.make_request(b"POST", url, b"{}")
|
||||||
|
|
||||||
if i == 5:
|
if i == 5:
|
||||||
self.assertEquals(channel.result["code"], b"429", channel.result)
|
self.assertEquals(channel.result["code"], b"429", channel.result)
|
||||||
|
@ -155,7 +155,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self.reactor.advance(retry_after_ms / 1000.0 + 1.0)
|
self.reactor.advance(retry_after_ms / 1000.0 + 1.0)
|
||||||
|
|
||||||
request, channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
"auth": {"type": LoginType.DUMMY},
|
"auth": {"type": LoginType.DUMMY},
|
||||||
}
|
}
|
||||||
request_data = json.dumps(params)
|
request_data = json.dumps(params)
|
||||||
request, channel = self.make_request(b"POST", self.url, request_data)
|
channel = self.make_request(b"POST", self.url, request_data)
|
||||||
|
|
||||||
if i == 5:
|
if i == 5:
|
||||||
self.assertEquals(channel.result["code"], b"429", channel.result)
|
self.assertEquals(channel.result["code"], b"429", channel.result)
|
||||||
|
@ -179,12 +179,12 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self.reactor.advance(retry_after_ms / 1000.0 + 1.0)
|
self.reactor.advance(retry_after_ms / 1000.0 + 1.0)
|
||||||
|
|
||||||
request, channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
channel = self.make_request(b"POST", self.url + b"?kind=guest", b"{}")
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
def test_advertised_flows(self):
|
def test_advertised_flows(self):
|
||||||
request, channel = self.make_request(b"POST", self.url, b"{}")
|
channel = self.make_request(b"POST", self.url, b"{}")
|
||||||
self.assertEquals(channel.result["code"], b"401", channel.result)
|
self.assertEquals(channel.result["code"], b"401", channel.result)
|
||||||
flows = channel.json_body["flows"]
|
flows = channel.json_body["flows"]
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
def test_advertised_flows_captcha_and_terms_and_3pids(self):
|
def test_advertised_flows_captcha_and_terms_and_3pids(self):
|
||||||
request, channel = self.make_request(b"POST", self.url, b"{}")
|
channel = self.make_request(b"POST", self.url, b"{}")
|
||||||
self.assertEquals(channel.result["code"], b"401", channel.result)
|
self.assertEquals(channel.result["code"], b"401", channel.result)
|
||||||
flows = channel.json_body["flows"]
|
flows = channel.json_body["flows"]
|
||||||
|
|
||||||
|
@ -239,7 +239,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
def test_advertised_flows_no_msisdn_email_required(self):
|
def test_advertised_flows_no_msisdn_email_required(self):
|
||||||
request, channel = self.make_request(b"POST", self.url, b"{}")
|
channel = self.make_request(b"POST", self.url, b"{}")
|
||||||
self.assertEquals(channel.result["code"], b"401", channel.result)
|
self.assertEquals(channel.result["code"], b"401", channel.result)
|
||||||
flows = channel.json_body["flows"]
|
flows = channel.json_body["flows"]
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ class RegisterRestServletTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
b"register/email/requestToken",
|
b"register/email/requestToken",
|
||||||
{"client_secret": "foobar", "email": email, "send_attempt": 1},
|
{"client_secret": "foobar", "email": email, "send_attempt": 1},
|
||||||
|
@ -318,13 +318,13 @@ class AccountValidityTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# The specific endpoint doesn't matter, all we need is an authenticated
|
# The specific endpoint doesn't matter, all we need is an authenticated
|
||||||
# endpoint.
|
# endpoint.
|
||||||
request, channel = self.make_request(b"GET", "/sync", access_token=tok)
|
channel = self.make_request(b"GET", "/sync", access_token=tok)
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
self.reactor.advance(datetime.timedelta(weeks=1).total_seconds())
|
self.reactor.advance(datetime.timedelta(weeks=1).total_seconds())
|
||||||
|
|
||||||
request, channel = self.make_request(b"GET", "/sync", access_token=tok)
|
channel = self.make_request(b"GET", "/sync", access_token=tok)
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"403", channel.result)
|
self.assertEquals(channel.result["code"], b"403", channel.result)
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
|
@ -346,14 +346,12 @@ class AccountValidityTestCase(unittest.HomeserverTestCase):
|
||||||
url = "/_synapse/admin/v1/account_validity/validity"
|
url = "/_synapse/admin/v1/account_validity/validity"
|
||||||
params = {"user_id": user_id}
|
params = {"user_id": user_id}
|
||||||
request_data = json.dumps(params)
|
request_data = json.dumps(params)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
|
||||||
b"POST", url, request_data, access_token=admin_tok
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
# The specific endpoint doesn't matter, all we need is an authenticated
|
# The specific endpoint doesn't matter, all we need is an authenticated
|
||||||
# endpoint.
|
# endpoint.
|
||||||
request, channel = self.make_request(b"GET", "/sync", access_token=tok)
|
channel = self.make_request(b"GET", "/sync", access_token=tok)
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
def test_manual_expire(self):
|
def test_manual_expire(self):
|
||||||
|
@ -370,14 +368,12 @@ class AccountValidityTestCase(unittest.HomeserverTestCase):
|
||||||
"enable_renewal_emails": False,
|
"enable_renewal_emails": False,
|
||||||
}
|
}
|
||||||
request_data = json.dumps(params)
|
request_data = json.dumps(params)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
|
||||||
b"POST", url, request_data, access_token=admin_tok
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
# The specific endpoint doesn't matter, all we need is an authenticated
|
# The specific endpoint doesn't matter, all we need is an authenticated
|
||||||
# endpoint.
|
# endpoint.
|
||||||
request, channel = self.make_request(b"GET", "/sync", access_token=tok)
|
channel = self.make_request(b"GET", "/sync", access_token=tok)
|
||||||
self.assertEquals(channel.result["code"], b"403", channel.result)
|
self.assertEquals(channel.result["code"], b"403", channel.result)
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
channel.json_body["errcode"], Codes.EXPIRED_ACCOUNT, channel.result
|
channel.json_body["errcode"], Codes.EXPIRED_ACCOUNT, channel.result
|
||||||
|
@ -397,20 +393,18 @@ class AccountValidityTestCase(unittest.HomeserverTestCase):
|
||||||
"enable_renewal_emails": False,
|
"enable_renewal_emails": False,
|
||||||
}
|
}
|
||||||
request_data = json.dumps(params)
|
request_data = json.dumps(params)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(b"POST", url, request_data, access_token=admin_tok)
|
||||||
b"POST", url, request_data, access_token=admin_tok
|
|
||||||
)
|
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
# Try to log the user out
|
# Try to log the user out
|
||||||
request, channel = self.make_request(b"POST", "/logout", access_token=tok)
|
channel = self.make_request(b"POST", "/logout", access_token=tok)
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
# Log the user in again (allowed for expired accounts)
|
# Log the user in again (allowed for expired accounts)
|
||||||
tok = self.login("kermit", "monkey")
|
tok = self.login("kermit", "monkey")
|
||||||
|
|
||||||
# Try to log out all of the user's sessions
|
# Try to log out all of the user's sessions
|
||||||
request, channel = self.make_request(b"POST", "/logout/all", access_token=tok)
|
channel = self.make_request(b"POST", "/logout/all", access_token=tok)
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
|
|
||||||
|
@ -484,7 +478,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
||||||
# retrieve the token from the DB.
|
# retrieve the token from the DB.
|
||||||
renewal_token = self.get_success(self.store.get_renewal_token_for_user(user_id))
|
renewal_token = self.get_success(self.store.get_renewal_token_for_user(user_id))
|
||||||
url = "/_matrix/client/unstable/account_validity/renew?token=%s" % renewal_token
|
url = "/_matrix/client/unstable/account_validity/renew?token=%s" % renewal_token
|
||||||
request, channel = self.make_request(b"GET", url)
|
channel = self.make_request(b"GET", url)
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
# Check that we're getting HTML back.
|
# Check that we're getting HTML back.
|
||||||
|
@ -504,14 +498,14 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
||||||
# our access token should be denied from now, otherwise they should
|
# our access token should be denied from now, otherwise they should
|
||||||
# succeed.
|
# succeed.
|
||||||
self.reactor.advance(datetime.timedelta(days=3).total_seconds())
|
self.reactor.advance(datetime.timedelta(days=3).total_seconds())
|
||||||
request, channel = self.make_request(b"GET", "/sync", access_token=tok)
|
channel = self.make_request(b"GET", "/sync", access_token=tok)
|
||||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||||
|
|
||||||
def test_renewal_invalid_token(self):
|
def test_renewal_invalid_token(self):
|
||||||
# Hit the renewal endpoint with an invalid token and check that it behaves as
|
# Hit the renewal endpoint with an invalid token and check that it behaves as
|
||||||
# expected, i.e. that it responds with 404 Not Found and the correct HTML.
|
# expected, i.e. that it responds with 404 Not Found and the correct HTML.
|
||||||
url = "/_matrix/client/unstable/account_validity/renew?token=123"
|
url = "/_matrix/client/unstable/account_validity/renew?token=123"
|
||||||
request, channel = self.make_request(b"GET", url)
|
channel = self.make_request(b"GET", url)
|
||||||
self.assertEquals(channel.result["code"], b"404", channel.result)
|
self.assertEquals(channel.result["code"], b"404", channel.result)
|
||||||
|
|
||||||
# Check that we're getting HTML back.
|
# Check that we're getting HTML back.
|
||||||
|
@ -532,7 +526,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
||||||
self.email_attempts = []
|
self.email_attempts = []
|
||||||
|
|
||||||
(user_id, tok) = self.create_user()
|
(user_id, tok) = self.create_user()
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"POST",
|
b"POST",
|
||||||
"/_matrix/client/unstable/account_validity/send_mail",
|
"/_matrix/client/unstable/account_validity/send_mail",
|
||||||
access_token=tok,
|
access_token=tok,
|
||||||
|
@ -556,10 +550,10 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
||||||
"erase": False,
|
"erase": False,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "account/deactivate", request_data, access_token=tok
|
"POST", "account/deactivate", request_data, access_token=tok
|
||||||
)
|
)
|
||||||
self.assertEqual(request.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
self.reactor.advance(datetime.timedelta(days=8).total_seconds())
|
self.reactor.advance(datetime.timedelta(days=8).total_seconds())
|
||||||
|
|
||||||
|
@ -607,7 +601,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
|
||||||
self.email_attempts = []
|
self.email_attempts = []
|
||||||
|
|
||||||
# Test that we're still able to manually trigger a mail to be sent.
|
# Test that we're still able to manually trigger a mail to be sent.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
b"POST",
|
b"POST",
|
||||||
"/_matrix/client/unstable/account_validity/send_mail",
|
"/_matrix/client/unstable/account_validity/send_mail",
|
||||||
access_token=tok,
|
access_token=tok,
|
||||||
|
|
|
@ -60,7 +60,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
event_id = channel.json_body["event_id"]
|
event_id = channel.json_body["event_id"]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/event/%s" % (self.room, event_id),
|
"/rooms/%s/event/%s" % (self.room, event_id),
|
||||||
access_token=self.user_token,
|
access_token=self.user_token,
|
||||||
|
@ -107,7 +107,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
annotation_id = channel.json_body["event_id"]
|
annotation_id = channel.json_body["event_id"]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s/relations/%s?limit=1"
|
"/_matrix/client/unstable/rooms/%s/relations/%s?limit=1"
|
||||||
% (self.room, self.parent_id),
|
% (self.room, self.parent_id),
|
||||||
|
@ -152,7 +152,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
if prev_token:
|
if prev_token:
|
||||||
from_token = "&from=" + prev_token
|
from_token = "&from=" + prev_token
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s/relations/%s?limit=1%s"
|
"/_matrix/client/unstable/rooms/%s/relations/%s?limit=1%s"
|
||||||
% (self.room, self.parent_id, from_token),
|
% (self.room, self.parent_id, from_token),
|
||||||
|
@ -210,7 +210,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
if prev_token:
|
if prev_token:
|
||||||
from_token = "&from=" + prev_token
|
from_token = "&from=" + prev_token
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s/aggregations/%s?limit=1%s"
|
"/_matrix/client/unstable/rooms/%s/aggregations/%s?limit=1%s"
|
||||||
% (self.room, self.parent_id, from_token),
|
% (self.room, self.parent_id, from_token),
|
||||||
|
@ -279,7 +279,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
if prev_token:
|
if prev_token:
|
||||||
from_token = "&from=" + prev_token
|
from_token = "&from=" + prev_token
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s"
|
"/_matrix/client/unstable/rooms/%s"
|
||||||
"/aggregations/%s/%s/m.reaction/%s?limit=1%s"
|
"/aggregations/%s/%s/m.reaction/%s?limit=1%s"
|
||||||
|
@ -325,7 +325,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "b")
|
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "b")
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s/aggregations/%s"
|
"/_matrix/client/unstable/rooms/%s/aggregations/%s"
|
||||||
% (self.room, self.parent_id),
|
% (self.room, self.parent_id),
|
||||||
|
@ -357,7 +357,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
|
||||||
# Now lets redact one of the 'a' reactions
|
# Now lets redact one of the 'a' reactions
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/rooms/%s/redact/%s" % (self.room, to_redact_event_id),
|
"/_matrix/client/r0/rooms/%s/redact/%s" % (self.room, to_redact_event_id),
|
||||||
access_token=self.user_token,
|
access_token=self.user_token,
|
||||||
|
@ -365,7 +365,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s/aggregations/%s"
|
"/_matrix/client/unstable/rooms/%s/aggregations/%s"
|
||||||
% (self.room, self.parent_id),
|
% (self.room, self.parent_id),
|
||||||
|
@ -382,7 +382,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
"""Test that aggregations must be annotations.
|
"""Test that aggregations must be annotations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s/aggregations/%s/%s?limit=1"
|
"/_matrix/client/unstable/rooms/%s/aggregations/%s/%s?limit=1"
|
||||||
% (self.room, self.parent_id, RelationTypes.REPLACE),
|
% (self.room, self.parent_id, RelationTypes.REPLACE),
|
||||||
|
@ -414,7 +414,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
reply_2 = channel.json_body["event_id"]
|
reply_2 = channel.json_body["event_id"]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/event/%s" % (self.room, self.parent_id),
|
"/rooms/%s/event/%s" % (self.room, self.parent_id),
|
||||||
access_token=self.user_token,
|
access_token=self.user_token,
|
||||||
|
@ -450,7 +450,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
edit_event_id = channel.json_body["event_id"]
|
edit_event_id = channel.json_body["event_id"]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/event/%s" % (self.room, self.parent_id),
|
"/rooms/%s/event/%s" % (self.room, self.parent_id),
|
||||||
access_token=self.user_token,
|
access_token=self.user_token,
|
||||||
|
@ -507,7 +507,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/rooms/%s/event/%s" % (self.room, self.parent_id),
|
"/rooms/%s/event/%s" % (self.room, self.parent_id),
|
||||||
access_token=self.user_token,
|
access_token=self.user_token,
|
||||||
|
@ -549,7 +549,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
|
||||||
# Check the relation is returned
|
# Check the relation is returned
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s/relations/%s/m.replace/m.room.message"
|
"/_matrix/client/unstable/rooms/%s/relations/%s/m.replace/m.room.message"
|
||||||
% (self.room, original_event_id),
|
% (self.room, original_event_id),
|
||||||
|
@ -561,7 +561,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(len(channel.json_body["chunk"]), 1)
|
self.assertEquals(len(channel.json_body["chunk"]), 1)
|
||||||
|
|
||||||
# Redact the original event
|
# Redact the original event
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/redact/%s/%s"
|
"/rooms/%s/redact/%s/%s"
|
||||||
% (self.room, original_event_id, "test_relations_redaction_redacts_edits"),
|
% (self.room, original_event_id, "test_relations_redaction_redacts_edits"),
|
||||||
|
@ -571,7 +571,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
|
||||||
# Try to check for remaining m.replace relations
|
# Try to check for remaining m.replace relations
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s/relations/%s/m.replace/m.room.message"
|
"/_matrix/client/unstable/rooms/%s/relations/%s/m.replace/m.room.message"
|
||||||
% (self.room, original_event_id),
|
% (self.room, original_event_id),
|
||||||
|
@ -598,7 +598,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
|
||||||
# Redact the original
|
# Redact the original
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
"/rooms/%s/redact/%s/%s"
|
"/rooms/%s/redact/%s/%s"
|
||||||
% (
|
% (
|
||||||
|
@ -612,7 +612,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(200, channel.code, channel.json_body)
|
self.assertEquals(200, channel.code, channel.json_body)
|
||||||
|
|
||||||
# Check that aggregations returns zero
|
# Check that aggregations returns zero
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/rooms/%s/aggregations/%s/m.annotation/m.reaction"
|
"/_matrix/client/unstable/rooms/%s/aggregations/%s/m.annotation/m.reaction"
|
||||||
% (self.room, original_event_id),
|
% (self.room, original_event_id),
|
||||||
|
@ -656,7 +656,7 @@ class RelationsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
original_id = parent_id if parent_id else self.parent_id
|
original_id = parent_id if parent_id else self.parent_id
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/unstable/rooms/%s/send_relation/%s/%s/%s%s"
|
"/_matrix/client/unstable/rooms/%s/send_relation/%s/%s/%s%s"
|
||||||
% (self.room, original_id, relation_type, event_type, query),
|
% (self.room, original_id, relation_type, event_type, query),
|
||||||
|
|
|
@ -17,6 +17,7 @@ from synapse.rest.client.v1 import login, room
|
||||||
from synapse.rest.client.v2_alpha import shared_rooms
|
from synapse.rest.client.v2_alpha import shared_rooms
|
||||||
|
|
||||||
from tests import unittest
|
from tests import unittest
|
||||||
|
from tests.server import FakeChannel
|
||||||
|
|
||||||
|
|
||||||
class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
|
@ -40,14 +41,13 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
self.store = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
self.handler = hs.get_user_directory_handler()
|
self.handler = hs.get_user_directory_handler()
|
||||||
|
|
||||||
def _get_shared_rooms(self, token, other_user):
|
def _get_shared_rooms(self, token, other_user) -> FakeChannel:
|
||||||
request, channel = self.make_request(
|
return self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_matrix/client/unstable/uk.half-shot.msc2666/user/shared_rooms/%s"
|
"/_matrix/client/unstable/uk.half-shot.msc2666/user/shared_rooms/%s"
|
||||||
% other_user,
|
% other_user,
|
||||||
access_token=token,
|
access_token=token,
|
||||||
)
|
)
|
||||||
return request, channel
|
|
||||||
|
|
||||||
def test_shared_room_list_public(self):
|
def test_shared_room_list_public(self):
|
||||||
"""
|
"""
|
||||||
|
@ -63,7 +63,7 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
self.helper.invite(room, src=u1, targ=u2, tok=u1_token)
|
self.helper.invite(room, src=u1, targ=u2, tok=u1_token)
|
||||||
self.helper.join(room, user=u2, tok=u2_token)
|
self.helper.join(room, user=u2, tok=u2_token)
|
||||||
|
|
||||||
request, channel = self._get_shared_rooms(u1_token, u2)
|
channel = self._get_shared_rooms(u1_token, u2)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
self.assertEquals(len(channel.json_body["joined"]), 1)
|
self.assertEquals(len(channel.json_body["joined"]), 1)
|
||||||
self.assertEquals(channel.json_body["joined"][0], room)
|
self.assertEquals(channel.json_body["joined"][0], room)
|
||||||
|
@ -82,7 +82,7 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
self.helper.invite(room, src=u1, targ=u2, tok=u1_token)
|
self.helper.invite(room, src=u1, targ=u2, tok=u1_token)
|
||||||
self.helper.join(room, user=u2, tok=u2_token)
|
self.helper.join(room, user=u2, tok=u2_token)
|
||||||
|
|
||||||
request, channel = self._get_shared_rooms(u1_token, u2)
|
channel = self._get_shared_rooms(u1_token, u2)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
self.assertEquals(len(channel.json_body["joined"]), 1)
|
self.assertEquals(len(channel.json_body["joined"]), 1)
|
||||||
self.assertEquals(channel.json_body["joined"][0], room)
|
self.assertEquals(channel.json_body["joined"][0], room)
|
||||||
|
@ -104,7 +104,7 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
self.helper.join(room_public, user=u2, tok=u2_token)
|
self.helper.join(room_public, user=u2, tok=u2_token)
|
||||||
self.helper.join(room_private, user=u1, tok=u1_token)
|
self.helper.join(room_private, user=u1, tok=u1_token)
|
||||||
|
|
||||||
request, channel = self._get_shared_rooms(u1_token, u2)
|
channel = self._get_shared_rooms(u1_token, u2)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
self.assertEquals(len(channel.json_body["joined"]), 2)
|
self.assertEquals(len(channel.json_body["joined"]), 2)
|
||||||
self.assertTrue(room_public in channel.json_body["joined"])
|
self.assertTrue(room_public in channel.json_body["joined"])
|
||||||
|
@ -125,13 +125,13 @@ class UserSharedRoomsTest(unittest.HomeserverTestCase):
|
||||||
self.helper.join(room, user=u2, tok=u2_token)
|
self.helper.join(room, user=u2, tok=u2_token)
|
||||||
|
|
||||||
# Assert user directory is not empty
|
# Assert user directory is not empty
|
||||||
request, channel = self._get_shared_rooms(u1_token, u2)
|
channel = self._get_shared_rooms(u1_token, u2)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
self.assertEquals(len(channel.json_body["joined"]), 1)
|
self.assertEquals(len(channel.json_body["joined"]), 1)
|
||||||
self.assertEquals(channel.json_body["joined"][0], room)
|
self.assertEquals(channel.json_body["joined"][0], room)
|
||||||
|
|
||||||
self.helper.leave(room, user=u1, tok=u1_token)
|
self.helper.leave(room, user=u1, tok=u1_token)
|
||||||
|
|
||||||
request, channel = self._get_shared_rooms(u2_token, u1)
|
channel = self._get_shared_rooms(u2_token, u1)
|
||||||
self.assertEquals(200, channel.code, channel.result)
|
self.assertEquals(200, channel.code, channel.result)
|
||||||
self.assertEquals(len(channel.json_body["joined"]), 0)
|
self.assertEquals(len(channel.json_body["joined"]), 0)
|
||||||
|
|
|
@ -35,7 +35,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
||||||
]
|
]
|
||||||
|
|
||||||
def test_sync_argless(self):
|
def test_sync_argless(self):
|
||||||
request, channel = self.make_request("GET", "/sync")
|
channel = self.make_request("GET", "/sync")
|
||||||
|
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
|
@ -55,7 +55,7 @@ class FilterTestCase(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
self.hs.config.use_presence = False
|
self.hs.config.use_presence = False
|
||||||
|
|
||||||
request, channel = self.make_request("GET", "/sync")
|
channel = self.make_request("GET", "/sync")
|
||||||
|
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
|
@ -194,7 +194,7 @@ class SyncFilterTestCase(unittest.HomeserverTestCase):
|
||||||
tok=tok,
|
tok=tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/sync?filter=%s" % sync_filter, access_token=tok
|
"GET", "/sync?filter=%s" % sync_filter, access_token=tok
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
|
@ -245,21 +245,19 @@ class SyncTypingTests(unittest.HomeserverTestCase):
|
||||||
self.helper.send(room, body="There!", tok=other_access_token)
|
self.helper.send(room, body="There!", tok=other_access_token)
|
||||||
|
|
||||||
# Start typing.
|
# Start typing.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
typing_url % (room, other_user_id, other_access_token),
|
typing_url % (room, other_user_id, other_access_token),
|
||||||
b'{"typing": true, "timeout": 30000}',
|
b'{"typing": true, "timeout": 30000}',
|
||||||
)
|
)
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "/sync?access_token=%s" % (access_token,))
|
||||||
"GET", "/sync?access_token=%s" % (access_token,)
|
|
||||||
)
|
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
next_batch = channel.json_body["next_batch"]
|
next_batch = channel.json_body["next_batch"]
|
||||||
|
|
||||||
# Stop typing.
|
# Stop typing.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
typing_url % (room, other_user_id, other_access_token),
|
typing_url % (room, other_user_id, other_access_token),
|
||||||
b'{"typing": false}',
|
b'{"typing": false}',
|
||||||
|
@ -267,7 +265,7 @@ class SyncTypingTests(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
|
||||||
# Start typing.
|
# Start typing.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"PUT",
|
"PUT",
|
||||||
typing_url % (room, other_user_id, other_access_token),
|
typing_url % (room, other_user_id, other_access_token),
|
||||||
b'{"typing": true, "timeout": 30000}',
|
b'{"typing": true, "timeout": 30000}',
|
||||||
|
@ -275,9 +273,7 @@ class SyncTypingTests(unittest.HomeserverTestCase):
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
|
|
||||||
# Should return immediately
|
# Should return immediately
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", sync_url % (access_token, next_batch))
|
||||||
"GET", sync_url % (access_token, next_batch)
|
|
||||||
)
|
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
next_batch = channel.json_body["next_batch"]
|
next_batch = channel.json_body["next_batch"]
|
||||||
|
|
||||||
|
@ -289,9 +285,7 @@ class SyncTypingTests(unittest.HomeserverTestCase):
|
||||||
# invalidate the stream token.
|
# invalidate the stream token.
|
||||||
self.helper.send(room, body="There!", tok=other_access_token)
|
self.helper.send(room, body="There!", tok=other_access_token)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", sync_url % (access_token, next_batch))
|
||||||
"GET", sync_url % (access_token, next_batch)
|
|
||||||
)
|
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
next_batch = channel.json_body["next_batch"]
|
next_batch = channel.json_body["next_batch"]
|
||||||
|
|
||||||
|
@ -299,9 +293,7 @@ class SyncTypingTests(unittest.HomeserverTestCase):
|
||||||
# ahead, and therefore it's saying the typing (that we've actually
|
# ahead, and therefore it's saying the typing (that we've actually
|
||||||
# already seen) is new, since it's got a token above our new, now-reset
|
# already seen) is new, since it's got a token above our new, now-reset
|
||||||
# stream token.
|
# stream token.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", sync_url % (access_token, next_batch))
|
||||||
"GET", sync_url % (access_token, next_batch)
|
|
||||||
)
|
|
||||||
self.assertEquals(200, channel.code)
|
self.assertEquals(200, channel.code)
|
||||||
next_batch = channel.json_body["next_batch"]
|
next_batch = channel.json_body["next_batch"]
|
||||||
|
|
||||||
|
@ -383,7 +375,7 @@ class UnreadMessagesTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Send a read receipt to tell the server we've read the latest event.
|
# Send a read receipt to tell the server we've read the latest event.
|
||||||
body = json.dumps({"m.read": res["event_id"]}).encode("utf8")
|
body = json.dumps({"m.read": res["event_id"]}).encode("utf8")
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/rooms/%s/read_markers" % self.room_id,
|
"/rooms/%s/read_markers" % self.room_id,
|
||||||
body,
|
body,
|
||||||
|
@ -450,7 +442,7 @@ class UnreadMessagesTestCase(unittest.HomeserverTestCase):
|
||||||
def _check_unread_count(self, expected_count: True):
|
def _check_unread_count(self, expected_count: True):
|
||||||
"""Syncs and compares the unread count with the expected value."""
|
"""Syncs and compares the unread count with the expected value."""
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", self.url % self.next_batch, access_token=self.tok,
|
"GET", self.url % self.next_batch, access_token=self.tok,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -228,7 +228,7 @@ class MediaRepoTests(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def _req(self, content_disposition):
|
def _req(self, content_disposition):
|
||||||
|
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(self.download_resource),
|
FakeSite(self.download_resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
@ -324,7 +324,7 @@ class MediaRepoTests(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
def _test_thumbnail(self, method, expected_body, expected_found):
|
def _test_thumbnail(self, method, expected_body, expected_found):
|
||||||
params = "?width=32&height=32&method=" + method
|
params = "?width=32&height=32&method=" + method
|
||||||
request, channel = make_request(
|
channel = make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
FakeSite(self.thumbnail_resource),
|
FakeSite(self.thumbnail_resource),
|
||||||
"GET",
|
"GET",
|
||||||
|
|
|
@ -113,7 +113,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
def test_cache_returns_correct_type(self):
|
def test_cache_returns_correct_type(self):
|
||||||
self.lookups["matrix.org"] = [(IPv4Address, "10.1.2.3")]
|
self.lookups["matrix.org"] = [(IPv4Address, "10.1.2.3")]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"preview_url?url=http://matrix.org",
|
"preview_url?url=http://matrix.org",
|
||||||
shorthand=False,
|
shorthand=False,
|
||||||
|
@ -138,7 +138,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check the cache returns the correct response
|
# Check the cache returns the correct response
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "preview_url?url=http://matrix.org", shorthand=False
|
"GET", "preview_url?url=http://matrix.org", shorthand=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -154,7 +154,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
self.assertNotIn("http://matrix.org", self.preview_url._cache)
|
self.assertNotIn("http://matrix.org", self.preview_url._cache)
|
||||||
|
|
||||||
# Check the database cache returns the correct response
|
# Check the database cache returns the correct response
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "preview_url?url=http://matrix.org", shorthand=False
|
"GET", "preview_url?url=http://matrix.org", shorthand=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
b"</head></html>"
|
b"</head></html>"
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"preview_url?url=http://matrix.org",
|
"preview_url?url=http://matrix.org",
|
||||||
shorthand=False,
|
shorthand=False,
|
||||||
|
@ -210,7 +210,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
b"</head></html>"
|
b"</head></html>"
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"preview_url?url=http://matrix.org",
|
"preview_url?url=http://matrix.org",
|
||||||
shorthand=False,
|
shorthand=False,
|
||||||
|
@ -245,7 +245,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
b"</head></html>"
|
b"</head></html>"
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"preview_url?url=http://matrix.org",
|
"preview_url?url=http://matrix.org",
|
||||||
shorthand=False,
|
shorthand=False,
|
||||||
|
@ -278,7 +278,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
self.lookups["example.com"] = [(IPv4Address, "10.1.2.3")]
|
self.lookups["example.com"] = [(IPv4Address, "10.1.2.3")]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"preview_url?url=http://example.com",
|
"preview_url?url=http://example.com",
|
||||||
shorthand=False,
|
shorthand=False,
|
||||||
|
@ -308,7 +308,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
self.lookups["example.com"] = [(IPv4Address, "192.168.1.1")]
|
self.lookups["example.com"] = [(IPv4Address, "192.168.1.1")]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "preview_url?url=http://example.com", shorthand=False
|
"GET", "preview_url?url=http://example.com", shorthand=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
self.lookups["example.com"] = [(IPv4Address, "1.1.1.2")]
|
self.lookups["example.com"] = [(IPv4Address, "1.1.1.2")]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "preview_url?url=http://example.com", shorthand=False
|
"GET", "preview_url?url=http://example.com", shorthand=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Blacklisted IP addresses, accessed directly, are not spidered.
|
Blacklisted IP addresses, accessed directly, are not spidered.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "preview_url?url=http://192.168.1.1", shorthand=False
|
"GET", "preview_url?url=http://192.168.1.1", shorthand=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
Blacklisted IP ranges, accessed directly, are not spidered.
|
Blacklisted IP ranges, accessed directly, are not spidered.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "preview_url?url=http://1.1.1.2", shorthand=False
|
"GET", "preview_url?url=http://1.1.1.2", shorthand=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
self.lookups["example.com"] = [(IPv4Address, "1.1.1.1")]
|
self.lookups["example.com"] = [(IPv4Address, "1.1.1.1")]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"preview_url?url=http://example.com",
|
"preview_url?url=http://example.com",
|
||||||
shorthand=False,
|
shorthand=False,
|
||||||
|
@ -422,7 +422,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
(IPv4Address, "10.1.2.3"),
|
(IPv4Address, "10.1.2.3"),
|
||||||
]
|
]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "preview_url?url=http://example.com", shorthand=False
|
"GET", "preview_url?url=http://example.com", shorthand=False
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 502)
|
self.assertEqual(channel.code, 502)
|
||||||
|
@ -442,7 +442,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
(IPv6Address, "3fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
|
(IPv6Address, "3fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")
|
||||||
]
|
]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "preview_url?url=http://example.com", shorthand=False
|
"GET", "preview_url?url=http://example.com", shorthand=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -463,7 +463,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
self.lookups["example.com"] = [(IPv6Address, "2001:800::1")]
|
self.lookups["example.com"] = [(IPv6Address, "2001:800::1")]
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "preview_url?url=http://example.com", shorthand=False
|
"GET", "preview_url?url=http://example.com", shorthand=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
"""
|
"""
|
||||||
OPTIONS returns the OPTIONS.
|
OPTIONS returns the OPTIONS.
|
||||||
"""
|
"""
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"OPTIONS", "preview_url?url=http://example.com", shorthand=False
|
"OPTIONS", "preview_url?url=http://example.com", shorthand=False
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -493,7 +493,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
self.lookups["example.com"] = [(IPv4Address, "10.1.2.3")]
|
self.lookups["example.com"] = [(IPv4Address, "10.1.2.3")]
|
||||||
|
|
||||||
# Build and make a request to the server
|
# Build and make a request to the server
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"preview_url?url=http://example.com",
|
"preview_url?url=http://example.com",
|
||||||
shorthand=False,
|
shorthand=False,
|
||||||
|
@ -567,7 +567,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
b"</head></html>"
|
b"</head></html>"
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"preview_url?url=http://twitter.com/matrixdotorg/status/12345",
|
"preview_url?url=http://twitter.com/matrixdotorg/status/12345",
|
||||||
shorthand=False,
|
shorthand=False,
|
||||||
|
@ -632,7 +632,7 @@ class URLPreviewTests(unittest.HomeserverTestCase):
|
||||||
}
|
}
|
||||||
end_content = json.dumps(result).encode("utf-8")
|
end_content = json.dumps(result).encode("utf-8")
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"preview_url?url=http://twitter.com/matrixdotorg/status/12345",
|
"preview_url?url=http://twitter.com/matrixdotorg/status/12345",
|
||||||
shorthand=False,
|
shorthand=False,
|
||||||
|
|
|
@ -25,7 +25,7 @@ class HealthCheckTests(unittest.HomeserverTestCase):
|
||||||
return HealthResource()
|
return HealthResource()
|
||||||
|
|
||||||
def test_health(self):
|
def test_health(self):
|
||||||
request, channel = self.make_request("GET", "/health", shorthand=False)
|
channel = self.make_request("GET", "/health", shorthand=False)
|
||||||
|
|
||||||
self.assertEqual(request.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
self.assertEqual(channel.result["body"], b"OK")
|
self.assertEqual(channel.result["body"], b"OK")
|
||||||
|
|
|
@ -28,11 +28,11 @@ class WellKnownTests(unittest.HomeserverTestCase):
|
||||||
self.hs.config.public_baseurl = "https://tesths"
|
self.hs.config.public_baseurl = "https://tesths"
|
||||||
self.hs.config.default_identity_server = "https://testis"
|
self.hs.config.default_identity_server = "https://testis"
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/.well-known/matrix/client", shorthand=False
|
"GET", "/.well-known/matrix/client", shorthand=False
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(request.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
channel.json_body,
|
channel.json_body,
|
||||||
{
|
{
|
||||||
|
@ -44,8 +44,8 @@ class WellKnownTests(unittest.HomeserverTestCase):
|
||||||
def test_well_known_no_public_baseurl(self):
|
def test_well_known_no_public_baseurl(self):
|
||||||
self.hs.config.public_baseurl = None
|
self.hs.config.public_baseurl = None
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/.well-known/matrix/client", shorthand=False
|
"GET", "/.well-known/matrix/client", shorthand=False
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(request.code, 404)
|
self.assertEqual(channel.code, 404)
|
||||||
|
|
|
@ -174,11 +174,11 @@ def make_request(
|
||||||
custom_headers: Optional[
|
custom_headers: Optional[
|
||||||
Iterable[Tuple[Union[bytes, str], Union[bytes, str]]]
|
Iterable[Tuple[Union[bytes, str], Union[bytes, str]]]
|
||||||
] = None,
|
] = None,
|
||||||
):
|
) -> FakeChannel:
|
||||||
"""
|
"""
|
||||||
Make a web request using the given method, path and content, and render it
|
Make a web request using the given method, path and content, and render it
|
||||||
|
|
||||||
Returns the Request and the Channel underneath.
|
Returns the fake Channel object which records the response to the request.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
site: The twisted Site to use to render the request
|
site: The twisted Site to use to render the request
|
||||||
|
@ -202,7 +202,7 @@ def make_request(
|
||||||
is finished.
|
is finished.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple[synapse.http.site.SynapseRequest, channel]
|
channel
|
||||||
"""
|
"""
|
||||||
if not isinstance(method, bytes):
|
if not isinstance(method, bytes):
|
||||||
method = method.encode("ascii")
|
method = method.encode("ascii")
|
||||||
|
@ -265,7 +265,7 @@ def make_request(
|
||||||
if await_result:
|
if await_result:
|
||||||
channel.await_result()
|
channel.await_result()
|
||||||
|
|
||||||
return req, channel
|
return channel
|
||||||
|
|
||||||
|
|
||||||
@implementer(IReactorPluggableNameResolver)
|
@implementer(IReactorPluggableNameResolver)
|
||||||
|
|
|
@ -70,7 +70,7 @@ class ConsentNoticesTests(unittest.HomeserverTestCase):
|
||||||
the notice URL + an authentication code.
|
the notice URL + an authentication code.
|
||||||
"""
|
"""
|
||||||
# Initial sync, to get the user consent room invite
|
# Initial sync, to get the user consent room invite
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/client/r0/sync", access_token=self.access_token
|
"GET", "/_matrix/client/r0/sync", access_token=self.access_token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
@ -79,7 +79,7 @@ class ConsentNoticesTests(unittest.HomeserverTestCase):
|
||||||
room_id = list(channel.json_body["rooms"]["invite"].keys())[0]
|
room_id = list(channel.json_body["rooms"]["invite"].keys())[0]
|
||||||
|
|
||||||
# Join the room
|
# Join the room
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST",
|
"POST",
|
||||||
"/_matrix/client/r0/rooms/" + room_id + "/join",
|
"/_matrix/client/r0/rooms/" + room_id + "/join",
|
||||||
access_token=self.access_token,
|
access_token=self.access_token,
|
||||||
|
@ -87,7 +87,7 @@ class ConsentNoticesTests(unittest.HomeserverTestCase):
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
||||||
# Sync again, to get the message in the room
|
# Sync again, to get the message in the room
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"GET", "/_matrix/client/r0/sync", access_token=self.access_token
|
"GET", "/_matrix/client/r0/sync", access_token=self.access_token
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200)
|
self.assertEqual(channel.code, 200)
|
||||||
|
|
|
@ -305,7 +305,7 @@ class TestResourceLimitsServerNoticesWithRealRooms(unittest.HomeserverTestCase):
|
||||||
self.register_user("user", "password")
|
self.register_user("user", "password")
|
||||||
tok = self.login("user", "password")
|
tok = self.login("user", "password")
|
||||||
|
|
||||||
request, channel = self.make_request("GET", "/sync?timeout=0", access_token=tok)
|
channel = self.make_request("GET", "/sync?timeout=0", access_token=tok)
|
||||||
|
|
||||||
invites = channel.json_body["rooms"]["invite"]
|
invites = channel.json_body["rooms"]["invite"]
|
||||||
self.assertEqual(len(invites), 0, invites)
|
self.assertEqual(len(invites), 0, invites)
|
||||||
|
@ -318,7 +318,7 @@ class TestResourceLimitsServerNoticesWithRealRooms(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
# Sync again to retrieve the events in the room, so we can check whether this
|
# Sync again to retrieve the events in the room, so we can check whether this
|
||||||
# room has a notice in it.
|
# room has a notice in it.
|
||||||
request, channel = self.make_request("GET", "/sync?timeout=0", access_token=tok)
|
channel = self.make_request("GET", "/sync?timeout=0", access_token=tok)
|
||||||
|
|
||||||
# Scan the events in the room to search for a message from the server notices
|
# Scan the events in the room to search for a message from the server notices
|
||||||
# user.
|
# user.
|
||||||
|
@ -353,9 +353,7 @@ class TestResourceLimitsServerNoticesWithRealRooms(unittest.HomeserverTestCase):
|
||||||
tok = self.login(localpart, "password")
|
tok = self.login(localpart, "password")
|
||||||
|
|
||||||
# Sync with the user's token to mark the user as active.
|
# Sync with the user's token to mark the user as active.
|
||||||
request, channel = self.make_request(
|
channel = self.make_request("GET", "/sync?timeout=0", access_token=tok,)
|
||||||
"GET", "/sync?timeout=0", access_token=tok,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Also retrieves the list of invites for this user. We don't care about that
|
# Also retrieves the list of invites for this user. We don't care about that
|
||||||
# one except if we're processing the last user, which should have received an
|
# one except if we're processing the last user, which should have received an
|
||||||
|
|
|
@ -201,7 +201,7 @@ class TestMauLimit(unittest.HomeserverTestCase):
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = self.make_request("POST", "/register", request_data)
|
channel = self.make_request("POST", "/register", request_data)
|
||||||
|
|
||||||
if channel.code != 200:
|
if channel.code != 200:
|
||||||
raise HttpResponseException(
|
raise HttpResponseException(
|
||||||
|
@ -213,7 +213,7 @@ class TestMauLimit(unittest.HomeserverTestCase):
|
||||||
return access_token
|
return access_token
|
||||||
|
|
||||||
def do_sync_for_user(self, token):
|
def do_sync_for_user(self, token):
|
||||||
request, channel = self.make_request("GET", "/sync", access_token=token)
|
channel = self.make_request("GET", "/sync", access_token=token)
|
||||||
|
|
||||||
if channel.code != 200:
|
if channel.code != 200:
|
||||||
raise HttpResponseException(
|
raise HttpResponseException(
|
||||||
|
|
|
@ -64,11 +64,10 @@ class JsonResourceTests(unittest.TestCase):
|
||||||
"test_servlet",
|
"test_servlet",
|
||||||
)
|
)
|
||||||
|
|
||||||
request, channel = make_request(
|
make_request(
|
||||||
self.reactor, FakeSite(res), b"GET", b"/_matrix/foo/%E2%98%83?a=%E2%98%83"
|
self.reactor, FakeSite(res), b"GET", b"/_matrix/foo/%E2%98%83?a=%E2%98%83"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(request.args, {b"a": ["\N{SNOWMAN}".encode("utf8")]})
|
|
||||||
self.assertEqual(got_kwargs, {"room_id": "\N{SNOWMAN}"})
|
self.assertEqual(got_kwargs, {"room_id": "\N{SNOWMAN}"})
|
||||||
|
|
||||||
def test_callback_direct_exception(self):
|
def test_callback_direct_exception(self):
|
||||||
|
@ -85,7 +84,7 @@ class JsonResourceTests(unittest.TestCase):
|
||||||
"GET", [re.compile("^/_matrix/foo$")], _callback, "test_servlet"
|
"GET", [re.compile("^/_matrix/foo$")], _callback, "test_servlet"
|
||||||
)
|
)
|
||||||
|
|
||||||
_, channel = make_request(self.reactor, FakeSite(res), b"GET", b"/_matrix/foo")
|
channel = make_request(self.reactor, FakeSite(res), b"GET", b"/_matrix/foo")
|
||||||
|
|
||||||
self.assertEqual(channel.result["code"], b"500")
|
self.assertEqual(channel.result["code"], b"500")
|
||||||
|
|
||||||
|
@ -109,7 +108,7 @@ class JsonResourceTests(unittest.TestCase):
|
||||||
"GET", [re.compile("^/_matrix/foo$")], _callback, "test_servlet"
|
"GET", [re.compile("^/_matrix/foo$")], _callback, "test_servlet"
|
||||||
)
|
)
|
||||||
|
|
||||||
_, channel = make_request(self.reactor, FakeSite(res), b"GET", b"/_matrix/foo")
|
channel = make_request(self.reactor, FakeSite(res), b"GET", b"/_matrix/foo")
|
||||||
|
|
||||||
self.assertEqual(channel.result["code"], b"500")
|
self.assertEqual(channel.result["code"], b"500")
|
||||||
|
|
||||||
|
@ -127,7 +126,7 @@ class JsonResourceTests(unittest.TestCase):
|
||||||
"GET", [re.compile("^/_matrix/foo$")], _callback, "test_servlet"
|
"GET", [re.compile("^/_matrix/foo$")], _callback, "test_servlet"
|
||||||
)
|
)
|
||||||
|
|
||||||
_, channel = make_request(self.reactor, FakeSite(res), b"GET", b"/_matrix/foo")
|
channel = make_request(self.reactor, FakeSite(res), b"GET", b"/_matrix/foo")
|
||||||
|
|
||||||
self.assertEqual(channel.result["code"], b"403")
|
self.assertEqual(channel.result["code"], b"403")
|
||||||
self.assertEqual(channel.json_body["error"], "Forbidden!!one!")
|
self.assertEqual(channel.json_body["error"], "Forbidden!!one!")
|
||||||
|
@ -149,9 +148,7 @@ class JsonResourceTests(unittest.TestCase):
|
||||||
"GET", [re.compile("^/_matrix/foo$")], _callback, "test_servlet"
|
"GET", [re.compile("^/_matrix/foo$")], _callback, "test_servlet"
|
||||||
)
|
)
|
||||||
|
|
||||||
_, channel = make_request(
|
channel = make_request(self.reactor, FakeSite(res), b"GET", b"/_matrix/foobar")
|
||||||
self.reactor, FakeSite(res), b"GET", b"/_matrix/foobar"
|
|
||||||
)
|
|
||||||
|
|
||||||
self.assertEqual(channel.result["code"], b"400")
|
self.assertEqual(channel.result["code"], b"400")
|
||||||
self.assertEqual(channel.json_body["error"], "Unrecognized request")
|
self.assertEqual(channel.json_body["error"], "Unrecognized request")
|
||||||
|
@ -173,7 +170,7 @@ class JsonResourceTests(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# The path was registered as GET, but this is a HEAD request.
|
# The path was registered as GET, but this is a HEAD request.
|
||||||
_, channel = make_request(self.reactor, FakeSite(res), b"HEAD", b"/_matrix/foo")
|
channel = make_request(self.reactor, FakeSite(res), b"HEAD", b"/_matrix/foo")
|
||||||
|
|
||||||
self.assertEqual(channel.result["code"], b"200")
|
self.assertEqual(channel.result["code"], b"200")
|
||||||
self.assertNotIn("body", channel.result)
|
self.assertNotIn("body", channel.result)
|
||||||
|
@ -205,7 +202,7 @@ class OptionsResourceTests(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
# render the request and return the channel
|
# render the request and return the channel
|
||||||
_, channel = make_request(self.reactor, site, method, path, shorthand=False)
|
channel = make_request(self.reactor, site, method, path, shorthand=False)
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
def test_unknown_options_request(self):
|
def test_unknown_options_request(self):
|
||||||
|
@ -278,7 +275,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
|
||||||
res = WrapHtmlRequestHandlerTests.TestResource()
|
res = WrapHtmlRequestHandlerTests.TestResource()
|
||||||
res.callback = callback
|
res.callback = callback
|
||||||
|
|
||||||
_, channel = make_request(self.reactor, FakeSite(res), b"GET", b"/path")
|
channel = make_request(self.reactor, FakeSite(res), b"GET", b"/path")
|
||||||
|
|
||||||
self.assertEqual(channel.result["code"], b"200")
|
self.assertEqual(channel.result["code"], b"200")
|
||||||
body = channel.result["body"]
|
body = channel.result["body"]
|
||||||
|
@ -296,7 +293,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
|
||||||
res = WrapHtmlRequestHandlerTests.TestResource()
|
res = WrapHtmlRequestHandlerTests.TestResource()
|
||||||
res.callback = callback
|
res.callback = callback
|
||||||
|
|
||||||
_, channel = make_request(self.reactor, FakeSite(res), b"GET", b"/path")
|
channel = make_request(self.reactor, FakeSite(res), b"GET", b"/path")
|
||||||
|
|
||||||
self.assertEqual(channel.result["code"], b"301")
|
self.assertEqual(channel.result["code"], b"301")
|
||||||
headers = channel.result["headers"]
|
headers = channel.result["headers"]
|
||||||
|
@ -317,7 +314,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
|
||||||
res = WrapHtmlRequestHandlerTests.TestResource()
|
res = WrapHtmlRequestHandlerTests.TestResource()
|
||||||
res.callback = callback
|
res.callback = callback
|
||||||
|
|
||||||
_, channel = make_request(self.reactor, FakeSite(res), b"GET", b"/path")
|
channel = make_request(self.reactor, FakeSite(res), b"GET", b"/path")
|
||||||
|
|
||||||
self.assertEqual(channel.result["code"], b"304")
|
self.assertEqual(channel.result["code"], b"304")
|
||||||
headers = channel.result["headers"]
|
headers = channel.result["headers"]
|
||||||
|
@ -336,7 +333,7 @@ class WrapHtmlRequestHandlerTests(unittest.TestCase):
|
||||||
res = WrapHtmlRequestHandlerTests.TestResource()
|
res = WrapHtmlRequestHandlerTests.TestResource()
|
||||||
res.callback = callback
|
res.callback = callback
|
||||||
|
|
||||||
_, channel = make_request(self.reactor, FakeSite(res), b"HEAD", b"/path")
|
channel = make_request(self.reactor, FakeSite(res), b"HEAD", b"/path")
|
||||||
|
|
||||||
self.assertEqual(channel.result["code"], b"200")
|
self.assertEqual(channel.result["code"], b"200")
|
||||||
self.assertNotIn("body", channel.result)
|
self.assertNotIn("body", channel.result)
|
||||||
|
|
|
@ -53,7 +53,7 @@ class TermsTestCase(unittest.HomeserverTestCase):
|
||||||
def test_ui_auth(self):
|
def test_ui_auth(self):
|
||||||
# Do a UI auth request
|
# Do a UI auth request
|
||||||
request_data = json.dumps({"username": "kermit", "password": "monkey"})
|
request_data = json.dumps({"username": "kermit", "password": "monkey"})
|
||||||
request, channel = self.make_request(b"POST", self.url, request_data)
|
channel = self.make_request(b"POST", self.url, request_data)
|
||||||
|
|
||||||
self.assertEquals(channel.result["code"], b"401", channel.result)
|
self.assertEquals(channel.result["code"], b"401", channel.result)
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ class TermsTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
self.registration_handler.check_username = Mock(return_value=True)
|
self.registration_handler.check_username = Mock(return_value=True)
|
||||||
|
|
||||||
request, channel = self.make_request(b"POST", self.url, request_data)
|
channel = self.make_request(b"POST", self.url, request_data)
|
||||||
|
|
||||||
# We don't bother checking that the response is correct - we'll leave that to
|
# We don't bother checking that the response is correct - we'll leave that to
|
||||||
# other tests. We just want to make sure we're on the right path.
|
# other tests. We just want to make sure we're on the right path.
|
||||||
|
@ -113,7 +113,7 @@ class TermsTestCase(unittest.HomeserverTestCase):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(b"POST", self.url, request_data)
|
channel = self.make_request(b"POST", self.url, request_data)
|
||||||
|
|
||||||
# We're interested in getting a response that looks like a successful
|
# We're interested in getting a response that looks like a successful
|
||||||
# registration, not so much that the details are exactly what we want.
|
# registration, not so much that the details are exactly what we want.
|
||||||
|
|
|
@ -20,7 +20,7 @@ import hmac
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from typing import Dict, Optional, Tuple, Type, TypeVar, Union, overload
|
from typing import Dict, Optional, Type, TypeVar, Union
|
||||||
|
|
||||||
from mock import Mock, patch
|
from mock import Mock, patch
|
||||||
|
|
||||||
|
@ -372,24 +372,6 @@ class HomeserverTestCase(TestCase):
|
||||||
Function to optionally be overridden in subclasses.
|
Function to optionally be overridden in subclasses.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Annoyingly mypy doesn't seem to pick up the fact that T is SynapseRequest
|
|
||||||
# when the `request` arg isn't given, so we define an explicit override to
|
|
||||||
# cover that case.
|
|
||||||
@overload
|
|
||||||
def make_request(
|
|
||||||
self,
|
|
||||||
method: Union[bytes, str],
|
|
||||||
path: Union[bytes, str],
|
|
||||||
content: Union[bytes, dict] = b"",
|
|
||||||
access_token: Optional[str] = None,
|
|
||||||
shorthand: bool = True,
|
|
||||||
federation_auth_origin: str = None,
|
|
||||||
content_is_form: bool = False,
|
|
||||||
await_result: bool = True,
|
|
||||||
) -> Tuple[SynapseRequest, FakeChannel]:
|
|
||||||
...
|
|
||||||
|
|
||||||
@overload
|
|
||||||
def make_request(
|
def make_request(
|
||||||
self,
|
self,
|
||||||
method: Union[bytes, str],
|
method: Union[bytes, str],
|
||||||
|
@ -401,21 +383,7 @@ class HomeserverTestCase(TestCase):
|
||||||
federation_auth_origin: str = None,
|
federation_auth_origin: str = None,
|
||||||
content_is_form: bool = False,
|
content_is_form: bool = False,
|
||||||
await_result: bool = True,
|
await_result: bool = True,
|
||||||
) -> Tuple[T, FakeChannel]:
|
) -> FakeChannel:
|
||||||
...
|
|
||||||
|
|
||||||
def make_request(
|
|
||||||
self,
|
|
||||||
method: Union[bytes, str],
|
|
||||||
path: Union[bytes, str],
|
|
||||||
content: Union[bytes, dict] = b"",
|
|
||||||
access_token: Optional[str] = None,
|
|
||||||
request: Type[T] = SynapseRequest,
|
|
||||||
shorthand: bool = True,
|
|
||||||
federation_auth_origin: str = None,
|
|
||||||
content_is_form: bool = False,
|
|
||||||
await_result: bool = True,
|
|
||||||
) -> Tuple[T, FakeChannel]:
|
|
||||||
"""
|
"""
|
||||||
Create a SynapseRequest at the path using the method and containing the
|
Create a SynapseRequest at the path using the method and containing the
|
||||||
given content.
|
given content.
|
||||||
|
@ -438,7 +406,7 @@ class HomeserverTestCase(TestCase):
|
||||||
tells the channel the request is finished.
|
tells the channel the request is finished.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple[synapse.http.site.SynapseRequest, channel]
|
The FakeChannel object which stores the result of the request.
|
||||||
"""
|
"""
|
||||||
return make_request(
|
return make_request(
|
||||||
self.reactor,
|
self.reactor,
|
||||||
|
@ -568,7 +536,7 @@ class HomeserverTestCase(TestCase):
|
||||||
self.hs.config.registration_shared_secret = "shared"
|
self.hs.config.registration_shared_secret = "shared"
|
||||||
|
|
||||||
# Create the user
|
# Create the user
|
||||||
request, channel = self.make_request("GET", "/_synapse/admin/v1/register")
|
channel = self.make_request("GET", "/_synapse/admin/v1/register")
|
||||||
self.assertEqual(channel.code, 200, msg=channel.result)
|
self.assertEqual(channel.code, 200, msg=channel.result)
|
||||||
nonce = channel.json_body["nonce"]
|
nonce = channel.json_body["nonce"]
|
||||||
|
|
||||||
|
@ -593,7 +561,7 @@ class HomeserverTestCase(TestCase):
|
||||||
"inhibit_login": True,
|
"inhibit_login": True,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "/_synapse/admin/v1/register", body.encode("utf8")
|
"POST", "/_synapse/admin/v1/register", body.encode("utf8")
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200, channel.json_body)
|
self.assertEqual(channel.code, 200, channel.json_body)
|
||||||
|
@ -611,7 +579,7 @@ class HomeserverTestCase(TestCase):
|
||||||
if device_id:
|
if device_id:
|
||||||
body["device_id"] = device_id
|
body["device_id"] = device_id
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "/_matrix/client/r0/login", json.dumps(body).encode("utf8")
|
"POST", "/_matrix/client/r0/login", json.dumps(body).encode("utf8")
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 200, channel.result)
|
self.assertEqual(channel.code, 200, channel.result)
|
||||||
|
@ -679,7 +647,7 @@ class HomeserverTestCase(TestCase):
|
||||||
"""
|
"""
|
||||||
body = {"type": "m.login.password", "user": username, "password": password}
|
body = {"type": "m.login.password", "user": username, "password": password}
|
||||||
|
|
||||||
request, channel = self.make_request(
|
channel = self.make_request(
|
||||||
"POST", "/_matrix/client/r0/login", json.dumps(body).encode("utf8")
|
"POST", "/_matrix/client/r0/login", json.dumps(body).encode("utf8")
|
||||||
)
|
)
|
||||||
self.assertEqual(channel.code, 403, channel.result)
|
self.assertEqual(channel.code, 403, channel.result)
|
||||||
|
|
Loading…
Reference in New Issue