mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-29 07:21:27 +00:00
test(tokens-repo): do not read json in generate recovery test
This commit is contained in:
parent
74777c4343
commit
0239f3174e
|
@ -257,21 +257,19 @@ def test_generate_recovery_token(authorized_client, client, tokens_file):
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert "token" in response.json()
|
assert "token" in response.json()
|
||||||
mnemonic_token = response.json()["token"]
|
mnemonic_token = response.json()["token"]
|
||||||
token = Mnemonic(language="english").to_entropy(mnemonic_token).hex()
|
|
||||||
assert read_json(tokens_file)["recovery_token"]["token"] == token
|
|
||||||
|
|
||||||
time_generated = read_json(tokens_file)["recovery_token"]["date"]
|
# Try to get token status
|
||||||
assert time_generated is not None
|
response = authorized_client.get("/auth/recovery_token")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert "date" in response.json()
|
||||||
|
time_generated = response.json()["date"]
|
||||||
|
|
||||||
# Assert that the token was generated near the current time
|
# Assert that the token was generated near the current time
|
||||||
assert (
|
assert (
|
||||||
datetime.datetime.strptime(time_generated, "%Y-%m-%dT%H:%M:%S.%f")
|
datetime.datetime.strptime(time_generated, "%Y-%m-%dT%H:%M:%S.%f")
|
||||||
- datetime.timedelta(seconds=5)
|
- datetime.timedelta(seconds=5)
|
||||||
< datetime.datetime.now()
|
< datetime.datetime.now()
|
||||||
)
|
)
|
||||||
|
|
||||||
# Try to get token status
|
|
||||||
response = authorized_client.get("/auth/recovery_token")
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json() == {
|
assert response.json() == {
|
||||||
"exists": True,
|
"exists": True,
|
||||||
"valid": True,
|
"valid": True,
|
||||||
|
@ -287,8 +285,7 @@ def test_generate_recovery_token(authorized_client, client, tokens_file):
|
||||||
)
|
)
|
||||||
assert recovery_response.status_code == 200
|
assert recovery_response.status_code == 200
|
||||||
new_token = recovery_response.json()["token"]
|
new_token = recovery_response.json()["token"]
|
||||||
assert read_json(tokens_file)["tokens"][2]["token"] == new_token
|
assert_token_valid(authorized_client, new_token)
|
||||||
assert read_json(tokens_file)["tokens"][2]["name"] == "recovery_device"
|
|
||||||
|
|
||||||
# Try to use token again
|
# Try to use token again
|
||||||
recovery_response = client.post(
|
recovery_response = client.post(
|
||||||
|
@ -297,8 +294,7 @@ def test_generate_recovery_token(authorized_client, client, tokens_file):
|
||||||
)
|
)
|
||||||
assert recovery_response.status_code == 200
|
assert recovery_response.status_code == 200
|
||||||
new_token = recovery_response.json()["token"]
|
new_token = recovery_response.json()["token"]
|
||||||
assert read_json(tokens_file)["tokens"][3]["token"] == new_token
|
assert_token_valid(authorized_client, new_token)
|
||||||
assert read_json(tokens_file)["tokens"][3]["name"] == "recovery_device2"
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("timeformat", DATE_FORMATS)
|
@pytest.mark.parametrize("timeformat", DATE_FORMATS)
|
||||||
|
|
Loading…
Reference in a new issue