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.
Add 3pid unbind callback to module API
- Loading branch information
Showing
6 changed files
with
179 additions
and
40 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
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 |
---|---|---|
|
@@ -937,3 +937,58 @@ def test_on_threepid_bind(self) -> None: | |
|
||
# Check that the mock was called with the right parameters | ||
self.assertEqual(args, (user_id, "email", "[email protected]")) | ||
|
||
def test_on_threepid_unbind(self) -> None: | ||
"""Tests that the on_threepid_unbind module callback is called correctly before | ||
removing a 3PID mapping. | ||
""" | ||
# Register a mocked callback. | ||
threepid_unbind_mock = Mock(return_value=make_awaitable(None)) | ||
third_party_rules = self.hs.get_third_party_event_rules() | ||
third_party_rules._on_threepid_unbind_callbacks.append(threepid_unbind_mock) | ||
|
||
# Register an admin user. | ||
self.register_user("admin", "password", admin=True) | ||
admin_tok = self.login("admin", "password") | ||
|
||
# Also register a normal user we can modify. | ||
user_id = self.register_user("user", "password") | ||
|
||
# Add a 3PID to the user. | ||
channel = self.make_request( | ||
"PUT", | ||
"/_synapse/admin/v2/users/%s" % user_id, | ||
{ | ||
"threepids": [ | ||
{ | ||
"medium": "email", | ||
"address": "[email protected]", | ||
}, | ||
], | ||
}, | ||
access_token=admin_tok, | ||
) | ||
self.assertEqual(channel.code, 200, channel.json_body) | ||
|
||
# Remove the 3PID mapping. | ||
channel = self.make_request( | ||
"DELETE", | ||
"/_synapse/admin/v2/users/%s" % user_id, | ||
{ | ||
"threepids": [ | ||
{ | ||
"medium": "email", | ||
"address": "[email protected]", | ||
}, | ||
], | ||
}, | ||
access_token=admin_tok, | ||
) | ||
self.assertEqual(channel.code, 200, channel.json_body) | ||
|
||
# Check that the mock was called once. | ||
threepid_unbind_mock.assert_called_once() | ||
args = threepid_unbind_mock.call_args[0] | ||
|
||
# Check that the mock was called with the right parameters | ||
self.assertEqual(args, (user_id, "email", "[email protected]")) |