0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-15 22:42:23 +01:00

Replace request.code with channel.code

The two are equivalent, but really we want to check the HTTP result that got
returned to the channel, not the code that the Request object *intended* to
return to the channel.
This commit is contained in:
Richard van der Hoff 2020-12-15 14:51:25 +00:00
parent 01333681bc
commit 7eebe4b3fc
8 changed files with 22 additions and 22 deletions

View file

@ -48,7 +48,7 @@ class AdditionalResourceTests(HomeserverTestCase):
request, channel = make_request(self.reactor, FakeSite(resource), "GET", "/") request, 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):
@ -57,5 +57,5 @@ class AdditionalResourceTests(HomeserverTestCase):
request, channel = make_request(self.reactor, FakeSite(resource), "GET", "/") request, 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"})

View file

@ -66,7 +66,7 @@ class WorkerAuthenticationTestCase(BaseMultiWorkerStreamTestCase):
"register", "register",
{"username": "user", "type": "m.login.password", "password": "bar"}, {"username": "user", "type": "m.login.password", "password": "bar"},
) # type: SynapseRequest, FakeChannel ) # 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"]
@ -84,7 +84,7 @@ class WorkerAuthenticationTestCase(BaseMultiWorkerStreamTestCase):
"""With no authentication the request should finish. """With no authentication the request should finish.
""" """
request, channel = self._test_register() request, 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")
@ -94,7 +94,7 @@ class WorkerAuthenticationTestCase(BaseMultiWorkerStreamTestCase):
"""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() request, channel = self._test_register()
self.assertEqual(request.code, 500) self.assertEqual(channel.code, 500)
@override_config( @override_config(
{ {
@ -106,14 +106,14 @@ class WorkerAuthenticationTestCase(BaseMultiWorkerStreamTestCase):
"""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() request, 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() request, 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")

View file

@ -48,7 +48,7 @@ class ClientReaderTestCase(BaseMultiWorkerStreamTestCase):
"register", "register",
{"username": "user", "type": "m.login.password", "password": "bar"}, {"username": "user", "type": "m.login.password", "password": "bar"},
) # type: SynapseRequest, FakeChannel ) # 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"]
@ -61,7 +61,7 @@ class ClientReaderTestCase(BaseMultiWorkerStreamTestCase):
"register", "register",
{"auth": {"session": session, "type": "m.login.dummy"}}, {"auth": {"session": session, "type": "m.login.dummy"}},
) # type: SynapseRequest, FakeChannel ) # 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")
@ -80,7 +80,7 @@ class ClientReaderTestCase(BaseMultiWorkerStreamTestCase):
"register", "register",
{"username": "user", "type": "m.login.password", "password": "bar"}, {"username": "user", "type": "m.login.password", "password": "bar"},
) # type: SynapseRequest, FakeChannel ) # 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"]
@ -94,7 +94,7 @@ class ClientReaderTestCase(BaseMultiWorkerStreamTestCase):
"register", "register",
{"auth": {"session": session, "type": "m.login.dummy"}}, {"auth": {"session": session, "type": "m.login.dummy"}},
) # type: SynapseRequest, FakeChannel ) # 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")

View file

@ -353,7 +353,7 @@ class DeactivateTestCase(unittest.HomeserverTestCase):
# Check that this access token has been invalidated. # Check that this access token has been invalidated.
request, channel = self.make_request("GET", "account/whoami") request, 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."""
@ -410,7 +410,7 @@ class DeactivateTestCase(unittest.HomeserverTestCase):
request, channel = self.make_request( 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):

View file

@ -71,7 +71,7 @@ class FallbackAuthTests(unittest.HomeserverTestCase):
"POST", "register", body "POST", "register", body
) # type: SynapseRequest, FakeChannel ) # type: SynapseRequest, FakeChannel
self.assertEqual(request.code, expected_response) self.assertEqual(channel.code, expected_response)
return channel return channel
def recaptcha( def recaptcha(
@ -84,7 +84,7 @@ class FallbackAuthTests(unittest.HomeserverTestCase):
request, channel = self.make_request( 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 ) # type: SynapseRequest, FakeChannel
self.assertEqual(request.code, 200) self.assertEqual(channel.code, 200)
request, channel = self.make_request( request, channel = self.make_request(
"POST", "POST",
@ -92,7 +92,7 @@ class FallbackAuthTests(unittest.HomeserverTestCase):
+ 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
@ -201,7 +201,7 @@ class UIAuthTests(unittest.HomeserverTestCase):
) # type: SynapseRequest, FakeChannel ) # 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
@ -214,7 +214,7 @@ class UIAuthTests(unittest.HomeserverTestCase):
) # type: SynapseRequest, FakeChannel ) # 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

View file

@ -559,7 +559,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
request, channel = self.make_request( 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())

View file

@ -27,5 +27,5 @@ class HealthCheckTests(unittest.HomeserverTestCase):
def test_health(self): def test_health(self):
request, channel = self.make_request("GET", "/health", shorthand=False) request, 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")

View file

@ -32,7 +32,7 @@ class WellKnownTests(unittest.HomeserverTestCase):
"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,
{ {
@ -48,4 +48,4 @@ class WellKnownTests(unittest.HomeserverTestCase):
"GET", "/.well-known/matrix/client", shorthand=False "GET", "/.well-known/matrix/client", shorthand=False
) )
self.assertEqual(request.code, 404) self.assertEqual(channel.code, 404)