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

Commit 84e695f

Browse files
authored
Merge pull request #5932 from matrix-org/babolivier/account_validity_template_encode
Fix encoding for account validity HTML files on Python 2
2 parents 99eec6d + 9169422 commit 84e695f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

synapse/python_dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"pymacaroons>=0.13.0",
6868
"msgpack>=0.5.0",
6969
"phonenumbers>=8.2.0",
70-
"six>=1.10",
70+
"six>=1.12",
7171
# prometheus_client 0.4.0 changed the format of counter metrics
7272
# (cf https://github.com/matrix-org/synapse/issues/4001)
7373
"prometheus_client>=0.0.18,<0.4.0",

synapse/rest/client/v2_alpha/account_validity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import logging
1717

18+
from six import ensure_binary
19+
1820
from twisted.internet import defer
1921

2022
from synapse.api.errors import AuthError, SynapseError
@@ -63,7 +65,7 @@ def on_GET(self, request):
6365
request.setResponseCode(status_code)
6466
request.setHeader(b"Content-Type", b"text/html; charset=utf-8")
6567
request.setHeader(b"Content-Length", b"%d" % (len(response),))
66-
request.write(response.encode("utf8"))
68+
request.write(ensure_binary(response))
6769
finish_request(request)
6870
defer.returnValue(None)
6971

tests/rest/client/v2_alpha/test_register.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import os
2121

2222
from mock import Mock
23+
from six import ensure_binary
2324

2425
import pkg_resources
2526

@@ -437,7 +438,7 @@ def test_renewal_email(self):
437438
# Check that the HTML we're getting is the one we expect on a successful renewal.
438439
expected_html = self.hs.config.account_validity.account_renewed_html_content
439440
self.assertEqual(
440-
channel.result["body"], expected_html.encode("utf8"), channel.result
441+
channel.result["body"], ensure_binary(expected_html), channel.result
441442
)
442443

443444
# Move 3 days forward. If the renewal failed, every authed request with
@@ -467,7 +468,7 @@ def test_renewal_invalid_token(self):
467468
# invalid/unknown token.
468469
expected_html = self.hs.config.account_validity.invalid_token_html_content
469470
self.assertEqual(
470-
channel.result["body"], expected_html.encode("utf8"), channel.result
471+
channel.result["body"], ensure_binary(expected_html), channel.result
471472
)
472473

473474
def test_manual_email_send(self):

0 commit comments

Comments
 (0)