Skip to content

Commit

Permalink
Add a test to verify remote user messages can be redacted via admin a…
Browse files Browse the repository at this point in the history
…pi redaction endpoint if requester is admin in room (#18043)
  • Loading branch information
H-Shay authored Jan 3, 2025
1 parent ebc21a8 commit b526767
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
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

0 comments on commit b526767

Please sign in to comment.