test(ssh): remove root key nonexistent

remove-rest
Houkime 2023-12-21 09:04:27 +00:00
parent 8fc7796da0
commit e7075546c5
2 changed files with 29 additions and 29 deletions

View File

@ -144,6 +144,25 @@ def api_add_ssh_key(authorized_client, user: str, key: str):
return result
def api_remove_ssh_key(authorized_client, user: str, key: str):
response = authorized_client.post(
"/graphql",
json={
"query": API_REMOVE_SSH_KEY_MUTATION,
"variables": {
"sshInput": {
"username": user,
"sshKey": key,
},
},
},
)
data = get_data(response)
result = data["users"]["removeSshKey"]
assert result is not None
return result
def api_rootkeys(authorized_client):
response = api_rootkeys_raw(authorized_client)
data = get_data(response)
@ -579,24 +598,17 @@ def test_graphql_remove_main_ssh_key(
def test_graphql_remove_nonexistent_ssh_key(
authorized_client, some_users, mock_subprocess_popen
):
response = authorized_client.post(
"/graphql",
json={
"query": API_REMOVE_SSH_KEY_MUTATION,
"variables": {
"sshInput": {
"username": "user1",
"sshKey": "ssh-rsa KEY test_key@pc",
},
},
},
)
assert response.status_code == 200
assert response.json().get("data") is not None
output = api_remove_ssh_key(authorized_client, "user1", "ssh-rsa KEY test_key@pc")
assert_errorcode(output, 404)
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
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"
)
assert_errorcode(output, 404)
def test_graphql_remove_ssh_key_nonexistent_user(

View File

@ -95,18 +95,6 @@ def some_users(mocker, datadir):
## /ssh/keys/{user} ######################################################
def test_delete_root_nonexistent_key(authorized_client, root_and_admin_have_keys):
response = authorized_client.delete(
"/services/ssh/keys/root", json={"public_key": "ssh-rsa KEY test@pc"}
)
assert response.status_code == 404
assert read_json(root_and_admin_have_keys / "root_and_admin_have_keys.json")["ssh"][
"rootKeys"
] == [
"ssh-ed25519 KEY test@pc",
]
def test_get_admin_key(authorized_client, root_and_admin_have_keys):
response = authorized_client.get("/services/ssh/keys/tester")
assert response.status_code == 200