mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
#239 added token type validation
This commit is contained in:
parent
89b0754b33
commit
4523a1cab3
2 changed files with 11 additions and 1 deletions
|
|
@ -24,8 +24,14 @@ def check_token(token: str) -> bool:
|
|||
:param token:
|
||||
:return:
|
||||
"""
|
||||
if not isinstance(token, str):
|
||||
message = (f"Token is invalid! "
|
||||
f"It must be 'str' type instead of {type(token)} type.")
|
||||
raise exceptions.ValidationError(message)
|
||||
|
||||
if any(x.isspace() for x in token):
|
||||
raise exceptions.ValidationError('Token is invalid!')
|
||||
message = "Token is invalid! It can't contains spaces."
|
||||
raise exceptions.ValidationError(message)
|
||||
|
||||
left, sep, right = token.partition(':')
|
||||
if (not sep) or (not left.isdigit()) or (not right):
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ INVALID_TOKENS = [
|
|||
':AABBCCDDEEFFaabbccddeeff123456789', # there is no left part
|
||||
'123456789:', # there is no right part
|
||||
'ABC AABBCCDDEEFFaabbccddeeff123456789', # there is no ':' separator
|
||||
None, # is None
|
||||
12345678, # is digit
|
||||
{}, # is dict
|
||||
[], # is dict
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue