diff options
author | Richard van der Hoff <richard@matrix.org> | 2020-10-13 22:02:41 +0100 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2020-10-13 23:24:50 +0100 |
commit | 898196f1cca419c0d2b60529c86ddff3cea83072 (patch) | |
tree | 83685785d64861d6d227e0e5b6db6ef1e20f0332 /tests | |
parent | Allow ThirdPartyRules modules to replace event content (diff) | |
download | synapse-898196f1cca419c0d2b60529c86ddff3cea83072.tar.xz |
guard against accidental modification
Diffstat (limited to 'tests')
-rw-r--r-- | tests/rest/client/test_third_party_rules.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/rest/client/test_third_party_rules.py b/tests/rest/client/test_third_party_rules.py index d404550800..0048bea54a 100644 --- a/tests/rest/client/test_third_party_rules.py +++ b/tests/rest/client/test_third_party_rules.py @@ -114,6 +114,26 @@ class ThirdPartyRulesTestCase(unittest.HomeserverTestCase): self.render(request) self.assertEquals(channel.result["code"], b"403", channel.result) + def test_cannot_modify_event(self): + """cannot accidentally modify an event before it is persisted""" + + # first patch the event checker so that it will try to modify the event + async def check(ev: EventBase, state): + ev.content = {"x": "y"} + return True + + current_rules_module().check_event_allowed = check + + # now send the event + request, channel = self.make_request( + "PUT", + "/_matrix/client/r0/rooms/%s/send/modifyme/1" % self.room_id, + {"x": "x"}, + access_token=self.tok, + ) + self.render(request) + self.assertEqual(channel.result["code"], b"500", channel.result) + def test_modify_event(self): """The module can return a modified version of the event""" # first patch the event checker so that it will modify the event |