mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 20:11:30 +00:00
test(ssh): parametrized removing keys
This commit is contained in:
parent
ca4b3c972d
commit
b120858fa1
|
@ -518,84 +518,25 @@ def test_graphql_remove_ssh_key_unauthorized(client, some_users, mock_subprocess
|
||||||
assert_empty(response)
|
assert_empty(response)
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_remove_ssh_key(authorized_client, some_users, mock_subprocess_popen):
|
@pytest.mark.parametrize("user", key_users)
|
||||||
response = authorized_client.post(
|
def test_graphql_remove_ssh_key(authorized_client, no_keys, user):
|
||||||
"/graphql",
|
keys = [
|
||||||
json={
|
"ssh-rsa KEY test_key@pc",
|
||||||
"query": API_REMOVE_SSH_KEY_MUTATION,
|
"ssh-rsa KEY2 test_key@pc",
|
||||||
"variables": {
|
]
|
||||||
"sshInput": {
|
output = api_add_ssh_key(authorized_client, user, keys[0])
|
||||||
"username": "user1",
|
output = api_add_ssh_key(authorized_client, user, keys[1])
|
||||||
"sshKey": "ssh-rsa KEY user1@pc",
|
assert output["user"]["sshKeys"] == keys
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json().get("data") is not None
|
|
||||||
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["code"] == 200
|
output = api_remove_ssh_key(authorized_client, user, keys[1])
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["message"] is not None
|
assert_ok(output)
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["success"] is True
|
assert output["user"]["username"] == user
|
||||||
|
assert output["user"]["sshKeys"] == [keys[0]]
|
||||||
|
|
||||||
assert (
|
if user == "root":
|
||||||
response.json()["data"]["users"]["removeSshKey"]["user"]["username"] == "user1"
|
assert api_rootkeys(authorized_client) == [keys[0]]
|
||||||
)
|
else:
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["user"]["sshKeys"] == []
|
assert api_get_user_keys(authorized_client, user) == [keys[0]]
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_remove_root_ssh_key(authorized_client, some_users):
|
|
||||||
response = authorized_client.post(
|
|
||||||
"/graphql",
|
|
||||||
json={
|
|
||||||
"query": API_REMOVE_SSH_KEY_MUTATION,
|
|
||||||
"variables": {
|
|
||||||
"sshInput": {
|
|
||||||
"username": "root",
|
|
||||||
"sshKey": "ssh-ed25519 KEY test@pc",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json().get("data") is not None
|
|
||||||
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["code"] == 200
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["message"] is not None
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["success"] is True
|
|
||||||
|
|
||||||
assert (
|
|
||||||
response.json()["data"]["users"]["removeSshKey"]["user"]["username"] == "root"
|
|
||||||
)
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["user"]["sshKeys"] == []
|
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_remove_admin_ssh_key(
|
|
||||||
authorized_client, some_users, mock_subprocess_popen
|
|
||||||
):
|
|
||||||
response = authorized_client.post(
|
|
||||||
"/graphql",
|
|
||||||
json={
|
|
||||||
"query": API_REMOVE_SSH_KEY_MUTATION,
|
|
||||||
"variables": {
|
|
||||||
"sshInput": {
|
|
||||||
"username": "tester",
|
|
||||||
"sshKey": "ssh-rsa KEY test@pc",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json().get("data") is not None
|
|
||||||
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["code"] == 200
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["message"] is not None
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["success"] is True
|
|
||||||
|
|
||||||
assert (
|
|
||||||
response.json()["data"]["users"]["removeSshKey"]["user"]["username"] == "tester"
|
|
||||||
)
|
|
||||||
assert response.json()["data"]["users"]["removeSshKey"]["user"]["sshKeys"] == []
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("user", key_users)
|
@pytest.mark.parametrize("user", key_users)
|
||||||
|
|
|
@ -95,14 +95,6 @@ def some_users(mocker, datadir):
|
||||||
## /ssh/keys/{user} ######################################################
|
## /ssh/keys/{user} ######################################################
|
||||||
|
|
||||||
|
|
||||||
def test_delete_user_key(authorized_client, some_users):
|
|
||||||
response = authorized_client.delete(
|
|
||||||
"/services/ssh/keys/user1", json={"public_key": "ssh-rsa KEY user1@pc"}
|
|
||||||
)
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert read_json(some_users / "some_users.json")["users"][0]["sshKeys"] == []
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("user", [2, 3])
|
@pytest.mark.parametrize("user", [2, 3])
|
||||||
def test_delete_nonexistent_user_key(authorized_client, some_users, user):
|
def test_delete_nonexistent_user_key(authorized_client, some_users, user):
|
||||||
response = authorized_client.delete(
|
response = authorized_client.delete(
|
||||||
|
|
Loading…
Reference in a new issue