From d94590ed4855691e54655396e45e3e275f9c1860 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Fri, 29 May 2015 12:11:40 +0100 Subject: [PATCH 1/5] Add config for setting the recaptcha verify api endpoint, so we can test it in sytest --- synapse/config/captcha.py | 4 ++++ synapse/handlers/auth.py | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/synapse/config/captcha.py b/synapse/config/captcha.py index d8fe577e34..ba221121cb 100644 --- a/synapse/config/captcha.py +++ b/synapse/config/captcha.py @@ -26,6 +26,7 @@ class CaptchaConfig(Config): config["captcha_ip_origin_is_x_forwarded"] ) self.captcha_bypass_secret = config.get("captcha_bypass_secret") + self.recaptcha_siteverify_api = config["recaptcha_siteverify_api"] def default_config(self, config_dir_path, server_name): return """\ @@ -48,4 +49,7 @@ class CaptchaConfig(Config): # A secret key used to bypass the captcha test entirely. #captcha_bypass_secret: "YOUR_SECRET_HERE" + + # The API endpoint to use for verifying m.login.recaptcha responses. + recaptcha_siteverify_api: "https://www.google.com/recaptcha/api/siteverify" """ diff --git a/synapse/handlers/auth.py b/synapse/handlers/auth.py index 4e2e50345e..4b442a8358 100644 --- a/synapse/handlers/auth.py +++ b/synapse/handlers/auth.py @@ -187,8 +187,8 @@ class AuthHandler(BaseHandler): # each request try: client = SimpleHttpClient(self.hs) - data = yield client.post_urlencoded_get_json( - "https://www.google.com/recaptcha/api/siteverify", + resp_body = yield client.post_urlencoded_get_json( + self.hs.config.recaptcha_siteverify_api, args={ 'secret': self.hs.config.recaptcha_private_key, 'response': user_response, @@ -198,7 +198,7 @@ class AuthHandler(BaseHandler): except PartialDownloadError as pde: # Twisted is silly data = pde.response - resp_body = simplejson.loads(data) + resp_body = simplejson.loads(data) if 'success' in resp_body and resp_body['success']: defer.returnValue(True) raise LoginError(401, "", errcode=Codes.UNAUTHORIZED) From ca580ef862fe1c21bf191f8066df90f78171d11f Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 29 May 2015 15:02:55 +0100 Subject: [PATCH 2/5] Don't copy twice --- synapse/events/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/events/__init__.py b/synapse/events/__init__.py index b2a904b408..39ce4f7c42 100644 --- a/synapse/events/__init__.py +++ b/synapse/events/__init__.py @@ -131,7 +131,7 @@ class FrozenEvent(EventBase): if USE_FROZEN_DICTS: frozen_dict = freeze(event_dict) else: - frozen_dict = dict(event_dict) + frozen_dict = event_dict super(FrozenEvent, self).__init__( frozen_dict, From d15f166093c121d93b8d0bcb53e55e1369b4ea84 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 29 May 2015 15:03:24 +0100 Subject: [PATCH 3/5] Remove log line --- synapse/http/server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/synapse/http/server.py b/synapse/http/server.py index cdb9f9cefc..ae8f3b3972 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py @@ -290,7 +290,6 @@ def respond_with_json(request, code, json_object, send_cors=False, json_bytes = encode_json( json_object, using_frozen_dicts=synapse.events.USE_FROZEN_DICTS ) - logger.debug("json_bytes: %r %r", json_object, json_bytes) return respond_with_json_bytes( request, code, json_bytes, From 53ef3a0bfebae941cf320ceee56499faafd3f31c Mon Sep 17 00:00:00 2001 From: Ivan Shapovalov Date: Sun, 31 May 2015 19:21:55 +0300 Subject: [PATCH 4/5] contrib/systemd: log_config.yaml: do not disable existing loggers It turned out that merely configuring the root logger is not enough for "catch-all" semantics. The logging subsystem also needs to be told not to disable existing loggers (so that their messages will get propagated to handlers up the logging hierarchy, not just silently discarded). Signed-off-by: Ivan Shapovalov --- contrib/systemd/log_config.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/systemd/log_config.yaml b/contrib/systemd/log_config.yaml index e16fb5456a..d85bdd1208 100644 --- a/contrib/systemd/log_config.yaml +++ b/contrib/systemd/log_config.yaml @@ -21,3 +21,5 @@ handlers: root: level: INFO handlers: [journal] + +disable_existing_loggers: False From 689b4de31454bd1496c6216d9a82c134bc87abd4 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 1 Jun 2015 14:55:02 +0100 Subject: [PATCH 5/5] Also cache user_id -> UserID conversion --- synapse/handlers/room.py | 4 +--- synapse/storage/events.py | 1 + synapse/storage/roommember.py | 7 +++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 4bd027d9bb..31efba0a9c 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -254,9 +254,7 @@ class RoomMemberHandler(BaseHandler): @defer.inlineCallbacks def get_room_members(self, room_id): - users = yield self.store.get_users_in_room(room_id) - - defer.returnValue([UserID.from_string(u) for u in users]) + return self.store.get_user_objs_in_room(room_id) @defer.inlineCallbacks def fetch_room_distributions_into(self, room_id, localusers=None, diff --git a/synapse/storage/events.py b/synapse/storage/events.py index 20a8d81794..79cb52beb0 100644 --- a/synapse/storage/events.py +++ b/synapse/storage/events.py @@ -128,6 +128,7 @@ class EventsStore(SQLBaseStore): txn.call_after(self.get_current_state_for_key.invalidate_all) txn.call_after(self.get_rooms_for_user.invalidate_all) txn.call_after(self.get_users_in_room.invalidate, event.room_id) + txn.call_after(self.get_user_objs_in_room.invalidate, event.room_id) txn.call_after(self.get_joined_hosts_for_room.invalidate, event.room_id) txn.call_after(self.get_room_name_and_aliases, event.room_id) diff --git a/synapse/storage/roommember.py b/synapse/storage/roommember.py index d36a6c18a8..2c879d56d6 100644 --- a/synapse/storage/roommember.py +++ b/synapse/storage/roommember.py @@ -67,6 +67,7 @@ class RoomMemberStore(SQLBaseStore): txn.call_after(self.get_rooms_for_user.invalidate, target_user_id) txn.call_after(self.get_joined_hosts_for_room.invalidate, event.room_id) txn.call_after(self.get_users_in_room.invalidate, event.room_id) + txn.call_after(self.get_user_objs_in_room.invalidate, event.room_id) def get_room_member(self, user_id, room_id): """Retrieve the current state of a room member. @@ -101,6 +102,12 @@ class RoomMemberStore(SQLBaseStore): return [r["user_id"] for r in rows] return self.runInteraction("get_users_in_room", f) + @cached() + def get_user_objs_in_room(self, room_id): + return self.get_users_in_room(room_id).addCallback( + lambda users: [UserID.from_string(u) for u in users] + ) + def get_room_members(self, room_id, membership=None): """Retrieve the current room member list for a room.