This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5462 from matrix-org/babolivier/account_validity_…
…deactivated_accounts_2 Don't send renewal emails to deactivated users (second attempt)
- Loading branch information
Showing
6 changed files
with
68 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a bug where deactivated users could receive renewal emails if the account validity feature is on. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
from synapse.api.errors import Codes | ||
from synapse.appservice import ApplicationService | ||
from synapse.rest.client.v1 import login | ||
from synapse.rest.client.v2_alpha import account_validity, register, sync | ||
from synapse.rest.client.v2_alpha import account, account_validity, register, sync | ||
|
||
from tests import unittest | ||
|
||
|
@@ -308,6 +308,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase): | |
login.register_servlets, | ||
sync.register_servlets, | ||
account_validity.register_servlets, | ||
account.register_servlets, | ||
] | ||
|
||
def make_homeserver(self, reactor, clock): | ||
|
@@ -358,20 +359,7 @@ def sendmail(*args, **kwargs): | |
def test_renewal_email(self): | ||
self.email_attempts = [] | ||
|
||
user_id = self.register_user("kermit", "monkey") | ||
tok = self.login("kermit", "monkey") | ||
# We need to manually add an email address otherwise the handler will do | ||
# nothing. | ||
now = self.hs.clock.time_msec() | ||
self.get_success( | ||
self.store.user_add_threepid( | ||
user_id=user_id, | ||
medium="email", | ||
address="[email protected]", | ||
validated_at=now, | ||
added_at=now, | ||
) | ||
) | ||
(user_id, tok) = self.create_user() | ||
|
||
# Move 6 days forward. This should trigger a renewal email to be sent. | ||
self.reactor.advance(datetime.timedelta(days=6).total_seconds()) | ||
|
@@ -396,6 +384,44 @@ def test_renewal_email(self): | |
def test_manual_email_send(self): | ||
self.email_attempts = [] | ||
|
||
(user_id, tok) = self.create_user() | ||
request, channel = self.make_request( | ||
b"POST", | ||
"/_matrix/client/unstable/account_validity/send_mail", | ||
access_token=tok, | ||
) | ||
self.render(request) | ||
self.assertEquals(channel.result["code"], b"200", channel.result) | ||
|
||
self.assertEqual(len(self.email_attempts), 1) | ||
|
||
def test_deactivated_user(self): | ||
self.email_attempts = [] | ||
|
||
(user_id, tok) = self.create_user() | ||
|
||
request_data = json.dumps({ | ||
"auth": { | ||
"type": "m.login.password", | ||
"user": user_id, | ||
"password": "monkey", | ||
}, | ||
"erase": False, | ||
}) | ||
request, channel = self.make_request( | ||
"POST", | ||
"account/deactivate", | ||
request_data, | ||
access_token=tok, | ||
) | ||
self.render(request) | ||
self.assertEqual(request.code, 200) | ||
|
||
self.reactor.advance(datetime.timedelta(days=8).total_seconds()) | ||
|
||
self.assertEqual(len(self.email_attempts), 0) | ||
|
||
def create_user(self): | ||
user_id = self.register_user("kermit", "monkey") | ||
tok = self.login("kermit", "monkey") | ||
# We need to manually add an email address otherwise the handler will do | ||
|
@@ -410,16 +436,7 @@ def test_manual_email_send(self): | |
added_at=now, | ||
) | ||
) | ||
|
||
request, channel = self.make_request( | ||
b"POST", | ||
"/_matrix/client/unstable/account_validity/send_mail", | ||
access_token=tok, | ||
) | ||
self.render(request) | ||
self.assertEquals(channel.result["code"], b"200", channel.result) | ||
|
||
self.assertEqual(len(self.email_attempts), 1) | ||
return (user_id, tok) | ||
|
||
def test_manual_email_send_expired_account(self): | ||
user_id = self.register_user("kermit", "monkey") | ||
|