Skip to content

Commit

Permalink
Allow cookie authentication to work with Python 3.5
Browse files Browse the repository at this point in the history
The json module started understanding bytes in Python 3.6 (with an
heuristic on which Unicode encoding the bytes are using).

We don't ufficially support Python 3.5, but since it's an easy fix and
we know better than the heuristic the encoding (UTF-8, since
everything is ASCII, really), let's decode explicitly.
  • Loading branch information
stefano-maggiolo committed Oct 2, 2018
1 parent 3401a2a commit 69f33ee
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cms/server/contest/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def log_failed_attempt(msg, *args):
timestamp)

return (participation,
json.dumps([username, password, make_timestamp(timestamp)]))
json.dumps([username, password, make_timestamp(timestamp)])
.encode("utf-8"))


class AmbiguousIPAddress(Exception):
Expand Down Expand Up @@ -316,7 +317,7 @@ def _authenticate_request_from_cookie(sql_session, contest, timestamp, cookie):

# Parse cookie.
try:
cookie = json.loads(cookie)
cookie = json.loads(cookie.decode("utf-8"))
username = cookie[0]
password = cookie[1]
last_update = make_datetime(cookie[2])
Expand Down Expand Up @@ -357,4 +358,5 @@ def log_failed_attempt(msg, *args):
timestamp)

return (participation,
json.dumps([username, password, make_timestamp(timestamp)]))
json.dumps([username, password, make_timestamp(timestamp)])
.encode("utf-8"))

0 comments on commit 69f33ee

Please sign in to comment.