test: add comprehensive unit tests for PassportService with exception handling optimization (#22268)
This commit is contained in:
parent
7f5087c6db
commit
253d8e5a5f
2 changed files with 209 additions and 2 deletions
|
|
@ -14,9 +14,11 @@ class PassportService:
|
|||
def verify(self, token):
|
||||
try:
|
||||
return jwt.decode(token, self.sk, algorithms=["HS256"])
|
||||
except jwt.exceptions.ExpiredSignatureError:
|
||||
raise Unauthorized("Token has expired.")
|
||||
except jwt.exceptions.InvalidSignatureError:
|
||||
raise Unauthorized("Invalid token signature.")
|
||||
except jwt.exceptions.DecodeError:
|
||||
raise Unauthorized("Invalid token.")
|
||||
except jwt.exceptions.ExpiredSignatureError:
|
||||
raise Unauthorized("Token has expired.")
|
||||
except jwt.exceptions.PyJWTError: # Catch-all for other JWT errors
|
||||
raise Unauthorized("Invalid token.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue