From a2065b87b76f378ff83fdabd505ec2a6fe7691b5 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 20 Dec 2023 11:36:58 +0000 Subject: [PATCH] test(ssh): delete undefined root keys --- .../test_rest_endpoints/services/test_ssh.py | 15 ------------ tests/test_ssh.py | 24 +++++++++++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/tests/test_rest_endpoints/services/test_ssh.py b/tests/test_rest_endpoints/services/test_ssh.py index 759e5ed..cd7ed86 100644 --- a/tests/test_rest_endpoints/services/test_ssh.py +++ b/tests/test_rest_endpoints/services/test_ssh.py @@ -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"} diff --git a/tests/test_ssh.py b/tests/test_ssh.py index 739d321..ec8b4b2 100644 --- a/tests/test_ssh.py +++ b/tests/test_ssh.py @@ -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"]