|
60 | 60 | from tests import unittest
|
61 | 61 | from tests.replication._base import BaseMultiWorkerStreamTestCase
|
62 | 62 | from tests.test_utils import SMALL_PNG
|
| 63 | +from tests.test_utils.event_injection import inject_event |
63 | 64 | from tests.unittest import override_config
|
64 | 65 |
|
65 | 66 |
|
@@ -5408,6 +5409,64 @@ def test_admin_redact_works_if_user_kicked_or_banned(self) -> None:
|
5408 | 5409 | # we redacted 6 messages
|
5409 | 5410 | self.assertEqual(len(matches), 6)
|
5410 | 5411 |
|
| 5412 | + def test_redactions_for_remote_user_succeed_with_admin_priv_in_room(self) -> None: |
| 5413 | + """ |
| 5414 | + Test that if the admin requester has privileges in a room, redaction requests |
| 5415 | + succeed for a remote user |
| 5416 | + """ |
| 5417 | + |
| 5418 | + # inject some messages from remote user and collect event ids |
| 5419 | + original_message_ids = [] |
| 5420 | + for i in range(5): |
| 5421 | + event = self.get_success( |
| 5422 | + inject_event( |
| 5423 | + self.hs, |
| 5424 | + room_id=self.rm1, |
| 5425 | + type="m.room.message", |
| 5426 | + sender="@remote:remote_server", |
| 5427 | + content={"msgtype": "m.text", "body": f"nefarious_chatter{i}"}, |
| 5428 | + ) |
| 5429 | + ) |
| 5430 | + original_message_ids.append(event.event_id) |
| 5431 | + |
| 5432 | + # send a request to redact a remote user's messages in a room. |
| 5433 | + # the server admin created this room and has admin privilege in room |
| 5434 | + channel = self.make_request( |
| 5435 | + "POST", |
| 5436 | + "/_synapse/admin/v1/user/@remote:remote_server/redact", |
| 5437 | + content={"rooms": [self.rm1]}, |
| 5438 | + access_token=self.admin_tok, |
| 5439 | + ) |
| 5440 | + self.assertEqual(channel.code, 200) |
| 5441 | + id = channel.json_body.get("redact_id") |
| 5442 | + |
| 5443 | + # check that there were no failed redactions |
| 5444 | + channel = self.make_request( |
| 5445 | + "GET", |
| 5446 | + f"/_synapse/admin/v1/user/redact_status/{id}", |
| 5447 | + access_token=self.admin_tok, |
| 5448 | + ) |
| 5449 | + self.assertEqual(channel.code, 200) |
| 5450 | + self.assertEqual(channel.json_body.get("status"), "complete") |
| 5451 | + failed_redactions = channel.json_body.get("failed_redactions") |
| 5452 | + self.assertEqual(failed_redactions, {}) |
| 5453 | + |
| 5454 | + filter = json.dumps({"types": [EventTypes.Redaction]}) |
| 5455 | + channel = self.make_request( |
| 5456 | + "GET", |
| 5457 | + f"rooms/{self.rm1}/messages?filter={filter}&limit=50", |
| 5458 | + access_token=self.admin_tok, |
| 5459 | + ) |
| 5460 | + self.assertEqual(channel.code, 200) |
| 5461 | + |
| 5462 | + for event in channel.json_body["chunk"]: |
| 5463 | + for event_id in original_message_ids: |
| 5464 | + if event["type"] == "m.room.redaction" and event["redacts"] == event_id: |
| 5465 | + original_message_ids.remove(event_id) |
| 5466 | + break |
| 5467 | + # we originally sent 5 messages so 5 should be redacted |
| 5468 | + self.assertEqual(len(original_message_ids), 0) |
| 5469 | + |
5411 | 5470 |
|
5412 | 5471 | class UserRedactionBackgroundTaskTestCase(BaseMultiWorkerStreamTestCase):
|
5413 | 5472 | servlets = [
|
|
0 commit comments