Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Allow admins to proactively block rooms #11228

Merged
merged 15 commits into from
Nov 9, 2021
Prev Previous commit
Next Next commit
Test that you can block an unknown room
  • Loading branch information
David Robertson committed Nov 1, 2021
commit 0ed7a3157ff4c991fc1ac437c7fec158ff77c126
28 changes: 28 additions & 0 deletions tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

import json
import urllib.parse
from http import HTTPStatus
from typing import List, Optional
from unittest.mock import Mock

from parameterized import parameterized

import synapse.rest.admin
from synapse.api.constants import EventTypes, Membership
from synapse.api.errors import Codes
Expand Down Expand Up @@ -281,6 +284,31 @@ def test_block_room_and_not_purge(self):
self._is_blocked(self.room_id, expect=True)
self._has_no_members(self.room_id)

@parameterized.expand([(True,), (False,)])
def test_block_unknown_room(self, purge: bool) -> None:
"""
We can block an unknown room. In this case, the `purge` argument
should be ignored.
"""
room_id = "!unknown:test"

# The room isn't already in the blocked rooms table
self._is_blocked(room_id, expect=False)

# Request the room be blocked.
channel = self.make_request(
self.method,
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
f"/_synapse/admin/v1/rooms/{room_id}",
{"block": True, "purge": purge},
access_token=self.admin_user_tok,
)

# The room is now blocked.
self.assertEqual(
HTTPStatus.OK, int(channel.result["code"]), msg=channel.result["body"]
)
self._is_blocked(room_id)

def test_shutdown_room_consent(self):
"""Test that we can shutdown rooms with local users who have not
yet accepted the privacy policy. This used to fail when we tried to
Expand Down