test(ssh): delete undefined root keys

remove-rest
Houkime 2023-12-20 11:36:58 +00:00
parent 25d2537208
commit a2065b87b7
2 changed files with 24 additions and 15 deletions

View File

@ -105,15 +105,6 @@ def test_add_root_key(authorized_client, ssh_on):
]
def test_add_root_key_on_undefined(authorized_client, undefined_settings):
response = authorized_client.put(
"/services/ssh/key/send", json={"public_key": "ssh-rsa KEY test@pc"}
)
assert response.status_code == 201
data = read_json(undefined_settings / "undefined.json")
assert data["ssh"]["rootKeys"] == ["ssh-rsa KEY test@pc"]
def test_add_root_key_one_more(authorized_client, root_and_admin_have_keys):
response = authorized_client.put(
"/services/ssh/key/send", json={"public_key": "ssh-rsa KEY test@pc"}
@ -154,12 +145,6 @@ def test_get_root_key_when_none(authorized_client, ssh_on):
assert response.json() == []
def test_get_root_key_on_undefined(authorized_client, undefined_settings):
response = authorized_client.get("/services/ssh/keys/root")
assert response.status_code == 200
assert response.json() == []
def test_delete_root_key(authorized_client, root_and_admin_have_keys):
response = authorized_client.delete(
"/services/ssh/keys/root", json={"public_key": "ssh-ed25519 KEY test@pc"}

View File

@ -10,6 +10,7 @@ from selfprivacy_api.actions.ssh import (
get_ssh_settings,
create_ssh_key,
remove_ssh_key,
KeyNotFound,
)
from selfprivacy_api.actions.users import get_users
from selfprivacy_api.utils import WriteUserData, ReadUserData
@ -164,6 +165,29 @@ def test_removing_root_key_writes_json(generic_userdata):
assert data["ssh"]["rootKeys"] == []
def test_remove_root_key_on_undefined(generic_userdata):
# generic userdata has a a single root key
rootkeys = get_ssh_settings().rootKeys
assert len(rootkeys) == 1
key1 = rootkeys[0]
with WriteUserData() as data:
del data["ssh"]["rootKeys"]
with pytest.raises(KeyNotFound):
remove_ssh_key("root", key1)
rootkeys = get_ssh_settings().rootKeys
assert len(rootkeys) == 0
with WriteUserData() as data:
del data["ssh"]
with pytest.raises(KeyNotFound):
remove_ssh_key("root", key1)
rootkeys = get_ssh_settings().rootKeys
assert len(rootkeys) == 0
def test_adding_root_key_writes_json(generic_userdata):
with WriteUserData() as data:
del data["ssh"]