summary refs log tree commit diff
path: root/tests/handlers
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-06-17 17:26:03 +0100
committerKegan Dougal <kegan@matrix.org>2015-06-17 17:26:03 +0100
commitd88e20cdb988a44155ef087ef28cd37c982cfe5d (patch)
tree46e276f7db348e2a186943a94e733880384d620c /tests/handlers
parentCorrect -H SERVER_NAME in config-missing complaint message (diff)
downloadsynapse-d88e20cdb988a44155ef087ef28cd37c982cfe5d.tar.xz
Fix bug where synapse was sending AS user queries incorrectly.
Bug introduced in 92b20713d7c6346aeb20dc09963081e472752bb5
which reversed the comparison when checking if a user existed
in the users table. Added UTs to prevent this happening again.
Diffstat (limited to 'tests/handlers')
-rw-r--r--tests/handlers/test_appservice.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/handlers/test_appservice.py b/tests/handlers/test_appservice.py
index 06cb1dd4cf..9e95d1e532 100644
--- a/tests/handlers/test_appservice.py
+++ b/tests/handlers/test_appservice.py
@@ -58,6 +58,49 @@ class AppServiceHandlerTestCase(unittest.TestCase):
         )
 
     @defer.inlineCallbacks
+    def test_query_user_exists_unknown_user(self):
+        user_id = "@someone:anywhere"
+        services = [self._mkservice(is_interested=True)]
+        services[0].is_interested_in_user = Mock(return_value=True)
+        self.mock_store.get_app_services = Mock(return_value=services)
+        self.mock_store.get_user_by_id = Mock(return_value=None)
+
+        event = Mock(
+            sender=user_id,
+            type="m.room.message",
+            room_id="!foo:bar"
+        )
+        self.mock_as_api.push = Mock()
+        self.mock_as_api.query_user = Mock()
+        yield self.handler.notify_interested_services(event)
+        self.mock_as_api.query_user.assert_called_once_with(
+            services[0], user_id
+        )
+
+    @defer.inlineCallbacks
+    def test_query_user_exists_known_user(self):
+        user_id = "@someone:anywhere"
+        services = [self._mkservice(is_interested=True)]
+        services[0].is_interested_in_user = Mock(return_value=True)
+        self.mock_store.get_app_services = Mock(return_value=services)
+        self.mock_store.get_user_by_id = Mock(return_value={
+            "name": user_id
+        })
+
+        event = Mock(
+            sender=user_id,
+            type="m.room.message",
+            room_id="!foo:bar"
+        )
+        self.mock_as_api.push = Mock()
+        self.mock_as_api.query_user = Mock()
+        yield self.handler.notify_interested_services(event)
+        self.assertFalse(
+            self.mock_as_api.query_user.called,
+            "query_user called when it shouldn't have been."
+        )
+
+    @defer.inlineCallbacks
     def test_query_room_alias_exists(self):
         room_alias_str = "#foo:bar"
         room_alias = Mock()