Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from matrix-org/babolivier/password-reset-templ…
Browse files Browse the repository at this point in the history
…ate-unicode

Ensure the password reset template is correctly converted to binary
  • Loading branch information
babolivier committed Sep 9, 2019
2 parents e9f2925 + c8f03a8 commit 43c1a10
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/3.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix encoding on password reset HTML responses in Python 2.
3 changes: 2 additions & 1 deletion synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import argparse
import errno
import os
from io import open as io_open
from textwrap import dedent

from six import integer_types
Expand Down Expand Up @@ -131,7 +132,7 @@ def ensure_directory(cls, dir_path):
@classmethod
def read_file(cls, file_path, config_name):
cls.check_file(file_path, config_name)
with open(file_path) as file_stream:
with io_open(file_path, encoding="utf-8") as file_stream:
return file_stream.read()

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion synapse/python_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"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",
Expand Down
4 changes: 1 addition & 3 deletions synapse/rest/client/v2_alpha/account_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import logging

from six import ensure_binary

from twisted.internet import defer

from synapse.api.errors import AuthError, SynapseError
Expand Down Expand Up @@ -65,7 +63,7 @@ def on_GET(self, request):
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)

Expand Down
5 changes: 2 additions & 3 deletions tests/rest/client/v2_alpha/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import os

from mock import Mock
from six import ensure_binary

import pkg_resources

Expand Down Expand Up @@ -438,7 +437,7 @@ def test_renewal_email(self):
# 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
Expand Down Expand Up @@ -468,7 +467,7 @@ def test_renewal_invalid_token(self):
# 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):
Expand Down

0 comments on commit 43c1a10

Please sign in to comment.