summary refs log tree commit diff
diff options
context:
space:
mode:
authorWill Hunt <will@half-shot.uk>2018-06-27 17:11:13 +0100
committerWill Hunt <will@half-shot.uk>2018-06-27 17:11:13 +0100
commit212d4abeab1d254ab4c2041ed6c9dd01f97b9a72 (patch)
tree3fbe26c0bd889ffeb8611c6f94c56094a0a648e8
parentevent.event_id => event.sender (diff)
downloadsynapse-hs/as-server-banlist.tar.xz
-rw-r--r--synapse/handlers/appservice.py12
-rw-r--r--tests/handlers/test_appservice.py34
2 files changed, 40 insertions, 6 deletions
diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py
index ad827a3416..4f05eba798 100644
--- a/synapse/handlers/appservice.py
+++ b/synapse/handlers/appservice.py
@@ -99,12 +99,12 @@ class ApplicationServicesHandler(object):
                         ev_domain = get_domain_from_id(event.sender)
                         if any(srv_re.match(ev_domain) is not None
                            for srv_re in self.server_blacklist):
-                            logger.info(
-                                "Ignoring %s from %s, matches server blacklist",
-                                event.sender,
-                                ev_domain
-                            )
-                            return
+                                logger.info(
+                                    "Ignoring %s from %s, matches server blacklist",
+                                    event.sender,
+                                    ev_domain
+                                )
+                                return
                         # Gather interested services
                         services = yield self._get_services_for_event(event)
                         if len(services) == 0:
diff --git a/tests/handlers/test_appservice.py b/tests/handlers/test_appservice.py
index b753455943..c265b95ef6 100644
--- a/tests/handlers/test_appservice.py
+++ b/tests/handlers/test_appservice.py
@@ -20,6 +20,7 @@ from tests.utils import MockClock
 from synapse.handlers.appservice import ApplicationServicesHandler
 
 from mock import Mock
+import re
 
 
 class AppServiceHandlerTestCase(unittest.TestCase):
@@ -32,9 +33,14 @@ class AppServiceHandlerTestCase(unittest.TestCase):
         hs = Mock()
         hs.get_datastore = Mock(return_value=self.mock_store)
         self.mock_store.get_received_ts.return_value = 0
+        self.mock_store.app_service_server_blacklist = []
         hs.get_application_service_api = Mock(return_value=self.mock_as_api)
         hs.get_application_service_scheduler = Mock(return_value=self.mock_scheduler)
         hs.get_clock.return_value = MockClock()
+        hs.config.app_service_server_blacklist = [
+            re.compile("evilplaceofevil"),
+            re.compile("bad.placeof..*")
+        ]
         self.handler = ApplicationServicesHandler(hs)
 
     @defer.inlineCallbacks
@@ -65,6 +71,34 @@ class AppServiceHandlerTestCase(unittest.TestCase):
         )
 
     @defer.inlineCallbacks
+    def test_ignore_blacklisted_services(self):
+        interested_service = self._mkservice(is_interested=True)
+        services = [
+            interested_service,
+        ]
+
+        self.mock_store.get_app_services = Mock(return_value=services)
+        self.mock_store.get_user_by_id = Mock(return_value=[])
+
+        eventLiteral = Mock(
+            sender="@someone:evilplaceofevil",
+            type="m.room.message",
+            room_id="!foo:bar"
+        )
+        eventMatched = Mock(
+            sender="@someone:bad.placeof.bad",
+            type="m.room.message",
+            room_id="!foo:bar"
+        )
+        self.mock_store.get_new_events_for_appservice.side_effect = [
+            (0, [eventLiteral]),
+            (0, [eventMatched])
+        ]
+        self.mock_as_api.push = Mock()
+        yield self.handler.notify_interested_services(0)
+        assert self.mock_scheduler.submit_event_for_as.called is False
+
+    @defer.inlineCallbacks
     def test_query_user_exists_unknown_user(self):
         user_id = "@someone:anywhere"
         services = [self._mkservice(is_interested=True)]