mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-24 17:56:44 +00:00
test(ssh): remove root key nonexistent
This commit is contained in:
parent
8fc7796da0
commit
e7075546c5
|
@ -144,6 +144,25 @@ def api_add_ssh_key(authorized_client, user: str, key: str):
|
||||||
return result
|
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):
|
def api_rootkeys(authorized_client):
|
||||||
response = api_rootkeys_raw(authorized_client)
|
response = api_rootkeys_raw(authorized_client)
|
||||||
data = get_data(response)
|
data = get_data(response)
|
||||||
|
@ -579,24 +598,17 @@ def test_graphql_remove_main_ssh_key(
|
||||||
def test_graphql_remove_nonexistent_ssh_key(
|
def test_graphql_remove_nonexistent_ssh_key(
|
||||||
authorized_client, some_users, mock_subprocess_popen
|
authorized_client, some_users, mock_subprocess_popen
|
||||||
):
|
):
|
||||||
response = authorized_client.post(
|
output = api_remove_ssh_key(authorized_client, "user1", "ssh-rsa KEY test_key@pc")
|
||||||
"/graphql",
|
assert_errorcode(output, 404)
|
||||||
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
|
|
||||||
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["code"] == 404
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["message"] is not None
|
def test_graphql_remove_nonexistent_root_key(
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["success"] is False
|
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(
|
def test_graphql_remove_ssh_key_nonexistent_user(
|
||||||
|
|
|
@ -95,18 +95,6 @@ def some_users(mocker, datadir):
|
||||||
## /ssh/keys/{user} ######################################################
|
## /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):
|
def test_get_admin_key(authorized_client, root_and_admin_have_keys):
|
||||||
response = authorized_client.get("/services/ssh/keys/tester")
|
response = authorized_client.get("/services/ssh/keys/tester")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
Loading…
Reference in a new issue