From 90c0c34a8d42302588a590f861462c883dcf3a83 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 20 Dec 2023 12:08:15 +0000 Subject: [PATCH] test(ssh): add root key when none --- tests/test_graphql/test_ssh.py | 13 +++++++++++-- tests/test_rest_endpoints/services/test_ssh.py | 10 ---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/test_graphql/test_ssh.py b/tests/test_graphql/test_ssh.py index a911fb1..effc3a7 100644 --- a/tests/test_graphql/test_ssh.py +++ b/tests/test_graphql/test_ssh.py @@ -5,6 +5,9 @@ import pytest from selfprivacy_api.graphql.mutations.system_mutations import SystemMutations from selfprivacy_api.graphql.queries.system import System +# only allowed in fixtures +from selfprivacy_api.actions.ssh import remove_ssh_key, get_ssh_settings + from tests.common import read_json, generate_system_query from tests.test_graphql.common import assert_empty, assert_ok, get_data @@ -43,6 +46,13 @@ def some_users(mocker, datadir): return datadir +@pytest.fixture +def no_rootkeys(generic_userdata): + for rootkey in get_ssh_settings().rootKeys: + remove_ssh_key("root", rootkey) + assert get_ssh_settings().rootKeys == [] + + # TESTS ######################################################## @@ -281,7 +291,7 @@ def test_graphql_add_ssh_key(authorized_client, some_users, mock_subprocess_pope ] -def test_graphql_add_root_ssh_key(authorized_client, some_users, mock_subprocess_popen): +def test_graphql_add_root_ssh_key(authorized_client, no_rootkeys): response = authorized_client.post( "/graphql", json={ @@ -303,7 +313,6 @@ def test_graphql_add_root_ssh_key(authorized_client, some_users, mock_subprocess assert response.json()["data"]["users"]["addSshKey"]["user"]["username"] == "root" assert response.json()["data"]["users"]["addSshKey"]["user"]["sshKeys"] == [ - "ssh-ed25519 KEY test@pc", "ssh-rsa KEY test_key@pc", ] diff --git a/tests/test_rest_endpoints/services/test_ssh.py b/tests/test_rest_endpoints/services/test_ssh.py index e9e668a..dfcce57 100644 --- a/tests/test_rest_endpoints/services/test_ssh.py +++ b/tests/test_rest_endpoints/services/test_ssh.py @@ -95,16 +95,6 @@ def some_users(mocker, datadir): ## PUT ON /ssh/key/send ###################################################### -def test_add_root_key(authorized_client, ssh_on): - response = authorized_client.put( - "/services/ssh/key/send", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 201 - assert read_json(ssh_on / "turned_on.json")["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"}