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.
This commit is contained in:
Patrick Cloke 2020-12-22 13:00:14 -05:00 committed by GitHub
parent 4218473f9e
commit a802606475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

1
changelog.d/8986.misc Normal file
View File

@ -0,0 +1 @@
Support using PyJWT v2.0.0 in the test suite.

View File

@ -475,8 +475,12 @@ class JWTTestCase(unittest.HomeserverTestCase):
self.hs.config.jwt_algorithm = self.jwt_algorithm self.hs.config.jwt_algorithm = self.jwt_algorithm
return self.hs return self.hs
def jwt_encode(self, token, secret=jwt_secret): def jwt_encode(self, token: str, secret: str = jwt_secret) -> str:
return jwt.encode(token, secret, self.jwt_algorithm).decode("ascii") # 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): def jwt_login(self, *args):
params = json.dumps( params = json.dumps(
@ -680,8 +684,12 @@ class JWTPubKeyTestCase(unittest.HomeserverTestCase):
self.hs.config.jwt_algorithm = "RS256" self.hs.config.jwt_algorithm = "RS256"
return self.hs return self.hs
def jwt_encode(self, token, secret=jwt_privatekey): def jwt_encode(self, token: str, secret: str = jwt_privatekey) -> str:
return jwt.encode(token, secret, "RS256").decode("ascii") # 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): def jwt_login(self, *args):
params = json.dumps( params = json.dumps(