mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-25 13:31:27 +00:00
test(ssh): admin keys deleting
This commit is contained in:
parent
ac41cc00ce
commit
f24aba8abb
|
@ -93,9 +93,6 @@ def api_get_user_keys(authorized_client, user: str):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# TESTS ########################################################
|
|
||||||
|
|
||||||
|
|
||||||
API_CREATE_SSH_KEY_MUTATION = """
|
API_CREATE_SSH_KEY_MUTATION = """
|
||||||
mutation addSshKey($sshInput: SshMutationInput!) {
|
mutation addSshKey($sshInput: SshMutationInput!) {
|
||||||
users {
|
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):
|
def test_graphql_ssh_query(authorized_client, some_users):
|
||||||
settings = api_ssh_settings(authorized_client)
|
settings = api_ssh_settings(authorized_client)
|
||||||
assert settings["enable"] is True
|
assert settings["enable"] is True
|
||||||
|
@ -638,40 +638,17 @@ def test_graphql_remove_main_ssh_key(
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["user"]["sshKeys"] == []
|
assert response.json()["data"]["users"]["removeSshKey"]["user"]["sshKeys"] == []
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_remove_nonexistent_ssh_key(
|
key_users = ["root", "tester", "user1"]
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_remove_nonexistent_root_key(
|
@pytest.mark.parametrize("user", key_users)
|
||||||
authorized_client, some_users, mock_subprocess_popen
|
def test_graphql_remove_nonexistent_ssh_key(authorized_client, some_users, user):
|
||||||
):
|
output = api_remove_ssh_key(authorized_client, user, "ssh-rsa nonexistent")
|
||||||
output = api_remove_ssh_key(
|
|
||||||
authorized_client, "root", "ssh-rsa gone in a puff of logic"
|
|
||||||
)
|
|
||||||
assert_errorcode(output, 404)
|
assert_errorcode(output, 404)
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_remove_ssh_key_nonexistent_user(
|
def test_graphql_remove_ssh_key_nonexistent_user(
|
||||||
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, "user666", "ssh-rsa KEY test_key@pc")
|
||||||
"/graphql",
|
assert_errorcode(output, 404)
|
||||||
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
|
|
||||||
|
|
|
@ -95,27 +95,6 @@ def some_users(mocker, datadir):
|
||||||
## /ssh/keys/{user} ######################################################
|
## /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):
|
def test_delete_admin_key_on_undefined(authorized_client, undefined_settings):
|
||||||
response = authorized_client.delete(
|
response = authorized_client.delete(
|
||||||
"/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY test@pc"}
|
"/services/ssh/keys/tester", json={"public_key": "ssh-rsa KEY test@pc"}
|
||||||
|
|
Loading…
Reference in a new issue