mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-10-18 11:52:43 +00:00
fix: duplicate DNS records + add new test case
This commit is contained in:
parent
77eaa181ca
commit
11e020c0e1
|
@ -61,26 +61,8 @@ class ServiceManager(Service):
|
||||||
def get_all_required_dns_records() -> list[ServiceDnsRecord]:
|
def get_all_required_dns_records() -> list[ServiceDnsRecord]:
|
||||||
ip4 = network_utils.get_ip4()
|
ip4 = network_utils.get_ip4()
|
||||||
ip6 = network_utils.get_ip6()
|
ip6 = network_utils.get_ip6()
|
||||||
dns_records: list[ServiceDnsRecord] = [
|
dns_records: list[ServiceDnsRecord] = []
|
||||||
ServiceDnsRecord(
|
|
||||||
type="A",
|
|
||||||
name="api",
|
|
||||||
content=ip4,
|
|
||||||
ttl=3600,
|
|
||||||
display_name="SelfPrivacy API",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
if ip6 is not None:
|
|
||||||
dns_records.append(
|
|
||||||
ServiceDnsRecord(
|
|
||||||
type="AAAA",
|
|
||||||
name="api",
|
|
||||||
content=ip6,
|
|
||||||
ttl=3600,
|
|
||||||
display_name="SelfPrivacy API (IPv6)",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
for service in ServiceManager.get_enabled_services():
|
for service in ServiceManager.get_enabled_services():
|
||||||
dns_records += service.get_dns_records(ip4, ip6)
|
dns_records += service.get_dns_records(ip4, ip6)
|
||||||
return dns_records
|
return dns_records
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
# pylint: disable=missing-function-docstring
|
# pylint: disable=missing-function-docstring
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
import json
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
from selfprivacy_api.graphql.queries.providers import DnsProvider
|
from selfprivacy_api.graphql.queries.providers import DnsProvider
|
||||||
|
|
||||||
|
@ -354,6 +356,31 @@ def test_graphql_get_domain(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dns_records_no_duplicates(
|
||||||
|
authorized_client, mock_get_ip4, mock_get_ip6, turned_on, mock_dkim_key
|
||||||
|
):
|
||||||
|
"""Check for duplicate DNS records"""
|
||||||
|
response = authorized_client.post(
|
||||||
|
"/graphql",
|
||||||
|
json={
|
||||||
|
"query": generate_system_query([API_GET_DOMAIN_INFO]),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
dns_records = response.json()["data"]["system"]["domainInfo"]["requiredDnsRecords"]
|
||||||
|
|
||||||
|
serialized_records = [json.dumps(record, sort_keys=True) for record in dns_records]
|
||||||
|
|
||||||
|
record_counts = Counter(serialized_records)
|
||||||
|
duplicates = [
|
||||||
|
json.loads(record) for record, count in record_counts.items() if count > 1
|
||||||
|
]
|
||||||
|
|
||||||
|
assert len(duplicates) == 0, f"Found duplicate DNS records: {duplicates}"
|
||||||
|
|
||||||
|
|
||||||
def test_graphql_get_domain_no_dkim(
|
def test_graphql_get_domain_no_dkim(
|
||||||
authorized_client,
|
authorized_client,
|
||||||
mock_get_ip4,
|
mock_get_ip4,
|
||||||
|
|
Loading…
Reference in a new issue