From 4523a1cab397b3cdf36c853c43f9c70119e952a0 Mon Sep 17 00:00:00 2001 From: Oleg A Date: Sat, 23 Nov 2019 12:45:47 +0300 Subject: [PATCH] #239 added token type validation --- aiogram/bot/api.py | 8 +++++++- tests/test_bot/test_api.py | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/aiogram/bot/api.py b/aiogram/bot/api.py index 9dea86ea..9589c3e5 100644 --- a/aiogram/bot/api.py +++ b/aiogram/bot/api.py @@ -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): diff --git a/tests/test_bot/test_api.py b/tests/test_bot/test_api.py index 0543a11f..29418169 100644 --- a/tests/test_bot/test_api.py +++ b/tests/test_bot/test_api.py @@ -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 ]