mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-25 21:41:27 +00:00
feature(ssh): change ssh settings from graphql
This commit is contained in:
parent
980d3622e8
commit
1b520a8093
|
@ -9,6 +9,7 @@ from selfprivacy_api.graphql.mutations.mutation_interface import (
|
||||||
)
|
)
|
||||||
|
|
||||||
import selfprivacy_api.actions.system as system_actions
|
import selfprivacy_api.actions.system as system_actions
|
||||||
|
import selfprivacy_api.actions.ssh as ssh_actions
|
||||||
|
|
||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
|
@ -26,6 +27,22 @@ class AutoUpgradeSettingsMutationReturn(MutationReturnInterface):
|
||||||
allowReboot: bool
|
allowReboot: bool
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.type
|
||||||
|
class SSHSettingsMutationReturn(MutationReturnInterface):
|
||||||
|
"""A return type for after changing SSH settings"""
|
||||||
|
|
||||||
|
enable: bool
|
||||||
|
password_authentication: bool
|
||||||
|
|
||||||
|
|
||||||
|
@strawberry.input
|
||||||
|
class SSHSettingsInput:
|
||||||
|
"""Input type for SSH settings"""
|
||||||
|
|
||||||
|
enable: bool
|
||||||
|
password_authentication: bool
|
||||||
|
|
||||||
|
|
||||||
@strawberry.input
|
@strawberry.input
|
||||||
class AutoUpgradeSettingsInput:
|
class AutoUpgradeSettingsInput:
|
||||||
"""Input type for auto upgrade settings"""
|
"""Input type for auto upgrade settings"""
|
||||||
|
@ -76,6 +93,26 @@ class SystemMutations:
|
||||||
allowReboot=new_settings.allowReboot,
|
allowReboot=new_settings.allowReboot,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
|
def change_ssh_settings(
|
||||||
|
self, settings: SSHSettingsInput
|
||||||
|
) -> SSHSettingsMutationReturn:
|
||||||
|
"""Change ssh settings of the server."""
|
||||||
|
ssh_actions.set_ssh_settings(
|
||||||
|
enable=settings.enable,
|
||||||
|
password_authentication=settings.password_authentication,
|
||||||
|
)
|
||||||
|
|
||||||
|
new_settings = ssh_actions.get_ssh_settings()
|
||||||
|
|
||||||
|
return SSHSettingsMutationReturn(
|
||||||
|
success=True,
|
||||||
|
message="SSH settings changed",
|
||||||
|
code=200,
|
||||||
|
enable=new_settings.enable,
|
||||||
|
password_authentication=new_settings.passwordAuthentication,
|
||||||
|
)
|
||||||
|
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def run_system_rebuild(self) -> GenericMutationReturn:
|
def run_system_rebuild(self) -> GenericMutationReturn:
|
||||||
system_actions.rebuild_system()
|
system_actions.rebuild_system()
|
||||||
|
|
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
from tests.common import read_json
|
from tests.common import read_json
|
||||||
from tests.test_graphql.common import assert_empty
|
from tests.test_graphql.common import assert_empty
|
||||||
|
from selfprivacy_api.graphql.mutations.system_mutations import SystemMutations
|
||||||
|
|
||||||
|
|
||||||
class ProcessMock:
|
class ProcessMock:
|
||||||
|
@ -59,6 +60,38 @@ mutation addSshKey($sshInput: SshMutationInput!) {
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
API_SET_SSH_SETTINGS = """
|
||||||
|
mutation enableSsh($sshInput: SSHSettingsInput!) {
|
||||||
|
system {
|
||||||
|
changeSshSettings(sshInput: $sshInput) {
|
||||||
|
success
|
||||||
|
message
|
||||||
|
code
|
||||||
|
enable
|
||||||
|
password_authentication
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def test_graphql_change_ssh_settings_unauthorized(
|
||||||
|
client, some_users, mock_subprocess_popen
|
||||||
|
):
|
||||||
|
response = client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_SET_SSH_SETTINGS,
|
||||||
|
"variables": {
|
||||||
|
"sshInput": {
|
||||||
|
"enable": True,
|
||||||
|
"passwordAuthentication": True,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert_empty(response)
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_add_ssh_key_unauthorized(client, some_users, mock_subprocess_popen):
|
def test_graphql_add_ssh_key_unauthorized(client, some_users, mock_subprocess_popen):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
|
|
Loading…
Reference in a new issue