test(ssh): parametrized testing of ssh key addition, existing and invalid

This commit is contained in:
Houkime 2023-12-22 08:12:50 +00:00
parent 65c2023366
commit 16c2598e9b
2 changed files with 8 additions and 52 deletions

View file

@ -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 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" 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] 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) assert_errorcode(output, 409)
# TODO: multiplex for root and admin @pytest.mark.parametrize("user", key_users)
def test_graphql_add_bad_ssh_key(authorized_client, some_users, mock_subprocess_popen): def test_graphql_add_bad_ssh_key(authorized_client, some_users, user):
response = authorized_client.post( output = api_add_ssh_key(authorized_client, user, "trust me, this is the ssh key")
"/graphql", assert_errorcode(output, 400)
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
def test_graphql_add_ssh_key_nonexistent_user( def test_graphql_add_ssh_key_nonexistent_user(

View file

@ -95,35 +95,6 @@ def some_users(mocker, datadir):
## /ssh/keys/{user} ###################################################### ## /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]) @pytest.mark.parametrize("user", [1, 2, 3])
def test_get_user_key(authorized_client, some_users, user): def test_get_user_key(authorized_client, some_users, user):
response = authorized_client.get(f"/services/ssh/keys/user{user}") response = authorized_client.get(f"/services/ssh/keys/user{user}")