summary refs log tree commit diff
path: root/synapse/appservice/api.py
diff options
context:
space:
mode:
authorPaul Evans <leonerd@leonerd.org.uk>2016-09-09 15:43:11 +0100
committerGitHub <noreply@github.com>2016-09-09 15:43:11 +0100
commit56f38d177694ca858594597a03567b7964ac44d8 (patch)
treec3239f27a6551f388a5e1211854d52edeee5071f /synapse/appservice/api.py
parentMerge pull request #1094 from matrix-org/paul/get-state-whole-event (diff)
parentLog if rejecting 3PE query metadata result due to type check (diff)
downloadsynapse-56f38d177694ca858594597a03567b7964ac44d8.tar.xz
Merge pull request #1091 from matrix-org/paul/third-party-lookup
Improvements to 3PE lookup API
Diffstat (limited to 'synapse/appservice/api.py')
-rw-r--r--synapse/appservice/api.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py
index cc4af23962..b0eb0c6d9d 100644
--- a/synapse/appservice/api.py
+++ b/synapse/appservice/api.py
@@ -32,6 +32,14 @@ HOUR_IN_MS = 60 * 60 * 1000
 APP_SERVICE_PREFIX = "/_matrix/app/unstable"
 
 
+def _is_valid_3pe_metadata(info):
+    if "instances" not in info:
+        return False
+    if not isinstance(info["instances"], list):
+        return False
+    return True
+
+
 def _is_valid_3pe_result(r, field):
     if not isinstance(r, dict):
         return False
@@ -162,11 +170,18 @@ class ApplicationServiceApi(SimpleHttpClient):
                 urllib.quote(protocol)
             )
             try:
-                defer.returnValue((yield self.get_json(uri, {})))
+                info = yield self.get_json(uri, {})
+
+                if not _is_valid_3pe_metadata(info):
+                    logger.warning("query_3pe_protocol to %s did not return a"
+                                   " valid result", uri)
+                    defer.returnValue(None)
+
+                defer.returnValue(info)
             except Exception as ex:
                 logger.warning("query_3pe_protocol to %s threw exception %s",
                                uri, ex)
-                defer.returnValue({})
+                defer.returnValue(None)
 
         key = (service.id, protocol)
         return self.protocol_meta_cache.get(key) or (