summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrendan Abolivier <babolivier@matrix.org>2019-09-06 15:41:37 +0100
committerBrendan Abolivier <babolivier@matrix.org>2019-09-06 15:41:37 +0100
commite163df4c204af42ba579963c52dca93a1841d2f0 (patch)
tree5ed179c92caaef8a78d526987dcb8b0a6a2917ee
parentDon't process revoked/redacted events as part of the room's membership info (diff)
parentMerge pull request #1 from matrix-org/babolivier/direct-avatar-name (diff)
downloadsynapse-e163df4c204af42ba579963c52dca93a1841d2f0.tar.xz
Merge branch 'dinsic' into babolivier/dinsic-3pid-invite
-rwxr-xr-x.circleci/merge_base_branch.sh2
-rw-r--r--changelog.d/1.feature1
-rwxr-xr-xscripts-dev/check-newsfragment6
-rw-r--r--synapse/third_party_rules/access_rules.py48
-rw-r--r--tests/rest/client/test_room_access_rules.py120
-rw-r--r--tox.ini2
6 files changed, 166 insertions, 13 deletions
diff --git a/.circleci/merge_base_branch.sh b/.circleci/merge_base_branch.sh

index 56895284ba..3a6476a96c 100755 --- a/.circleci/merge_base_branch.sh +++ b/.circleci/merge_base_branch.sh
@@ -17,7 +17,7 @@ then GITBASE="dinsic" else # Get the reference, using the GitHub API - GITBASE=`wget -O- https://api.github.com/repos/matrix-org/synapse/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.ref'` + GITBASE=`wget -O- https://api.github.com/repos/matrix-org/synapse-dinsic/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.ref'` fi # Show what we are before diff --git a/changelog.d/1.feature b/changelog.d/1.feature new file mode 100644
index 0000000000..845642e445 --- /dev/null +++ b/changelog.d/1.feature
@@ -0,0 +1 @@ +Forbid changing the name, avatar or topic of a direct room. diff --git a/scripts-dev/check-newsfragment b/scripts-dev/check-newsfragment
index 0ec5075e79..b8a85abe18 100755 --- a/scripts-dev/check-newsfragment +++ b/scripts-dev/check-newsfragment
@@ -5,9 +5,9 @@ set -e -# make sure that origin/develop is up to date -git remote set-branches --add origin develop -git fetch origin develop +# make sure that origin/dinsic is up to date +git remote set-branches --add origin dinsic +git fetch origin dinsic # if there are changes in the debian directory, check that the debian changelog # has been updated diff --git a/synapse/third_party_rules/access_rules.py b/synapse/third_party_rules/access_rules.py
index ac09807738..0fa36ba200 100644 --- a/synapse/third_party_rules/access_rules.py +++ b/synapse/third_party_rules/access_rules.py
@@ -237,6 +237,15 @@ class RoomAccessRules(object): if event.type == EventTypes.JoinRules: return self._on_join_rule_change(event, rule) + if event.type == EventTypes.RoomAvatar: + return self._on_room_avatar_change(event, rule) + + if event.type == EventTypes.Name: + return self._on_room_name_change(event, rule) + + if event.type == EventTypes.Topic: + return self._on_room_topic_change(event, rule) + return True def _on_rules_change(self, event, state_events): @@ -461,6 +470,45 @@ class RoomAccessRules(object): return True + def _on_room_avatar_change(self, event, rule): + """Check whether a change of room avatar is allowed. + The current rule is to forbid such a change in direct chats but allow it + everywhere else. + + Args: + event (synapse.events.EventBase): The event to check. + rule (str): The name of the rule to apply. + Returns: + bool, True if the event can be allowed, False otherwise. + """ + return rule != ACCESS_RULE_DIRECT + + def _on_room_name_change(self, event, rule): + """Check whether a change of room name is allowed. + The current rule is to forbid such a change in direct chats but allow it + everywhere else. + + Args: + event (synapse.events.EventBase): The event to check. + rule (str): The name of the rule to apply. + Returns: + bool, True if the event can be allowed, False otherwise. + """ + return rule != ACCESS_RULE_DIRECT + + def _on_room_topic_change(self, event, rule): + """Check whether a change of room topic is allowed. + The current rule is to forbid such a change in direct chats but allow it + everywhere else. + + Args: + event (synapse.events.EventBase): The event to check. + rule (str): The name of the rule to apply. + Returns: + bool, True if the event can be allowed, False otherwise. + """ + return rule != ACCESS_RULE_DIRECT + @staticmethod def _get_rule_from_state(state_events): """Extract the rule to be applied from the given set of state events. diff --git a/tests/rest/client/test_room_access_rules.py b/tests/rest/client/test_room_access_rules.py
index 8fa828fa15..8da56c29dd 100644 --- a/tests/rest/client/test_room_access_rules.py +++ b/tests/rest/client/test_room_access_rules.py
@@ -483,6 +483,110 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): expected_code=403, ) + def test_change_room_avatar(self): + """Tests that changing the room avatar is always allowed unless the room is a + direct chat, in which case it's forbidden. + """ + + avatar_content = { + "info": { + "h": 398, + "mimetype": "image/jpeg", + "size": 31037, + "w": 394 + }, + "url": "mxc://example.org/JWEIFJgwEIhweiWJE", + } + + self.helper.send_state( + room_id=self.restricted_room, + event_type=EventTypes.RoomAvatar, + body=avatar_content, + tok=self.tok, + expect_code=200, + ) + + self.helper.send_state( + room_id=self.unrestricted_room, + event_type=EventTypes.RoomAvatar, + body=avatar_content, + tok=self.tok, + expect_code=200, + ) + + self.helper.send_state( + room_id=self.direct_rooms[0], + event_type=EventTypes.RoomAvatar, + body=avatar_content, + tok=self.tok, + expect_code=403, + ) + + def test_change_room_name(self): + """Tests that changing the room name is always allowed unless the room is a direct + chat, in which case it's forbidden. + """ + + name_content = { + "name": "My super room", + } + + self.helper.send_state( + room_id=self.restricted_room, + event_type=EventTypes.Name, + body=name_content, + tok=self.tok, + expect_code=200, + ) + + self.helper.send_state( + room_id=self.unrestricted_room, + event_type=EventTypes.Name, + body=name_content, + tok=self.tok, + expect_code=200, + ) + + self.helper.send_state( + room_id=self.direct_rooms[0], + event_type=EventTypes.Name, + body=name_content, + tok=self.tok, + expect_code=403, + ) + + def test_change_room_topic(self): + """Tests that changing the room topic is always allowed unless the room is a + direct chat, in which case it's forbidden. + """ + + topic_content = { + "topic": "Welcome to this room", + } + + self.helper.send_state( + room_id=self.restricted_room, + event_type=EventTypes.Topic, + body=topic_content, + tok=self.tok, + expect_code=200, + ) + + self.helper.send_state( + room_id=self.unrestricted_room, + event_type=EventTypes.Topic, + body=topic_content, + tok=self.tok, + expect_code=200, + ) + + self.helper.send_state( + room_id=self.direct_rooms[0], + event_type=EventTypes.Topic, + body=topic_content, + tok=self.tok, + expect_code=403, + def test_revoke_3pid_invite_direct(self): """Tests that revoking a 3PID invite doesn't cause the room access rules module to confuse the revokation as a new 3PID invite. @@ -492,14 +596,14 @@ class RoomAccessTestCase(unittest.HomeserverTestCase): invite_body = { "display_name": "ker...@exa...", "public_keys": [ - { - "key_validity_url": "https://validity_url", - "public_key": "ta8IQ0u1sp44HVpxYi7dFOdS/bfwDjcy4xLFlfY5KOA" - }, - { - "key_validity_url": "https://validity_url", - "public_key": "4_9nzEeDwR5N9s51jPodBiLnqH43A2_g2InVT137t9I" - } + { + "key_validity_url": "https://validity_url", + "public_key": "ta8IQ0u1sp44HVpxYi7dFOdS/bfwDjcy4xLFlfY5KOA" + }, + { + "key_validity_url": "https://validity_url", + "public_key": "4_9nzEeDwR5N9s51jPodBiLnqH43A2_g2InVT137t9I" + } ], "key_validity_url": "https://validity_url", "public_key": "ta8IQ0u1sp44HVpxYi7dFOdS/bfwDjcy4xLFlfY5KOA" diff --git a/tox.ini b/tox.ini
index 543b232ae7..b702cf670b 100644 --- a/tox.ini +++ b/tox.ini
@@ -128,7 +128,7 @@ commands = /bin/sh -c "isort -c -df -sp setup.cfg -rc synapse tests" skip_install = True deps = towncrier>=18.6.0rc1 commands = - python -m towncrier.check --compare-with=origin/develop + python -m towncrier.check --compare-with=origin/dinsic basepython = python3.6 [testenv:check-sampleconfig]