mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-09 20:53:10 +00:00
test(system): dns migration
This commit is contained in:
parent
77fb99d84e
commit
68d0ee8c5d
|
@ -55,7 +55,7 @@ class SSHSettingsInput:
|
|||
|
||||
|
||||
@strawberry.input
|
||||
class SetDNSProviderInput:
|
||||
class SetDnsProviderInput:
|
||||
"""Input type to set the provider"""
|
||||
|
||||
provider: DnsProvider
|
||||
|
@ -225,7 +225,7 @@ class SystemMutations:
|
|||
)
|
||||
|
||||
@strawberry.mutation(permission_classes=[IsAuthenticated])
|
||||
def set_dns_provider(self, input: SetDNSProviderInput) -> GenericMutationReturn:
|
||||
def set_dns_provider(self, input: SetDnsProviderInput) -> GenericMutationReturn:
|
||||
|
||||
try:
|
||||
set_dns_provider(input.provider, input.api_token)
|
||||
|
|
|
@ -4,9 +4,17 @@
|
|||
import os
|
||||
import pytest
|
||||
|
||||
from selfprivacy_api.graphql.queries.providers import DnsProvider
|
||||
|
||||
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_system import assert_provider
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -123,6 +131,23 @@ def mock_dkim_key(mocker):
|
|||
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 = """
|
||||
info {
|
||||
pythonVersion
|
||||
|
@ -1002,3 +1027,46 @@ def test_graphql_pull_system_broken_repo(
|
|||
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[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
|
||||
|
||||
|
||||
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):
|
||||
token = "testytesty"
|
||||
provider = DnsProvider.DESEC
|
||||
|
||||
set_dns_provider(provider, token)
|
||||
|
||||
with ReadUserData() as user_data:
|
||||
assert user_data["dns"]["provider"] == "DESEC"
|
||||
with ReadUserData(file_type=UserDataFiles.SECRETS) as secrets:
|
||||
assert secrets["dns"]["apiKey"] == token
|
||||
assert_provider(provider.value, token)
|
||||
|
||||
|
||||
# uname is just an arbitrary command expected to be everywhere we care
|
||||
|
|
Loading…
Reference in a new issue