summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/handlers/test_profile.py9
-rw-r--r--tests/rulecheck/__init__.py14
-rw-r--r--tests/rulecheck/test_domainrulecheck.py101
-rw-r--r--tests/storage/test_profile.py12
-rw-r--r--tests/utils.py1
5 files changed, 121 insertions, 16 deletions
diff --git a/tests/handlers/test_profile.py b/tests/handlers/test_profile.py

index 458296ee4c..b2fd4b9af9 100644 --- a/tests/handlers/test_profile.py +++ b/tests/handlers/test_profile.py
@@ -68,14 +68,12 @@ class ProfileTestCase(unittest.TestCase): self.bob = UserID.from_string("@4567:test") self.alice = UserID.from_string("@alice:remote") - yield self.store.create_profile(self.frank.localpart) - self.handler = hs.get_profile_handler() @defer.inlineCallbacks def test_get_my_name(self): yield self.store.set_profile_displayname( - self.frank.localpart, "Frank" + self.frank.localpart, "Frank", 1, ) displayname = yield self.handler.get_displayname(self.frank) @@ -123,8 +121,7 @@ class ProfileTestCase(unittest.TestCase): @defer.inlineCallbacks def test_incoming_fed_query(self): - yield self.store.create_profile("caroline") - yield self.store.set_profile_displayname("caroline", "Caroline") + yield self.store.set_profile_displayname("caroline", "Caroline", 1) response = yield self.query_handlers["profile"]( {"user_id": "@caroline:test", "field": "displayname"} @@ -135,7 +132,7 @@ class ProfileTestCase(unittest.TestCase): @defer.inlineCallbacks def test_get_my_avatar(self): yield self.store.set_profile_avatar_url( - self.frank.localpart, "http://my.server/me.png" + self.frank.localpart, "http://my.server/me.png", 1, ) avatar_url = yield self.handler.get_avatar_url(self.frank) diff --git a/tests/rulecheck/__init__.py b/tests/rulecheck/__init__.py new file mode 100644
index 0000000000..a354d38ca8 --- /dev/null +++ b/tests/rulecheck/__init__.py
@@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 New Vector Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/tests/rulecheck/test_domainrulecheck.py b/tests/rulecheck/test_domainrulecheck.py new file mode 100644
index 0000000000..a24fb53766 --- /dev/null +++ b/tests/rulecheck/test_domainrulecheck.py
@@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 New Vector Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +from tests import unittest + +from synapse.config._base import ConfigError +from synapse.rulecheck.domain_rule_checker import DomainRuleChecker + + +class DomainRuleCheckerTestCase(unittest.TestCase): + + def test_allowed(self): + config = { + "default": False, + "domain_mapping": { + "source_one": ["target_one", "target_two"], + "source_two": ["target_two"] + } + } + check = DomainRuleChecker(config) + self.assertTrue(check.user_may_invite("test:source_one", + "test:target_one", "room")) + self.assertTrue(check.user_may_invite("test:source_one", + "test:target_two", "room")) + self.assertTrue(check.user_may_invite("test:source_two", + "test:target_two", "room")) + + def test_disallowed(self): + config = { + "default": True, + "domain_mapping": { + "source_one": ["target_one", "target_two"], + "source_two": ["target_two"], + "source_four": [] + } + } + check = DomainRuleChecker(config) + self.assertFalse(check.user_may_invite("test:source_one", + "test:target_three", "room")) + self.assertFalse(check.user_may_invite("test:source_two", + "test:target_three", "room")) + self.assertFalse(check.user_may_invite("test:source_two", + "test:target_one", "room")) + self.assertFalse(check.user_may_invite("test:source_four", + "test:target_one", "room")) + + def test_default_allow(self): + config = { + "default": True, + "domain_mapping": { + "source_one": ["target_one", "target_two"], + "source_two": ["target_two"] + } + } + check = DomainRuleChecker(config) + self.assertTrue(check.user_may_invite("test:source_three", + "test:target_one", "room")) + + def test_default_deny(self): + config = { + "default": False, + "domain_mapping": { + "source_one": ["target_one", "target_two"], + "source_two": ["target_two"] + } + } + check = DomainRuleChecker(config) + self.assertFalse(check.user_may_invite("test:source_three", + "test:target_one", "room")) + + def test_config_parse(self): + config = { + "default": False, + "domain_mapping": { + "source_one": ["target_one", "target_two"], + "source_two": ["target_two"] + } + } + self.assertEquals(config, DomainRuleChecker.parse_config(config)) + + def test_config_parse_failure(self): + config = { + "domain_mapping": { + "source_one": ["target_one", "target_two"], + "source_two": ["target_two"] + } + } + self.assertRaises(ConfigError, DomainRuleChecker.parse_config, config) diff --git a/tests/storage/test_profile.py b/tests/storage/test_profile.py
index 423710c9c1..d173195787 100644 --- a/tests/storage/test_profile.py +++ b/tests/storage/test_profile.py
@@ -35,12 +35,8 @@ class ProfileStoreTestCase(unittest.TestCase): @defer.inlineCallbacks def test_displayname(self): - yield self.store.create_profile( - self.u_frank.localpart - ) - yield self.store.set_profile_displayname( - self.u_frank.localpart, "Frank" + self.u_frank.localpart, "Frank", 1, ) self.assertEquals( @@ -50,12 +46,8 @@ class ProfileStoreTestCase(unittest.TestCase): @defer.inlineCallbacks def test_avatar_url(self): - yield self.store.create_profile( - self.u_frank.localpart - ) - yield self.store.set_profile_avatar_url( - self.u_frank.localpart, "http://my.site/here" + self.u_frank.localpart, "http://my.site/here", 1, ) self.assertEquals( diff --git a/tests/utils.py b/tests/utils.py
index 189fd2711c..9cc44a80aa 100644 --- a/tests/utils.py +++ b/tests/utils.py
@@ -67,6 +67,7 @@ def setup_test_homeserver(name="test", datastore=None, config=None, reactor=None config.federation_rc_concurrent = 10 config.filter_timeline_limit = 5000 config.user_directory_search_all_users = False + config.replicate_user_profiles_to = [] config.user_consent_server_notice_content = None config.block_events_without_consent_error = None