Browse Source

small fixes and remove unnecessary Enum

Andrew Morgan 4 years ago
parent
commit
e68d648594
2 changed files with 18 additions and 23 deletions
  1. 1 2
      synapse/handlers/identity.py
  2. 17 21
      synapse/handlers/room_member.py

+ 1 - 2
synapse/handlers/identity.py

@@ -18,7 +18,6 @@
 """Utilities for interacting with Identity Servers"""
 """Utilities for interacting with Identity Servers"""
 
 
 import logging
 import logging
-from enum import Enum
 
 
 from canonicaljson import json
 from canonicaljson import json
 
 
@@ -285,7 +284,7 @@ class IdentityHandler(BaseHandler):
             raise e.to_synapse_error()
             raise e.to_synapse_error()
 
 
 
 
-class LookupAlgorithm(Enum):
+class LookupAlgorithm:
     """
     """
     Supported hashing algorithms when performing a 3PID lookup.
     Supported hashing algorithms when performing a 3PID lookup.
 
 

+ 17 - 21
synapse/handlers/room_member.py

@@ -525,7 +525,7 @@ class RoomMemberHandler(object):
             event (SynapseEvent): The membership event.
             event (SynapseEvent): The membership event.
             context: The context of the event.
             context: The context of the event.
             is_guest (bool): Whether the sender is a guest.
             is_guest (bool): Whether the sender is a guest.
-            room_hosts ([str]): Homeservers which are likely to already be in
+            remote_room_hosts ([str]): Homeservers which are likely to already be in
                 the room, and could be danced with in order to join this
                 the room, and could be danced with in order to join this
                 homeserver for the first time.
                 homeserver for the first time.
             ratelimit (bool): Whether to rate limit this request.
             ratelimit (bool): Whether to rate limit this request.
@@ -636,7 +636,7 @@ class RoomMemberHandler(object):
             servers.remove(room_alias.domain)
             servers.remove(room_alias.domain)
         servers.insert(0, room_alias.domain)
         servers.insert(0, room_alias.domain)
 
 
-        return (RoomID.from_string(room_id), servers)
+        return RoomID.from_string(room_id), servers
 
 
     @defer.inlineCallbacks
     @defer.inlineCallbacks
     def _get_inviter(self, user_id, room_id):
     def _get_inviter(self, user_id, room_id):
@@ -702,6 +702,7 @@ class RoomMemberHandler(object):
 
 
         # Check what hashing details are supported by this identity server
         # Check what hashing details are supported by this identity server
         use_v1 = False
         use_v1 = False
+        hash_details = None
         try:
         try:
             hash_details = yield self.simple_http_client.get_json(
             hash_details = yield self.simple_http_client.get_json(
                 "%s%s/_matrix/identity/v2/hash_details" % (id_server_scheme, id_server)
                 "%s%s/_matrix/identity/v2/hash_details" % (id_server_scheme, id_server)
@@ -714,15 +715,14 @@ class RoomMemberHandler(object):
             if e.code == 404:
             if e.code == 404:
                 # This is an old identity server that does not yet support v2 lookups
                 # This is an old identity server that does not yet support v2 lookups
                 use_v1 = True
                 use_v1 = True
-
-            logger.warn("Error when looking up hashing details: %s" % (e,))
-            return None
+            else:
+                logger.warn("Error when looking up hashing details: %s" % (e,))
+                return None
 
 
         if use_v1:
         if use_v1:
-            return self._lookup_3pid_v1(id_server, medium, address)
+            return (yield self._lookup_3pid_v1(id_server, medium, address))
 
 
-        res = yield self._lookup_3pid_v2(id_server, medium, address, hash_details)
-        return res
+        return (yield self._lookup_3pid_v2(id_server, medium, address, hash_details))
 
 
     @defer.inlineCallbacks
     @defer.inlineCallbacks
     def _lookup_3pid_v1(self, id_server, medium, address):
     def _lookup_3pid_v1(self, id_server, medium, address):
@@ -763,18 +763,18 @@ class RoomMemberHandler(object):
                 of the identity server to use.
                 of the identity server to use.
             medium (str): The type of the third party identifier (e.g. "email").
             medium (str): The type of the third party identifier (e.g. "email").
             address (str): The third party identifier (e.g. "foo@example.com").
             address (str): The third party identifier (e.g. "foo@example.com").
-            hash_details (dict[str, str]): A dictionary containing hashing information
+            hash_details (dict[str, str|list]): A dictionary containing hashing information
                 provided by an identity server.
                 provided by an identity server.
 
 
         Returns:
         Returns:
-            str: the matrix ID of the 3pid, or None if it is not recognized.
+            str: the matrix ID of the 3pid, or None if it is not recognised.
         """
         """
         # Extract information from hash_details
         # Extract information from hash_details
         supported_lookup_algorithms = hash_details["algorithms"]
         supported_lookup_algorithms = hash_details["algorithms"]
         lookup_pepper = hash_details["lookup_pepper"]
         lookup_pepper = hash_details["lookup_pepper"]
 
 
         # Check if any of the supported lookup algorithms are present
         # Check if any of the supported lookup algorithms are present
-        if LookupAlgorithm.SHA256 in supported_lookup_algorithms:
+        if str(LookupAlgorithm.SHA256) in supported_lookup_algorithms:
             # Perform a hashed lookup
             # Perform a hashed lookup
             lookup_algorithm = LookupAlgorithm.SHA256
             lookup_algorithm = LookupAlgorithm.SHA256
 
 
@@ -782,7 +782,7 @@ class RoomMemberHandler(object):
             to_hash = "%s %s %s" % (address, medium, lookup_pepper)
             to_hash = "%s %s %s" % (address, medium, lookup_pepper)
             lookup_value = sha256_and_url_safe_base64(to_hash)
             lookup_value = sha256_and_url_safe_base64(to_hash)
 
 
-        elif LookupAlgorithm.NONE in supported_lookup_algorithms:
+        elif str(LookupAlgorithm.NONE) in supported_lookup_algorithms:
             # Perform a non-hashed lookup
             # Perform a non-hashed lookup
             lookup_algorithm = LookupAlgorithm.NONE
             lookup_algorithm = LookupAlgorithm.NONE
 
 
@@ -791,7 +791,7 @@ class RoomMemberHandler(object):
 
 
         else:
         else:
             logger.warn(
             logger.warn(
-                "No supported lookup algorithms provided by %s%s: %s",
+                "None of the provided lookup algorithms of %s%s are supported: %s",
                 id_server_scheme,
                 id_server_scheme,
                 id_server,
                 id_server,
                 hash_details["algorithms"],
                 hash_details["algorithms"],
@@ -821,7 +821,8 @@ class RoomMemberHandler(object):
             return None
             return None
 
 
         # Return the MXID if it's available, or None otherwise
         # Return the MXID if it's available, or None otherwise
-        return lookup_results["mappings"].get(lookup_value)
+        mxid = lookup_results["mappings"].get(lookup_value)
+        return mxid
 
 
     @defer.inlineCallbacks
     @defer.inlineCallbacks
     def _verify_any_signature(self, data, server_hostname):
     def _verify_any_signature(self, data, server_hostname):
@@ -1072,9 +1073,7 @@ class RoomMemberMasterHandler(RoomMemberHandler):
         )
         )
 
 
         if complexity:
         if complexity:
-            if complexity["v1"] > max_complexity:
-                return True
-            return False
+            return complexity["v1"] > max_complexity
         return None
         return None
 
 
     @defer.inlineCallbacks
     @defer.inlineCallbacks
@@ -1090,10 +1089,7 @@ class RoomMemberMasterHandler(RoomMemberHandler):
         max_complexity = self.hs.config.limit_remote_rooms.complexity
         max_complexity = self.hs.config.limit_remote_rooms.complexity
         complexity = yield self.store.get_room_complexity(room_id)
         complexity = yield self.store.get_room_complexity(room_id)
 
 
-        if complexity["v1"] > max_complexity:
-            return True
-
-        return False
+        return complexity["v1"] > max_complexity
 
 
     @defer.inlineCallbacks
     @defer.inlineCallbacks
     def _remote_join(self, requester, remote_room_hosts, room_id, user, content):
     def _remote_join(self, requester, remote_room_hosts, room_id, user, content):