diff options
author | Brendan Abolivier <babolivier@matrix.org> | 2020-03-10 22:23:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-10 22:23:01 +0000 |
commit | 54dd28621b070ca67de9f773fe9a89e1f4dc19da (patch) | |
tree | dd1dc083e8b9c0ef80fb630c41cddc305efc7d38 /tests/handlers/test_profile.py | |
parent | Merge pull request #7058 from matrix-org/babolivier/saml_error_html (diff) | |
parent | Update sample_config.yaml (diff) | |
download | synapse-54dd28621b070ca67de9f773fe9a89e1f4dc19da.tar.xz |
Add options to disable setting profile info for prevent changes. (#7053)
Diffstat (limited to 'tests/handlers/test_profile.py')
-rw-r--r-- | tests/handlers/test_profile.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/handlers/test_profile.py b/tests/handlers/test_profile.py index d60c124eec..e600b9777b 100644 --- a/tests/handlers/test_profile.py +++ b/tests/handlers/test_profile.py @@ -19,7 +19,7 @@ from mock import Mock, NonCallableMock from twisted.internet import defer import synapse.types -from synapse.api.errors import AuthError +from synapse.api.errors import AuthError, SynapseError from synapse.handlers.profile import MasterProfileHandler from synapse.types import UserID @@ -70,6 +70,7 @@ class ProfileTestCase(unittest.TestCase): yield self.store.create_profile(self.frank.localpart) self.handler = hs.get_profile_handler() + self.hs = hs @defer.inlineCallbacks def test_get_my_name(self): @@ -91,6 +92,19 @@ class ProfileTestCase(unittest.TestCase): ) @defer.inlineCallbacks + def test_set_my_name_if_disabled(self): + self.hs.config.enable_set_displayname = False + + # Set first displayname is allowed, if displayname is null + yield self.store.set_profile_displayname(self.frank.localpart, "Frank") + + d = self.handler.set_displayname( + self.frank, synapse.types.create_requester(self.frank), "Frank Jr." + ) + + yield self.assertFailure(d, SynapseError) + + @defer.inlineCallbacks def test_set_my_name_noauth(self): d = self.handler.set_displayname( self.frank, synapse.types.create_requester(self.bob), "Frank Jr." @@ -147,3 +161,20 @@ class ProfileTestCase(unittest.TestCase): (yield self.store.get_profile_avatar_url(self.frank.localpart)), "http://my.server/pic.gif", ) + + @defer.inlineCallbacks + def test_set_my_avatar_if_disabled(self): + self.hs.config.enable_set_avatar_url = False + + # Set first time avatar is allowed, if avatar is null + yield self.store.set_profile_avatar_url( + self.frank.localpart, "http://my.server/me.png" + ) + + d = self.handler.set_avatar_url( + self.frank, + synapse.types.create_requester(self.frank), + "http://my.server/pic.gif", + ) + + yield self.assertFailure(d, SynapseError) |