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

Commit 5e08880

Browse files
JeyRathnamclokep
andauthored
Disable sending confirmation email when 3pid is disabled matrix-org#14682 (matrix-org#14725)
* Fixes matrix-org#12277 :Disable sending confirmation email when 3pid is disabled * Fix test_add_email_if_disabled test case to reflect changes to enable_3pid_changes flag * Add changelog file * Rename newsfragment. Co-authored-by: Patrick Cloke <[email protected]>
1 parent b4de0c6 commit 5e08880

File tree

3 files changed

+11
-25
lines changed

3 files changed

+11
-25
lines changed

changelog.d/14725.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Disable sending confirmation email when 3pid is disabled.

synapse/rest/client/account.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,11 @@ def __init__(self, hs: "HomeServer"):
338338
)
339339

340340
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
341+
if not self.hs.config.registration.enable_3pid_changes:
342+
raise SynapseError(
343+
400, "3PID changes are disabled on this server", Codes.FORBIDDEN
344+
)
345+
341346
if not self.config.email.can_verify_email:
342347
logger.warning(
343348
"Adding emails have been disabled due to lack of an email config"

tests/rest/client/test_account.py

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -690,41 +690,21 @@ def test_add_email_if_disabled(self) -> None:
690690
self.hs.config.registration.enable_3pid_changes = False
691691

692692
client_secret = "foobar"
693-
session_id = self._request_token(self.email, client_secret)
694-
695-
self.assertEqual(len(self.email_attempts), 1)
696-
link = self._get_link_from_email()
697-
698-
self._validate_token(link)
699-
700693
channel = self.make_request(
701694
"POST",
702-
b"/_matrix/client/unstable/account/3pid/add",
695+
b"/_matrix/client/unstable/account/3pid/email/requestToken",
703696
{
704697
"client_secret": client_secret,
705-
"sid": session_id,
706-
"auth": {
707-
"type": "m.login.password",
708-
"user": self.user_id,
709-
"password": "test",
710-
},
698+
"email": "[email protected]",
699+
"send_attempt": 1,
711700
},
712-
access_token=self.user_id_tok,
713701
)
702+
714703
self.assertEqual(
715704
HTTPStatus.BAD_REQUEST, channel.code, msg=channel.result["body"]
716705
)
717-
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
718706

719-
# Get user
720-
channel = self.make_request(
721-
"GET",
722-
self.url_3pid,
723-
access_token=self.user_id_tok,
724-
)
725-
726-
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.result["body"])
727-
self.assertFalse(channel.json_body["threepids"])
707+
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
728708

729709
def test_delete_email(self) -> None:
730710
"""Test deleting an email from profile"""

0 commit comments

Comments
 (0)