mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-18 08:29:14 +00:00
fix(tokens-repo): fix name pair validation being able to raise a notfound error
This commit is contained in:
parent
3021584adc
commit
20410ec790
|
@ -77,8 +77,11 @@ class AbstractTokensRepository(ABC):
|
|||
|
||||
def is_token_name_pair_valid(self, token_name: str, token_string: str) -> bool:
|
||||
"""Check if the token name and token are valid"""
|
||||
token = self.get_token_by_name(token_name)
|
||||
if token is None:
|
||||
try:
|
||||
token = self.get_token_by_name(token_name)
|
||||
if token is None:
|
||||
return False
|
||||
except TokenNotFound:
|
||||
return False
|
||||
return token.token == token_string
|
||||
|
||||
|
|
|
@ -207,6 +207,14 @@ def test_get_token_by_non_existent_name(some_tokens_repo):
|
|||
assert repo.get_token_by_name(token_name="badname") is None
|
||||
|
||||
|
||||
def test_is_token_name_pair_valid(some_tokens_repo):
|
||||
repo = some_tokens_repo
|
||||
token = repo.get_tokens()[0]
|
||||
assert repo.is_token_name_pair_valid(token.device_name, token.token)
|
||||
assert not repo.is_token_name_pair_valid(token.device_name, "gibberish")
|
||||
assert not repo.is_token_name_pair_valid("gibberish", token.token)
|
||||
|
||||
|
||||
def test_get_tokens(some_tokens_repo):
|
||||
repo = some_tokens_repo
|
||||
tokenstrings = []
|
||||
|
|
Loading…
Reference in a new issue