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

Support PyJWT v2.0.0. #8986

Merged
merged 1 commit into from
Dec 22, 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/8986.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support using PyJWT v2.0.0 in the test suite.
16 changes: 12 additions & 4 deletions tests/rest/client/v1/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,12 @@ def make_homeserver(self, reactor, clock):
self.hs.config.jwt_algorithm = self.jwt_algorithm
return self.hs

def jwt_encode(self, token, secret=jwt_secret):
return jwt.encode(token, secret, self.jwt_algorithm).decode("ascii")
def jwt_encode(self, token: str, secret: str = jwt_secret) -> str:
# PyJWT 2.0.0 changed the return type of jwt.encode from bytes to str.
result = jwt.encode(token, secret, self.jwt_algorithm)
if isinstance(result, bytes):
return result.decode("ascii")
return result

def jwt_login(self, *args):
params = json.dumps(
Expand Down Expand Up @@ -680,8 +684,12 @@ def make_homeserver(self, reactor, clock):
self.hs.config.jwt_algorithm = "RS256"
return self.hs

def jwt_encode(self, token, secret=jwt_privatekey):
return jwt.encode(token, secret, "RS256").decode("ascii")
def jwt_encode(self, token: str, secret: str = jwt_privatekey) -> str:
# PyJWT 2.0.0 changed the return type of jwt.encode from bytes to str.
result = jwt.encode(token, secret, "RS256")
if isinstance(result, bytes):
return result.decode("ascii")
return result

def jwt_login(self, *args):
params = json.dumps(
Expand Down