|
20 | 20 |
|
21 | 21 | from twisted.test.proto_helpers import MemoryReactor
|
22 | 22 |
|
23 |
| -from synapse.api.constants import EventTypes, RelationTypes |
| 23 | +from synapse.api.constants import AccountDataTypes, EventTypes, RelationTypes |
24 | 24 | from synapse.rest import admin
|
25 | 25 | from synapse.rest.client import login, register, relations, room, sync
|
26 | 26 | from synapse.server import HomeServer
|
@@ -1324,6 +1324,84 @@ def test_bundled_aggregations_with_filter(self) -> None:
|
1324 | 1324 | self.assertIn("m.relations", parent_event["unsigned"])
|
1325 | 1325 |
|
1326 | 1326 |
|
| 1327 | +class RelationIgnoredUserTestCase(BaseRelationsTestCase): |
| 1328 | + """Relations sent from an ignored user should be ignored.""" |
| 1329 | + |
| 1330 | + def _test_ignored_user( |
| 1331 | + self, allowed_event_ids: List[str], ignored_event_ids: List[str] |
| 1332 | + ) -> None: |
| 1333 | + """ |
| 1334 | + Fetch the relations and ensure they're all there, then ignore user2, and |
| 1335 | + repeat. |
| 1336 | + """ |
| 1337 | + # Get the relations. |
| 1338 | + event_ids = self._get_related_events() |
| 1339 | + self.assertCountEqual(event_ids, allowed_event_ids + ignored_event_ids) |
| 1340 | + |
| 1341 | + # Ignore user2 and re-do the requests. |
| 1342 | + self.get_success( |
| 1343 | + self.store.add_account_data_for_user( |
| 1344 | + self.user_id, |
| 1345 | + AccountDataTypes.IGNORED_USER_LIST, |
| 1346 | + {"ignored_users": {self.user2_id: {}}}, |
| 1347 | + ) |
| 1348 | + ) |
| 1349 | + |
| 1350 | + # Get the relations. |
| 1351 | + event_ids = self._get_related_events() |
| 1352 | + self.assertCountEqual(event_ids, allowed_event_ids) |
| 1353 | + |
| 1354 | + def test_annotation(self) -> None: |
| 1355 | + """Annotations should ignore""" |
| 1356 | + # Send 2 from us, 2 from the to be ignored user. |
| 1357 | + allowed_event_ids = [] |
| 1358 | + ignored_event_ids = [] |
| 1359 | + channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", key="a") |
| 1360 | + allowed_event_ids.append(channel.json_body["event_id"]) |
| 1361 | + channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", key="b") |
| 1362 | + allowed_event_ids.append(channel.json_body["event_id"]) |
| 1363 | + channel = self._send_relation( |
| 1364 | + RelationTypes.ANNOTATION, |
| 1365 | + "m.reaction", |
| 1366 | + key="a", |
| 1367 | + access_token=self.user2_token, |
| 1368 | + ) |
| 1369 | + ignored_event_ids.append(channel.json_body["event_id"]) |
| 1370 | + channel = self._send_relation( |
| 1371 | + RelationTypes.ANNOTATION, |
| 1372 | + "m.reaction", |
| 1373 | + key="c", |
| 1374 | + access_token=self.user2_token, |
| 1375 | + ) |
| 1376 | + ignored_event_ids.append(channel.json_body["event_id"]) |
| 1377 | + |
| 1378 | + self._test_ignored_user(allowed_event_ids, ignored_event_ids) |
| 1379 | + |
| 1380 | + def test_reference(self) -> None: |
| 1381 | + """Annotations should ignore""" |
| 1382 | + channel = self._send_relation(RelationTypes.REFERENCE, "m.room.test") |
| 1383 | + allowed_event_ids = [channel.json_body["event_id"]] |
| 1384 | + |
| 1385 | + channel = self._send_relation( |
| 1386 | + RelationTypes.REFERENCE, "m.room.test", access_token=self.user2_token |
| 1387 | + ) |
| 1388 | + ignored_event_ids = [channel.json_body["event_id"]] |
| 1389 | + |
| 1390 | + self._test_ignored_user(allowed_event_ids, ignored_event_ids) |
| 1391 | + |
| 1392 | + def test_thread(self) -> None: |
| 1393 | + """Annotations should ignore""" |
| 1394 | + channel = self._send_relation(RelationTypes.THREAD, "m.room.test") |
| 1395 | + allowed_event_ids = [channel.json_body["event_id"]] |
| 1396 | + |
| 1397 | + channel = self._send_relation( |
| 1398 | + RelationTypes.THREAD, "m.room.test", access_token=self.user2_token |
| 1399 | + ) |
| 1400 | + ignored_event_ids = [channel.json_body["event_id"]] |
| 1401 | + |
| 1402 | + self._test_ignored_user(allowed_event_ids, ignored_event_ids) |
| 1403 | + |
| 1404 | + |
1327 | 1405 | class RelationRedactionTestCase(BaseRelationsTestCase):
|
1328 | 1406 | """
|
1329 | 1407 | Test the behaviour of relations when the parent or child event is redacted.
|
|
0 commit comments