test(ssh): try disabling ssh

remove-rest
Houkime 2023-12-15 10:43:07 +00:00
parent 66561308bf
commit f179cff0b4
1 changed files with 30 additions and 5 deletions

View File

@ -6,7 +6,7 @@ from selfprivacy_api.graphql.mutations.system_mutations import SystemMutations
from selfprivacy_api.graphql.queries.system import System
from tests.common import read_json, generate_system_query
from tests.test_graphql.common import assert_empty, get_data
from tests.test_graphql.common import assert_empty, assert_ok, get_data
class ProcessMock:
@ -63,9 +63,9 @@ mutation addSshKey($sshInput: SshMutationInput!) {
"""
API_SET_SSH_SETTINGS = """
mutation enableSsh($sshInput: SSHSettingsInput!) {
mutation enableSsh($settings: SSHSettingsInput!) {
system {
changeSshSettings(sshInput: $sshInput) {
changeSshSettings(settings: $settings) {
success
message
code
@ -97,8 +97,26 @@ def api_ssh_settings(authorized_client):
return result
def test_graphql_ssh_enabled_by_default(authorized_client, some_users):
# TODO: Should it be enabled by default though if there are no keys anyway?
def api_set_ssh_settings(authorized_client, enable: bool, password_auth: bool):
response = authorized_client.post(
"/graphql",
json={
"query": API_SET_SSH_SETTINGS,
"variables": {
"settings": {
"enable": enable,
"passwordAuthentication": password_auth,
},
},
},
)
data = get_data(response)
result = data["system"]["changeSshSettings"]
assert result is not None
return result
def test_graphql_ssh_query(authorized_client, some_users):
settings = api_ssh_settings(authorized_client)
assert settings["enable"] is True
assert settings["passwordAuthentication"] is True
@ -122,6 +140,13 @@ def test_graphql_change_ssh_settings_unauthorized(
assert_empty(response)
def test_graphql_disable_ssh(authorized_client, some_users, mock_subprocess_popen):
output = api_set_ssh_settings(authorized_client, enable=False, password_auth=False)
assert_ok(output)
assert output["enable"] == False
assert output["passwordAuthentication"] == False
def test_graphql_add_ssh_key_unauthorized(client, some_users, mock_subprocess_popen):
response = client.post(
"/graphql",