test(tokens-repo): check for token existense in recovery tests

This commit is contained in:
Houkime 2023-01-06 11:57:51 +00:00 committed by Inex Code
parent de27032191
commit ce4fbdae0a

View file

@ -10,7 +10,14 @@ from tests.common import (
write_json,
assert_recovery_recent,
)
from tests.test_graphql.common import assert_empty, assert_data, assert_ok
from tests.test_graphql.common import (
assert_empty,
assert_data,
assert_ok,
assert_token_valid,
graphql_get_devices,
set_client_token,
)
API_RECOVERY_QUERY = """
recoveryKey {
@ -69,6 +76,11 @@ def graphql_use_recovery_key(client, key, device_name):
assert_ok(response, "useRecoveryApiKey")
token = response.json()["data"]["useRecoveryApiKey"]["token"]
assert token is not None
assert_token_valid(client, token)
set_client_token(client, token)
assert "new_test_token" in [
device["name"] for device in graphql_get_devices(client)
]
return token
@ -119,34 +131,9 @@ def test_graphql_generate_recovery_key(client, authorized_client, tokens_file):
assert status["expirationDate"] is None
assert status["usesLeft"] is None
token = graphql_use_recovery_key(client, key, "new_test_token")
assert token == read_json(tokens_file)["tokens"][2]["token"]
assert read_json(tokens_file)["tokens"][2]["name"] == "new_test_token"
# Try to use token again
response = client.post(
"/graphql",
json={
"query": API_RECOVERY_KEY_USE_MUTATION,
"variables": {
"input": {
"key": key,
"deviceName": "new_test_token2",
},
},
},
)
assert response.status_code == 200
assert response.json().get("data") is not None
assert response.json()["data"]["useRecoveryApiKey"]["success"] is True
assert response.json()["data"]["useRecoveryApiKey"]["message"] is not None
assert response.json()["data"]["useRecoveryApiKey"]["code"] == 200
assert response.json()["data"]["useRecoveryApiKey"]["token"] is not None
assert (
response.json()["data"]["useRecoveryApiKey"]["token"]
== read_json(tokens_file)["tokens"][3]["token"]
)
assert read_json(tokens_file)["tokens"][3]["name"] == "new_test_token2"
graphql_use_recovery_key(client, key, "new_test_token")
# And again
graphql_use_recovery_key(client, key, "new_test_token2")
def test_graphql_generate_recovery_key_with_expiration_date(