diff options
author | Kegan Dougal <kegan@matrix.org> | 2015-02-04 12:24:20 +0000 |
---|---|---|
committer | Kegan Dougal <kegan@matrix.org> | 2015-02-04 12:24:20 +0000 |
commit | 525a218b2b072b24721c9c9efae42aae21388fc8 (patch) | |
tree | cff1cb05b2c12902ba7ac778ac40d3f79dbd3d1e /synapse | |
parent | Add stub ApplicationServiceApi and glue it with the handler. (diff) | |
download | synapse-525a218b2b072b24721c9c9efae42aae21388fc8.tar.xz |
Begin to add unit tests for appservice glue and regex testing.
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/appservice/__init__.py | 14 | ||||
-rw-r--r-- | synapse/handlers/appservice.py | 8 |
2 files changed, 18 insertions, 4 deletions
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 |