Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test to verify remote user messages can be redacted via admin api redaction endpoint if requester is admin in room #18043

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/18043.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug preventing the admin redaction endpoint from working on messages from remote users.
59 changes: 59 additions & 0 deletions tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from tests import unittest
from tests.replication._base import BaseMultiWorkerStreamTestCase
from tests.test_utils import SMALL_PNG
from tests.test_utils.event_injection import inject_event
from tests.unittest import override_config


Expand Down Expand Up @@ -5408,6 +5409,64 @@ def test_admin_redact_works_if_user_kicked_or_banned(self) -> None:
# we redacted 6 messages
self.assertEqual(len(matches), 6)

def test_redactions_for_remote_user_succeed_with_admin_priv_in_room(self) -> None:
"""
Test that if the admin requester has privileges in a room, redaction requests
succeed for a remote user
"""

# inject some messages from remote user and collect event ids
original_message_ids = []
for i in range(5):
event = self.get_success(
inject_event(
self.hs,
room_id=self.rm1,
type="m.room.message",
sender="@remote:remote_server",
content={"msgtype": "m.text", "body": f"nefarious_chatter{i}"},
)
)
original_message_ids.append(event.event_id)

# send a request to redact a remote user's messages in a room.
# the server admin created this room and has admin privilege in room
channel = self.make_request(
"POST",
"/_synapse/admin/v1/user/@remote:remote_server/redact",
content={"rooms": [self.rm1]},
access_token=self.admin_tok,
)
self.assertEqual(channel.code, 200)
id = channel.json_body.get("redact_id")

# check that there were no failed redactions
channel = self.make_request(
"GET",
f"/_synapse/admin/v1/user/redact_status/{id}",
access_token=self.admin_tok,
)
self.assertEqual(channel.code, 200)
self.assertEqual(channel.json_body.get("status"), "complete")
failed_redactions = channel.json_body.get("failed_redactions")
self.assertEqual(failed_redactions, {})

filter = json.dumps({"types": [EventTypes.Redaction]})
channel = self.make_request(
"GET",
f"rooms/{self.rm1}/messages?filter={filter}&limit=50",
access_token=self.admin_tok,
)
self.assertEqual(channel.code, 200)

for event in channel.json_body["chunk"]:
for event_id in original_message_ids:
if event["type"] == "m.room.redaction" and event["redacts"] == event_id:
original_message_ids.remove(event_id)
break
# we originally sent 5 messages so 5 should be redacted
self.assertEqual(len(original_message_ids), 0)


class UserRedactionBackgroundTaskTestCase(BaseMultiWorkerStreamTestCase):
servlets = [
Expand Down
Loading