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/appservice | |
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/appservice')
-rw-r--r-- | synapse/appservice/__init__.py | 14 |
1 files changed, 12 insertions, 2 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 |