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

Stop passing bytes when dumping JSON #7799

Merged
merged 3 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7799.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure that strings (not bytes) are passed into JSON serialization.
4 changes: 2 additions & 2 deletions synapse/handlers/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ async def try_unbind_threepid_with_id_server(self, mxid, threepid, id_server):
# 'browser-like' HTTPS.
auth_headers = self.federation_http_client.build_auth_headers(
destination=None,
method="POST",
method=b"POST",
url_bytes=url_bytes,
content=content,
destination_is=id_server,
destination_is=id_server.encode("ascii"),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means we're not going str -> bytes -> str, but at least we abide by the interfaces now.

)
headers = {b"Authorization": auth_headers}

Expand Down
10 changes: 7 additions & 3 deletions synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,17 @@ def build_auth_headers(
Returns:
list[bytes]: a list of headers to be added as "Authorization:" headers
"""
request = {"method": method, "uri": url_bytes, "origin": self.server_name}
request = {
"method": method.decode("ascii"),
"uri": url_bytes.decode("ascii"),
"origin": self.server_name,
}

if destination is not None:
request["destination"] = destination
request["destination"] = destination.decode("ascii")

if destination_is is not None:
request["destination_is"] = destination_is
request["destination_is"] = destination_is.decode("ascii")

if content is not None:
request["content"] = content
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/v1/voip.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def on_GET(self, request):
# We need to use standard padded base64 encoding here
# encode_base64 because we need to add the standard padding to get the
# same result as the TURN server.
password = base64.b64encode(mac.digest())
password = base64.b64encode(mac.digest()).decode("ascii")

elif turnUris and turnUsername and turnPassword and userLifetime:
username = turnUsername
Expand Down