mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-10 04:53:11 +00:00
test(system): dns migration
This commit is contained in:
parent
77fb99d84e
commit
68d0ee8c5d
|
@ -55,7 +55,7 @@ class SSHSettingsInput:
|
||||||
|
|
||||||
|
|
||||||
@strawberry.input
|
@strawberry.input
|
||||||
class SetDNSProviderInput:
|
class SetDnsProviderInput:
|
||||||
"""Input type to set the provider"""
|
"""Input type to set the provider"""
|
||||||
|
|
||||||
provider: DnsProvider
|
provider: DnsProvider
|
||||||
|
@ -225,7 +225,7 @@ class SystemMutations:
|
||||||
)
|
)
|
||||||
|
|
||||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||||
def set_dns_provider(self, input: SetDNSProviderInput) -> GenericMutationReturn:
|
def set_dns_provider(self, input: SetDnsProviderInput) -> GenericMutationReturn:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
set_dns_provider(input.provider, input.api_token)
|
set_dns_provider(input.provider, input.api_token)
|
||||||
|
|
|
@ -4,9 +4,17 @@
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from selfprivacy_api.graphql.queries.providers import DnsProvider
|
||||||
|
|
||||||
from tests.common import generate_system_query, read_json
|
from tests.common import generate_system_query, read_json
|
||||||
from tests.test_graphql.common import assert_empty
|
from tests.test_graphql.common import (
|
||||||
|
assert_empty,
|
||||||
|
assert_ok,
|
||||||
|
assert_errorcode,
|
||||||
|
get_data,
|
||||||
|
)
|
||||||
from tests.test_dkim import no_dkim_file, dkim_file
|
from tests.test_dkim import no_dkim_file, dkim_file
|
||||||
|
from tests.test_system import assert_provider
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -123,6 +131,23 @@ def mock_dkim_key(mocker):
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
||||||
|
def api_set_dns_provider_raw(authorized_client, provider: str, token: str):
|
||||||
|
response = authorized_client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": API_SET_DNS_PROVIDER_MUTATION,
|
||||||
|
"variables": {
|
||||||
|
"input": {"provider": provider, "apiToken": token},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def api_set_dns_provider(authorized_client, provider: DnsProvider, token: str):
|
||||||
|
return api_set_dns_provider_raw(authorized_client, provider.value, token)
|
||||||
|
|
||||||
|
|
||||||
API_PYTHON_VERSION_INFO = """
|
API_PYTHON_VERSION_INFO = """
|
||||||
info {
|
info {
|
||||||
pythonVersion
|
pythonVersion
|
||||||
|
@ -1002,3 +1027,46 @@ def test_graphql_pull_system_broken_repo(
|
||||||
assert mock_os_chdir.call_count == 2
|
assert mock_os_chdir.call_count == 2
|
||||||
assert mock_os_chdir.call_args_list[0][0][0] == "/etc/nixos"
|
assert mock_os_chdir.call_args_list[0][0][0] == "/etc/nixos"
|
||||||
assert mock_os_chdir.call_args_list[1][0][0] == current_dir
|
assert mock_os_chdir.call_args_list[1][0][0] == current_dir
|
||||||
|
|
||||||
|
|
||||||
|
API_SET_DNS_PROVIDER_MUTATION = """
|
||||||
|
mutation TestSetDnsProvider($input: SetDnsProviderInput!) {
|
||||||
|
system {
|
||||||
|
setDnsProvider(input: $input) {
|
||||||
|
success
|
||||||
|
message
|
||||||
|
code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_dns_provider(authorized_client, generic_userdata):
|
||||||
|
provider = DnsProvider.DIGITALOCEAN
|
||||||
|
token = "someRandomToken"
|
||||||
|
|
||||||
|
response = api_set_dns_provider(authorized_client, provider, token)
|
||||||
|
data = get_data(response)["system"]["setDnsProvider"]
|
||||||
|
assert_ok(data)
|
||||||
|
assert_provider(provider.value, token)
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_dns_provider_nonexistent(authorized_client, generic_userdata):
|
||||||
|
provider = "BOGUSINC"
|
||||||
|
token = "someRandomToken"
|
||||||
|
|
||||||
|
response = api_set_dns_provider_raw(authorized_client, provider, token)
|
||||||
|
assert_empty(response)
|
||||||
|
|
||||||
|
# Test that nothing has indeed changed
|
||||||
|
with pytest.raises(AssertionError):
|
||||||
|
assert_provider(provider, token)
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_dns_provider_unauthorized(client, generic_userdata):
|
||||||
|
provider = DnsProvider.DIGITALOCEAN
|
||||||
|
token = "someRandomToken"
|
||||||
|
|
||||||
|
response = api_set_dns_provider(client, provider, token)
|
||||||
|
assert_empty(response)
|
||||||
|
|
|
@ -6,16 +6,20 @@ from selfprivacy_api.actions.system import set_dns_provider
|
||||||
from selfprivacy_api.graphql.queries.providers import DnsProvider
|
from selfprivacy_api.graphql.queries.providers import DnsProvider
|
||||||
|
|
||||||
|
|
||||||
|
def assert_provider(provider_str: str, key: str):
|
||||||
|
with ReadUserData() as user_data:
|
||||||
|
assert user_data["dns"]["provider"] == provider_str
|
||||||
|
with ReadUserData(file_type=UserDataFiles.SECRETS) as secrets:
|
||||||
|
assert secrets["dns"]["apiKey"] == key
|
||||||
|
|
||||||
|
|
||||||
def test_set_dns(generic_userdata):
|
def test_set_dns(generic_userdata):
|
||||||
token = "testytesty"
|
token = "testytesty"
|
||||||
provider = DnsProvider.DESEC
|
provider = DnsProvider.DESEC
|
||||||
|
|
||||||
set_dns_provider(provider, token)
|
set_dns_provider(provider, token)
|
||||||
|
|
||||||
with ReadUserData() as user_data:
|
assert_provider(provider.value, token)
|
||||||
assert user_data["dns"]["provider"] == "DESEC"
|
|
||||||
with ReadUserData(file_type=UserDataFiles.SECRETS) as secrets:
|
|
||||||
assert secrets["dns"]["apiKey"] == token
|
|
||||||
|
|
||||||
|
|
||||||
# uname is just an arbitrary command expected to be everywhere we care
|
# uname is just an arbitrary command expected to be everywhere we care
|
||||||
|
|
Loading…
Reference in a new issue