diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py
index 92f64619c9..0c7f58574e 100644
--- a/synapse/appservice/__init__.py
+++ b/synapse/appservice/__init__.py
@@ -14,8 +14,11 @@
# limitations under the License.
from synapse.api.constants import EventTypes
+import logging
import re
+logger = logging.getLogger(__name__)
+
class ApplicationService(object):
"""Defines an application service. This definition is mostly what is
@@ -56,15 +59,22 @@ class ApplicationService(object):
return namespaces
def _matches_regex(self, test_string, namespace_key):
+ if not isinstance(test_string, basestring):
+ logger.warning(
+ "Expected a string to test regex against, but got %s",
+ test_string
+ )
+ return False
+
for regex in self.namespaces[namespace_key]:
if re.match(regex, test_string):
return True
return False
def _matches_user(self, event):
- if (hasattr(event, "user_id") and
+ if (hasattr(event, "sender") and
self._matches_regex(
- event.user_id, ApplicationService.NS_USERS)):
+ event.sender, ApplicationService.NS_USERS)):
return True
# also check m.room.member state key
if (hasattr(event, "type") and event.type == EventTypes.Member
diff --git a/synapse/handlers/appservice.py b/synapse/handlers/appservice.py
index 9cdeaa2d94..3188c60f3d 100644
--- a/synapse/handlers/appservice.py
+++ b/synapse/handlers/appservice.py
@@ -26,10 +26,14 @@ import logging
logger = logging.getLogger(__name__)
-class ApplicationServicesHandler(BaseHandler):
+# NB: Purposefully not inheriting BaseHandler since that contains way too much
+# setup code which this handler does not need or use. This makes testing a lot
+# easier.
+class ApplicationServicesHandler(object):
def __init__(self, hs):
- super(ApplicationServicesHandler, self).__init__(hs)
+ self.store = hs.get_datastore()
+ self.hs = hs
self.appservice_api = ApplicationServiceApi(hs)
@defer.inlineCallbacks
|