Skip to content
Snippets Groups Projects
Unverified Commit 5e088807 authored by Jeyachandran Rathnam's avatar Jeyachandran Rathnam Committed by GitHub
Browse files

Disable sending confirmation email when 3pid is disabled #14682 (#14725)


* Fixes #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: default avatarPatrick Cloke <clokep@users.noreply.github.com>
parent b4de0c63
No related branches found
No related tags found
No related merge requests found
Disable sending confirmation email when 3pid is disabled.
......@@ -338,6 +338,11 @@ class EmailThreepidRequestTokenRestServlet(RestServlet):
)
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
if not self.hs.config.registration.enable_3pid_changes:
raise SynapseError(
400, "3PID changes are disabled on this server", Codes.FORBIDDEN
)
if not self.config.email.can_verify_email:
logger.warning(
"Adding emails have been disabled due to lack of an email config"
......
......@@ -690,41 +690,21 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
self.hs.config.registration.enable_3pid_changes = False
client_secret = "foobar"
session_id = self._request_token(self.email, client_secret)
self.assertEqual(len(self.email_attempts), 1)
link = self._get_link_from_email()
self._validate_token(link)
channel = self.make_request(
"POST",
b"/_matrix/client/unstable/account/3pid/add",
b"/_matrix/client/unstable/account/3pid/email/requestToken",
{
"client_secret": client_secret,
"sid": session_id,
"auth": {
"type": "m.login.password",
"user": self.user_id,
"password": "test",
},
"email": "test@example.com",
"send_attempt": 1,
},
access_token=self.user_id_tok,
)
self.assertEqual(
HTTPStatus.BAD_REQUEST, channel.code, msg=channel.result["body"]
)
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
# Get user
channel = self.make_request(
"GET",
self.url_3pid,
access_token=self.user_id_tok,
)
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.result["body"])
self.assertFalse(channel.json_body["threepids"])
self.assertEqual(Codes.FORBIDDEN, channel.json_body["errcode"])
def test_delete_email(self) -> None:
"""Test deleting an email from profile"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment