Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 685f76f

Browse files
committed
Block new accounts after registering if configured to do so
1 parent 1eaff08 commit 685f76f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

synapse/rest/client/register.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ def __init__(self, hs: "HomeServer"):
433433
hs.config.registration.inhibit_user_in_use_error
434434
)
435435

436+
self._require_approval = (
437+
hs.config.experimental.msc3866.enabled
438+
and hs.config.experimental.msc3866.require_approval_for_new_accounts
439+
)
440+
436441
self._registration_flows = _calculate_registration_flows(
437442
hs.config, self.auth_handler
438443
)
@@ -756,6 +761,13 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
756761
access_token=return_dict.get("access_token"),
757762
)
758763

764+
if self._require_approval:
765+
raise SynapseError(
766+
code=403,
767+
errcode=Codes.USER_AWAITING_APPROVAL,
768+
msg="This account needs to be approved by an administrator before it can be used.",
769+
)
770+
759771
return 200, return_dict
760772

761773
async def _do_appservice_registration(

tests/rest/client/test_register.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,29 @@ def test_inhibit_user_in_use_error(self) -> None:
765765
self.assertEqual(channel.code, 400, channel.json_body)
766766
self.assertEqual(channel.json_body["errcode"], Codes.USER_IN_USE)
767767

768+
@override_config(
769+
{
770+
"experimental_features": {
771+
"msc3866": {
772+
"enabled": True,
773+
"require_approval_for_new_accounts": True,
774+
}
775+
}
776+
}
777+
)
778+
def test_require_approval(self) -> None:
779+
channel = self.make_request(
780+
"POST",
781+
"register",
782+
{
783+
"username": "kermit",
784+
"password": "monkey",
785+
"auth": {"type": LoginType.DUMMY},
786+
},
787+
)
788+
self.assertEqual(403, channel.code, channel.result)
789+
self.assertEqual(Codes.USER_AWAITING_APPROVAL, channel.json_body["errcode"])
790+
768791

769792
class AccountValidityTestCase(unittest.HomeserverTestCase):
770793

0 commit comments

Comments
 (0)