diff --git a/synapse/events/spamcheck.py b/synapse/events/spamcheck.py index 458be77083..b404cf6f84 100644 --- a/synapse/events/spamcheck.py +++ b/synapse/events/spamcheck.py @@ -45,7 +45,10 @@ CHECK_EVENT_FOR_SPAM_CALLBACK = Callable[ Awaitable[Union[bool, str]], ] # FIXME: Callback signature differs from mainline -USER_MAY_INVITE_CALLBACK = Callable[[str, str, str, str, bool, bool], Awaitable[bool]] +USER_MAY_INVITE_CALLBACK = Callable[ + [str, Optional[str], Optional[dict], str, bool, bool], + Awaitable[bool] +] # FIXME: Callback signature differs from mainline USER_MAY_CREATE_ROOM_CALLBACK = Callable[ [str, List[str], List[dict], bool], Awaitable[bool] diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py index a12fa30bfd..3688a7f5e7 100644 --- a/synapse/http/servlet.py +++ b/synapse/http/servlet.py @@ -22,7 +22,7 @@ from typing import ( Optional, Sequence, Tuple, - overload, + overload, Union, ) from typing_extensions import Literal @@ -630,7 +630,7 @@ def parse_json_object_from_request( return content -def assert_params_in_dict(body: JsonDict, required: Iterable[str]) -> None: +def assert_params_in_dict(body: JsonDict, required: Iterable[Union[str, bytes]]) -> None: absent = [] for k in required: if k not in body: diff --git a/synapse/rest/client/account.py b/synapse/rest/client/account.py index d5ef51a8c4..69e3083fea 100644 --- a/synapse/rest/client/account.py +++ b/synapse/rest/client/account.py @@ -17,7 +17,7 @@ import logging import random import re from http import HTTPStatus -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional from urllib.parse import urlparse from synapse.api.constants import LoginType @@ -692,7 +692,10 @@ class ThreepidRestServlet(RestServlet): # This makes the API entirely change shape when we have an AS token; # it really should be an entirely separate API - perhaps # /account/3pid/replicate or something. - threepid = body.get("threepid") + threepid: Optional[dict] = body.get("threepid") + + if not threepid: + raise SynapseError(400, "Missing param 'threepid'") await self.auth_handler.add_threepid( user_id, diff --git a/tests/storage/test_profile.py b/tests/storage/test_profile.py index 33ef510b21..acbb9a57c4 100644 --- a/tests/storage/test_profile.py +++ b/tests/storage/test_profile.py @@ -41,7 +41,7 @@ class ProfileStoreTestCase(unittest.HomeserverTestCase): # test set to None self.get_success( - self.store.set_profile_displayname(self.u_frank.localpart, None) + self.store.set_profile_displayname(self.u_frank.localpart, None, 1) ) self.assertIsNone(