mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-02-16 22:34:32 +00:00
test(tokens-repo): break out getting new device token
This commit is contained in:
parent
1d6275b75b
commit
179078aed2
|
@ -132,15 +132,20 @@ def test_delete_token_unauthenticated(client, tokens_file):
|
||||||
assert_original(tokens_file)
|
assert_original(tokens_file)
|
||||||
|
|
||||||
|
|
||||||
def test_get_and_authorize_new_device(client, authorized_client, tokens_file):
|
def rest_get_new_device_token(client):
|
||||||
response = authorized_client.post("/auth/new_device")
|
response = client.post("/auth/new_device")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert "token" in response.json()
|
assert "token" in response.json()
|
||||||
token = Mnemonic(language="english").to_entropy(response.json()["token"]).hex()
|
return response.json()["token"]
|
||||||
assert read_json(tokens_file)["new_device"]["token"] == token
|
|
||||||
|
|
||||||
|
def test_get_and_authorize_new_device(client, authorized_client, tokens_file):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/auth/new_device/authorize",
|
"/auth/new_device/authorize",
|
||||||
json={"token": response.json()["token"], "device": "new_device"},
|
json={
|
||||||
|
"token": rest_get_new_device_token(authorized_client),
|
||||||
|
"device": "new_device",
|
||||||
|
},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert read_json(tokens_file)["tokens"][2]["token"] == response.json()["token"]
|
assert read_json(tokens_file)["tokens"][2]["token"] == response.json()["token"]
|
||||||
|
@ -157,21 +162,17 @@ def test_authorize_new_device_with_invalid_token(client, tokens_file):
|
||||||
|
|
||||||
|
|
||||||
def test_get_and_authorize_used_token(client, authorized_client, tokens_file):
|
def test_get_and_authorize_used_token(client, authorized_client, tokens_file):
|
||||||
response = authorized_client.post("/auth/new_device")
|
token_to_be_used_2_times = rest_get_new_device_token(authorized_client)
|
||||||
assert response.status_code == 200
|
|
||||||
assert "token" in response.json()
|
|
||||||
token = Mnemonic(language="english").to_entropy(response.json()["token"]).hex()
|
|
||||||
assert read_json(tokens_file)["new_device"]["token"] == token
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/auth/new_device/authorize",
|
"/auth/new_device/authorize",
|
||||||
json={"token": response.json()["token"], "device": "new_device"},
|
json={"token": token_to_be_used_2_times, "device": "new_device"},
|
||||||
)
|
)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert read_json(tokens_file)["tokens"][2]["token"] == response.json()["token"]
|
assert read_json(tokens_file)["tokens"][2]["token"] == response.json()["token"]
|
||||||
assert read_json(tokens_file)["tokens"][2]["name"] == "new_device"
|
assert read_json(tokens_file)["tokens"][2]["name"] == "new_device"
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/auth/new_device/authorize",
|
"/auth/new_device/authorize",
|
||||||
json={"token": response.json()["token"], "device": "new_device"},
|
json={"token": token_to_be_used_2_times, "device": "new_device"},
|
||||||
)
|
)
|
||||||
assert response.status_code == 404
|
assert response.status_code == 404
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue