test(ssh): add graphql ssh status query test

remove-rest
Houkime 2023-12-15 10:09:35 +00:00
parent 1b520a8093
commit 66561308bf
1 changed files with 32 additions and 3 deletions

View File

@ -2,9 +2,11 @@
# pylint: disable=unused-argument
import pytest
from tests.common import read_json
from tests.test_graphql.common import assert_empty
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
class ProcessMock:
@ -68,12 +70,39 @@ mutation enableSsh($sshInput: SSHSettingsInput!) {
message
code
enable
password_authentication
passwordAuthentication
}
}
}
"""
API_SSH_SETTINGS_QUERY = """
settings {
ssh {
enable
passwordAuthentication
}
}
"""
def api_ssh_settings(authorized_client):
response = authorized_client.post(
"/graphql",
json={"query": generate_system_query([API_SSH_SETTINGS_QUERY])},
)
data = get_data(response)
result = data["system"]["settings"]["ssh"]
assert result is not None
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?
settings = api_ssh_settings(authorized_client)
assert settings["enable"] is True
assert settings["passwordAuthentication"] is True
def test_graphql_change_ssh_settings_unauthorized(
client, some_users, mock_subprocess_popen