diff --git a/tests/test_graphql/test_ssh.py b/tests/test_graphql/test_ssh.py index b27c5fe..e6a619c 100644 --- a/tests/test_graphql/test_ssh.py +++ b/tests/test_graphql/test_ssh.py @@ -446,35 +446,20 @@ def test_graphql_add_ssh_key_one_more(authorized_client, no_keys, user): assert api_get_user_keys(authorized_client, user) == keys -def test_graphql_add_root_ssh_key_same(authorized_client, no_rootkeys): +@pytest.mark.parametrize("user", key_users) +def test_graphql_add_ssh_key_same(authorized_client, no_keys, user): key = "ssh-rsa KEY test_key@pc" - output = api_add_ssh_key(authorized_client, "root", key) + output = api_add_ssh_key(authorized_client, user, key) assert output["user"]["sshKeys"] == [key] - output = api_add_ssh_key(authorized_client, "root", key) + output = api_add_ssh_key(authorized_client, user, key) assert_errorcode(output, 409) -# TODO: multiplex for root and admin -def test_graphql_add_bad_ssh_key(authorized_client, some_users, mock_subprocess_popen): - response = authorized_client.post( - "/graphql", - json={ - "query": API_CREATE_SSH_KEY_MUTATION, - "variables": { - "sshInput": { - "username": "user1", - "sshKey": "trust me, this is the ssh key", - }, - }, - }, - ) - assert response.status_code == 200 - assert response.json().get("data") is not None - - assert response.json()["data"]["users"]["addSshKey"]["code"] == 400 - assert response.json()["data"]["users"]["addSshKey"]["message"] is not None - assert response.json()["data"]["users"]["addSshKey"]["success"] is False +@pytest.mark.parametrize("user", key_users) +def test_graphql_add_bad_ssh_key(authorized_client, some_users, user): + output = api_add_ssh_key(authorized_client, user, "trust me, this is the ssh key") + assert_errorcode(output, 400) def test_graphql_add_ssh_key_nonexistent_user( diff --git a/tests/test_rest_endpoints/services/test_ssh.py b/tests/test_rest_endpoints/services/test_ssh.py index ebc60fb..ce9a39c 100644 --- a/tests/test_rest_endpoints/services/test_ssh.py +++ b/tests/test_rest_endpoints/services/test_ssh.py @@ -95,35 +95,6 @@ def some_users(mocker, datadir): ## /ssh/keys/{user} ###################################################### -def test_add_admin_key_one_more(authorized_client, root_and_admin_have_keys): - response = authorized_client.post( - "/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY_2 test@pc"} - ) - assert response.status_code == 201 - assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")[ - "sshKeys" - ] == ["ssh-rsa KEY test@pc", "ssh-rsa KEY_2 test@pc"] - - -def test_add_existing_admin_key(authorized_client, root_and_admin_have_keys): - response = authorized_client.post( - "/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY test@pc"} - ) - assert response.status_code == 409 - assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")[ - "sshKeys" - ] == [ - "ssh-rsa KEY test@pc", - ] - - -def test_add_invalid_admin_key(authorized_client, ssh_on): - response = authorized_client.post( - "/services/ssh/keys/tester", json={"public_key": "INVALID KEY test@pc"} - ) - assert response.status_code == 400 - - @pytest.mark.parametrize("user", [1, 2, 3]) def test_get_user_key(authorized_client, some_users, user): response = authorized_client.get(f"/services/ssh/keys/user{user}")