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
Stop shadow-banned users from sending invites. #8095
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4b0e761
Stop shadow-banned users from sending invites.
clokep 25961b3
Add tests.
clokep 25f4b30
Fix lots of typos.
clokep d1d278e
Merge remote-tracking branch 'origin/develop' into clokep/shadow-bann…
clokep 86193e6
Add a test for inviting a 3PID.
clokep 6279ee6
Expand creation test to include invites.
clokep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ | ||
Add support for shadow-banning users (ignoring any message send requests). |
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 |
---|---|---|
|
@@ -1974,3 +1974,103 @@ def test_bad_alias(self): | |
"""An alias which does not point to the room raises a SynapseError.""" | ||
self._set_canonical_alias({"alias": "@unknown:test"}, expected_code=400) | ||
self._set_canonical_alias({"alt_aliases": ["@unknown:test"]}, expected_code=400) | ||
|
||
|
||
class ShadowBannedTestCase(unittest.HomeserverTestCase): | ||
servlets = [ | ||
synapse.rest.admin.register_servlets_for_client_rest_resource, | ||
directory.register_servlets, | ||
login.register_servlets, | ||
room.register_servlets, | ||
] | ||
|
||
def prepare(self, reactor, clock, homeserver): | ||
self.banned_user_id = self.register_user("banned", "test") | ||
self.banned_access_token = self.login("banned", "test") | ||
|
||
self.store = self.hs.get_datastore() | ||
|
||
self.get_success( | ||
self.store.db_pool.simple_update( | ||
table="users", | ||
keyvalues={"name": self.banned_user_id}, | ||
updatevalues={"shadow_banned": True}, | ||
desc="shadow_ban", | ||
) | ||
) | ||
|
||
self.other_user_id = self.register_user("otheruser", "pass") | ||
self.other_access_token = self.login("otheruser", "pass") | ||
|
||
def test_invite(self): | ||
"""Invites from shadow-banned users don't actually get sent.""" | ||
|
||
# The create works fine. | ||
room_id = self.helper.create_room_as( | ||
self.banned_user_id, tok=self.banned_access_token | ||
) | ||
|
||
# Inviting the user completes successfully. | ||
self.helper.invite( | ||
room=room_id, | ||
src=self.banned_user_id, | ||
tok=self.banned_access_token, | ||
targ=self.other_user_id, | ||
) | ||
|
||
# But the user wasn't actually invited. | ||
invited_rooms = self.get_success( | ||
self.store.get_invited_rooms_for_local_user(self.other_user_id) | ||
) | ||
self.assertEqual(invited_rooms, []) | ||
|
||
def test_invite_3pid(self): | ||
"""Ensure that a 3PID invite does not attempt to contact the identity server.""" | ||
identity_handler = self.hs.get_handlers().identity_handler | ||
identity_handler.lookup_3pid = Mock( | ||
side_effect=AssertionError("This should not get called") | ||
) | ||
|
||
# The create works fine. | ||
room_id = self.helper.create_room_as( | ||
self.banned_user_id, tok=self.banned_access_token | ||
) | ||
|
||
# Inviting the user completes successfully. | ||
request, channel = self.make_request( | ||
"POST", | ||
"/rooms/%s/invite" % (room_id,), | ||
{"id_server": "test", "medium": "email", "address": "test@test.test"}, | ||
access_token=self.banned_access_token, | ||
) | ||
self.render(request) | ||
self.assertEquals(200, channel.code, channel.result) | ||
|
||
# This should have raised an error earlier, but double check this wasn't called. | ||
identity_handler.lookup_3pid.assert_not_called() | ||
|
||
def test_create_room(self): | ||
"""Invitations during a room creation should be discarded, but the room still gets created.""" | ||
# The room creation is successful. | ||
request, channel = self.make_request( | ||
"POST", | ||
"/_matrix/client/r0/createRoom", | ||
{"visibility": "public", "invite": [self.other_user_id]}, | ||
access_token=self.banned_access_token, | ||
) | ||
self.render(request) | ||
self.assertEquals(200, channel.code, channel.result) | ||
room_id = channel.json_body["room_id"] | ||
|
||
# But the user wasn't actually invited. | ||
invited_rooms = self.get_success( | ||
self.store.get_invited_rooms_for_local_user(self.other_user_id) | ||
) | ||
self.assertEqual(invited_rooms, []) | ||
|
||
# Since a real room was created, the other user should be able to join it. | ||
self.helper.join(room_id, self.other_user_id, tok=self.other_access_token) | ||
|
||
# Both users should be in the room. | ||
users = self.get_success(self.store.get_users_in_room(room_id)) | ||
self.assertCountEqual(users, ["@banned:test", "@otheruser:test"]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about a test for inviting a user/3pid on creating a room? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a test for inviting a 3PID and re-worked this creation test to include an invite in the initial creation. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was missed in #8092 (probably missed while rebasing that branch 😢 ).