|
|
|
@ -35,6 +35,7 @@ def MockEvent(**kwargs): |
|
|
|
|
kwargs["type"] = "fake_type" |
|
|
|
|
return FrozenEvent(kwargs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FilteringTestCase(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
@defer.inlineCallbacks |
|
|
|
@ -56,18 +57,61 @@ class FilteringTestCase(unittest.TestCase): |
|
|
|
|
|
|
|
|
|
def test_errors_on_invalid_filters(self): |
|
|
|
|
invalid_filters = [ |
|
|
|
|
{ "boom": {} }, |
|
|
|
|
{ "account_data": "Hello World" }, |
|
|
|
|
{ "event_fields": ["\\foo"] }, |
|
|
|
|
{ "room": { "timeline" : { "limit" : 0 }, "state": { "not_bars": ["*"]} } }, |
|
|
|
|
{"boom": {}}, |
|
|
|
|
{"account_data": "Hello World"}, |
|
|
|
|
{"event_fields": ["\\foo"]}, |
|
|
|
|
{"room": {"timeline": {"limit": 0}, "state": {"not_bars": ["*"]}}}, |
|
|
|
|
{"event_format": "other"} |
|
|
|
|
] |
|
|
|
|
for filter in invalid_filters: |
|
|
|
|
with self.assertRaises(SynapseError) as check_filter_error: |
|
|
|
|
self.filtering.check_valid_filter(filter) |
|
|
|
|
self.assertIsInstance(check_filter_error.exception, SynapseError) |
|
|
|
|
|
|
|
|
|
def test_valid_filters(self): |
|
|
|
|
valid_filters = [ |
|
|
|
|
{ |
|
|
|
|
"room": { |
|
|
|
|
"timeline": {"limit": 20}, |
|
|
|
|
"state": {"not_types": ["m.room.member"]}, |
|
|
|
|
"ephemeral": {"limit": 0, "not_types": ["*"]}, |
|
|
|
|
"include_leave": False, |
|
|
|
|
"rooms": ["#dee:pik-test"], |
|
|
|
|
"not_rooms": ["#gee:pik-test"], |
|
|
|
|
"account_data": {"limit": 0, "types": ["*"]} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
"room": { |
|
|
|
|
"state": { |
|
|
|
|
"types": ["m.room.*"], |
|
|
|
|
"not_rooms": ["!726s6s6q:example.com"] |
|
|
|
|
}, |
|
|
|
|
"timeline": { |
|
|
|
|
"limit": 10, |
|
|
|
|
"types": ["m.room.message"], |
|
|
|
|
"not_rooms": ["!726s6s6q:example.com"], |
|
|
|
|
"not_senders": ["@spam:example.com"] |
|
|
|
|
}, |
|
|
|
|
"ephemeral": { |
|
|
|
|
"types": ["m.receipt", "m.typing"], |
|
|
|
|
"not_rooms": ["!726s6s6q:example.com"], |
|
|
|
|
"not_senders": ["@spam:example.com"] |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
"presence": { |
|
|
|
|
"types": ["m.presence"], |
|
|
|
|
"not_senders": ["@alice:example.com"] |
|
|
|
|
}, |
|
|
|
|
"event_format": "client", |
|
|
|
|
"event_fields": ["type", "content", "sender"] |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
for filter in valid_filters: |
|
|
|
|
self.filtering.check_valid_filter(filter) |
|
|
|
|
|
|
|
|
|
def test_limits_are_applied(self): |
|
|
|
|
#TODO |
|
|
|
|
# TODO |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
def test_definition_types_works_with_literals(self): |
|
|
|
|