From f24aba8abb3c7bbc97edfa16903eb7ddae59ca00 Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Thu, 21 Dec 2023 11:40:08 +0000 Subject: [PATCH] test(ssh): admin keys deleting --- tests/test_graphql/test_ssh.py | 41 ++++--------------- .../test_rest_endpoints/services/test_ssh.py | 21 ---------- 2 files changed, 9 insertions(+), 53 deletions(-) diff --git a/tests/test_graphql/test_ssh.py b/tests/test_graphql/test_ssh.py index 2d83eea..ee95cbe 100644 --- a/tests/test_graphql/test_ssh.py +++ b/tests/test_graphql/test_ssh.py @@ -93,9 +93,6 @@ def api_get_user_keys(authorized_client, user: str): return None -# TESTS ######################################################## - - API_CREATE_SSH_KEY_MUTATION = """ mutation addSshKey($sshInput: SshMutationInput!) { users { @@ -240,6 +237,9 @@ def api_set_ssh_settings(authorized_client, enable: bool, password_auth: bool): ) +# TESTS ######################################################## + + def test_graphql_ssh_query(authorized_client, some_users): settings = api_ssh_settings(authorized_client) assert settings["enable"] is True @@ -638,40 +638,17 @@ def test_graphql_remove_main_ssh_key( assert response.json()["data"]["users"]["removeSshKey"]["user"]["sshKeys"] == [] -def test_graphql_remove_nonexistent_ssh_key( - authorized_client, some_users, mock_subprocess_popen -): - output = api_remove_ssh_key(authorized_client, "user1", "ssh-rsa KEY test_key@pc") - assert_errorcode(output, 404) +key_users = ["root", "tester", "user1"] -def test_graphql_remove_nonexistent_root_key( - authorized_client, some_users, mock_subprocess_popen -): - output = api_remove_ssh_key( - authorized_client, "root", "ssh-rsa gone in a puff of logic" - ) +@pytest.mark.parametrize("user", key_users) +def test_graphql_remove_nonexistent_ssh_key(authorized_client, some_users, user): + output = api_remove_ssh_key(authorized_client, user, "ssh-rsa nonexistent") assert_errorcode(output, 404) def test_graphql_remove_ssh_key_nonexistent_user( authorized_client, some_users, mock_subprocess_popen ): - response = authorized_client.post( - "/graphql", - json={ - "query": API_REMOVE_SSH_KEY_MUTATION, - "variables": { - "sshInput": { - "username": "user666", - "sshKey": "ssh-rsa KEY test_key@pc", - }, - }, - }, - ) - assert response.status_code == 200 - assert response.json().get("data") is not None - - assert response.json()["data"]["users"]["removeSshKey"]["code"] == 404 - assert response.json()["data"]["users"]["removeSshKey"]["message"] is not None - assert response.json()["data"]["users"]["removeSshKey"]["success"] is False + output = api_remove_ssh_key(authorized_client, "user666", "ssh-rsa KEY test_key@pc") + assert_errorcode(output, 404) diff --git a/tests/test_rest_endpoints/services/test_ssh.py b/tests/test_rest_endpoints/services/test_ssh.py index b9817c6..03dadb3 100644 --- a/tests/test_rest_endpoints/services/test_ssh.py +++ b/tests/test_rest_endpoints/services/test_ssh.py @@ -95,27 +95,6 @@ def some_users(mocker, datadir): ## /ssh/keys/{user} ###################################################### -def test_delete_admin_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.delete( - "/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 200 - assert ( - read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")["sshKeys"] - == [] - ) - - -def test_delete_nonexistent_admin_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.delete( - "/services/ssh/keys/tester", json={"public_key": "ssh-rsa NO KEY test@pc"} - ) - assert response.status_code == 404 - assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")[ - "sshKeys" - ] == ["ssh-rsa KEY test@pc"] - - def test_delete_admin_key_on_undefined(authorized_client, undefined_settings): response = authorized_client.delete( "/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY test@pc"}