From 665dd9f7f8db2f8d38f454d4d5b96efcf163a5db Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Sep 2019 11:35:56 +0100 Subject: Ensure the password reset template is correctly converted to binary Regardless of the Python version --- synapse/rest/client/v2_alpha/account.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/synapse/rest/client/v2_alpha/account.py b/synapse/rest/client/v2_alpha/account.py index 32770a4a95..20e1e01592 100644 --- a/synapse/rest/client/v2_alpha/account.py +++ b/synapse/rest/client/v2_alpha/account.py @@ -17,6 +17,7 @@ import logging import re +from six import ensure_binary from six.moves import http_client import jinja2 @@ -295,7 +296,7 @@ class PasswordResetSubmitTokenServlet(RestServlet): ) request.setResponseCode(e.code) - request.write(html.encode('utf-8')) + request.write(ensure_binary(html)) finish_request(request) defer.returnValue(None) -- cgit 1.5.1 From a8c7c26e7d76fac9a7749a0b13c47cd32802b298 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Sep 2019 11:49:42 +0100 Subject: Changelog --- changelog.d/3.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/3.bugfix diff --git a/changelog.d/3.bugfix b/changelog.d/3.bugfix new file mode 100644 index 0000000000..cc4bcefa80 --- /dev/null +++ b/changelog.d/3.bugfix @@ -0,0 +1 @@ +Fix encoding on password reset HTML responses in Python 2. -- cgit 1.5.1 From 6ceaf90e13c019fc55db05f79f47922106d55d63 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Sep 2019 16:33:09 +0100 Subject: Revert "Ensure the password reset template is correctly converted to binary" This reverts commit 665dd9f7f8db2f8d38f454d4d5b96efcf163a5db. --- synapse/rest/client/v2_alpha/account.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/synapse/rest/client/v2_alpha/account.py b/synapse/rest/client/v2_alpha/account.py index 20e1e01592..32770a4a95 100644 --- a/synapse/rest/client/v2_alpha/account.py +++ b/synapse/rest/client/v2_alpha/account.py @@ -17,7 +17,6 @@ import logging import re -from six import ensure_binary from six.moves import http_client import jinja2 @@ -296,7 +295,7 @@ class PasswordResetSubmitTokenServlet(RestServlet): ) request.setResponseCode(e.code) - request.write(ensure_binary(html)) + request.write(html.encode('utf-8')) finish_request(request) defer.returnValue(None) -- cgit 1.5.1 From 21a6f0b12c3e0db147b73b26fa465460f46a3bd8 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Sep 2019 16:34:47 +0100 Subject: Read all files as UTF-8 --- synapse/config/_base.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/synapse/config/_base.py b/synapse/config/_base.py index f7d7f153bb..ae05667a40 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py @@ -15,6 +15,7 @@ import argparse import errno +from io import open import os from textwrap import dedent @@ -131,7 +132,7 @@ class Config(object): @classmethod def read_file(cls, file_path, config_name): cls.check_file(file_path, config_name) - with open(file_path) as file_stream: + with open(file_path, encoding="utf-8") as file_stream: return file_stream.read() @staticmethod -- cgit 1.5.1 From 76f70779f18a130d6ec4194dba8ae42eeaa5afaa Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Sep 2019 16:36:00 +0100 Subject: Revert "Merge pull request #5932 from matrix-org/babolivier/account_validity_template_encode" This reverts commit 84e695f506faf54982b9e19dceb9c02acffad95f, reversing changes made to 99eec6d2d5cc76e645c3fd7ca6cda85b2bab6feb. --- synapse/python_dependencies.py | 2 +- synapse/rest/client/v2_alpha/account_validity.py | 4 +--- tests/rest/client/v2_alpha/test_register.py | 5 ++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/synapse/python_dependencies.py b/synapse/python_dependencies.py index 9692f0bf75..7dfa78dadb 100644 --- a/synapse/python_dependencies.py +++ b/synapse/python_dependencies.py @@ -67,7 +67,7 @@ REQUIREMENTS = [ "pymacaroons>=0.13.0", "msgpack>=0.5.0", "phonenumbers>=8.2.0", - "six>=1.12", + "six>=1.10", # prometheus_client 0.4.0 changed the format of counter metrics # (cf https://github.com/matrix-org/synapse/issues/4001) "prometheus_client>=0.0.18,<0.4.0", diff --git a/synapse/rest/client/v2_alpha/account_validity.py b/synapse/rest/client/v2_alpha/account_validity.py index 98f7c60016..8091b78285 100644 --- a/synapse/rest/client/v2_alpha/account_validity.py +++ b/synapse/rest/client/v2_alpha/account_validity.py @@ -15,8 +15,6 @@ import logging -from six import ensure_binary - from twisted.internet import defer from synapse.api.errors import AuthError, SynapseError @@ -65,7 +63,7 @@ class AccountValidityRenewServlet(RestServlet): request.setResponseCode(status_code) request.setHeader(b"Content-Type", b"text/html; charset=utf-8") request.setHeader(b"Content-Length", b"%d" % (len(response),)) - request.write(ensure_binary(response)) + request.write(response.encode("utf8")) finish_request(request) defer.returnValue(None) diff --git a/tests/rest/client/v2_alpha/test_register.py b/tests/rest/client/v2_alpha/test_register.py index b28de3663c..af1e600591 100644 --- a/tests/rest/client/v2_alpha/test_register.py +++ b/tests/rest/client/v2_alpha/test_register.py @@ -20,7 +20,6 @@ import json import os from mock import Mock -from six import ensure_binary import pkg_resources @@ -438,7 +437,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase): # Check that the HTML we're getting is the one we expect on a successful renewal. expected_html = self.hs.config.account_validity.account_renewed_html_content self.assertEqual( - channel.result["body"], ensure_binary(expected_html), channel.result + channel.result["body"], expected_html.encode("utf8"), channel.result ) # Move 3 days forward. If the renewal failed, every authed request with @@ -468,7 +467,7 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase): # invalid/unknown token. expected_html = self.hs.config.account_validity.invalid_token_html_content self.assertEqual( - channel.result["body"], ensure_binary(expected_html), channel.result + channel.result["body"], expected_html.encode("utf8"), channel.result ) def test_manual_email_send(self): -- cgit 1.5.1 From b0eec085bd518e76cf96b84f98e90860dca1a5c7 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Sep 2019 16:41:46 +0100 Subject: Lint --- synapse/config/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/config/_base.py b/synapse/config/_base.py index ae05667a40..71a81c1cc9 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py @@ -15,8 +15,8 @@ import argparse import errno -from io import open import os +from io import open from textwrap import dedent from six import integer_types -- cgit 1.5.1 From c8f03a8fb0160956c5c593f63641e9a522ee2b8e Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 9 Sep 2019 17:13:37 +0100 Subject: Rename io.open import to limite side-effects --- synapse/config/_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/config/_base.py b/synapse/config/_base.py index 71a81c1cc9..bf039e5823 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py @@ -16,7 +16,7 @@ import argparse import errno import os -from io import open +from io import open as io_open from textwrap import dedent from six import integer_types @@ -132,7 +132,7 @@ class Config(object): @classmethod def read_file(cls, file_path, config_name): cls.check_file(file_path, config_name) - with open(file_path, encoding="utf-8") as file_stream: + with io_open(file_path, encoding="utf-8") as file_stream: return file_stream.read() @staticmethod -- cgit 1.5.1