mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-12-01 10:56:39 +00:00
test(tokens-repo): check for token existense in recovery tests
This commit is contained in:
parent
de27032191
commit
ce4fbdae0a
|
@ -10,7 +10,14 @@ from tests.common import (
|
||||||
write_json,
|
write_json,
|
||||||
assert_recovery_recent,
|
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 = """
|
API_RECOVERY_QUERY = """
|
||||||
recoveryKey {
|
recoveryKey {
|
||||||
|
@ -69,6 +76,11 @@ def graphql_use_recovery_key(client, key, device_name):
|
||||||
assert_ok(response, "useRecoveryApiKey")
|
assert_ok(response, "useRecoveryApiKey")
|
||||||
token = response.json()["data"]["useRecoveryApiKey"]["token"]
|
token = response.json()["data"]["useRecoveryApiKey"]["token"]
|
||||||
assert token is not None
|
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
|
return token
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,34 +131,9 @@ def test_graphql_generate_recovery_key(client, authorized_client, tokens_file):
|
||||||
assert status["expirationDate"] is None
|
assert status["expirationDate"] is None
|
||||||
assert status["usesLeft"] is None
|
assert status["usesLeft"] is None
|
||||||
|
|
||||||
token = graphql_use_recovery_key(client, key, "new_test_token")
|
graphql_use_recovery_key(client, key, "new_test_token")
|
||||||
assert token == read_json(tokens_file)["tokens"][2]["token"]
|
# And again
|
||||||
assert read_json(tokens_file)["tokens"][2]["name"] == "new_test_token"
|
graphql_use_recovery_key(client, key, "new_test_token2")
|
||||||
|
|
||||||
# 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"
|
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_generate_recovery_key_with_expiration_date(
|
def test_graphql_generate_recovery_key_with_expiration_date(
|
||||||
|
|
Loading…
Reference in a new issue