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

Commit

Permalink
Fix event filtering for frozen events
Browse files Browse the repository at this point in the history
Looks like this one was introduced by #11194.
  • Loading branch information
richvdh committed Feb 28, 2022
1 parent 024b03d commit ee7a13f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions synapse/api/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
Dict,
Iterable,
List,
Mapping,
Optional,
Set,
TypeVar,
Expand Down Expand Up @@ -361,10 +362,10 @@ def _check(self, event: FilterEvent) -> bool:
return self._check_fields(field_matchers)
else:
content = event.get("content")
# Content is assumed to be a dict below, so ensure it is. This should
# Content is assumed to be a mapping below, so ensure it is. This should
# always be true for events, but account_data has been allowed to
# have non-dict content.
if not isinstance(content, dict):
if not isinstance(content, Mapping):
content = {}

sender = event.get("sender", None)
Expand Down
10 changes: 10 additions & 0 deletions tests/api/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from unittest.mock import patch

import jsonschema
from frozendict import frozendict

from synapse.api.constants import EventContentFields
from synapse.api.errors import SynapseError
Expand Down Expand Up @@ -327,6 +328,15 @@ def test_filter_labels(self):

self.assertFalse(Filter(self.hs, definition)._check(event))

# check it works with frozendicts too
event = MockEvent(
sender="@foo:bar",
type="m.room.message",
room_id="!secretbase:unknown",
content=frozendict({EventContentFields.LABELS: ["#fun"]}),
)
self.assertTrue(Filter(self.hs, definition)._check(event))

def test_filter_not_labels(self):
definition = {"org.matrix.not_labels": ["#fun"]}
event = MockEvent(
Expand Down

0 comments on commit ee7a13f

Please sign in to comment.