Skip to content
Snippets Groups Projects
Unverified Commit a8026064 authored by Patrick Cloke's avatar Patrick Cloke Committed by GitHub
Browse files

Support PyJWT v2.0.0. (#8986)

Tests were broken due to an API changing. The code used in Synapse
proper should be compatible with both versions already.
parent 4218473f
No related branches found
No related tags found
No related merge requests found
Support using PyJWT v2.0.0 in the test suite.
......@@ -475,8 +475,12 @@ class JWTTestCase(unittest.HomeserverTestCase):
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(
......@@ -680,8 +684,12 @@ class JWTPubKeyTestCase(unittest.HomeserverTestCase):
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(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment