fix: duplicate DNS records + add new test case

This commit is contained in:
dettlaff 2024-10-02 16:54:41 +04:00 committed by Inex Code
parent 77eaa181ca
commit 11e020c0e1
2 changed files with 28 additions and 19 deletions

View file

@ -61,26 +61,8 @@ class ServiceManager(Service):
def get_all_required_dns_records() -> list[ServiceDnsRecord]:
ip4 = network_utils.get_ip4()
ip6 = network_utils.get_ip6()
dns_records: list[ServiceDnsRecord] = [
ServiceDnsRecord(
type="A",
name="api",
content=ip4,
ttl=3600,
display_name="SelfPrivacy API",
),
]
dns_records: list[ServiceDnsRecord] = []
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():
dns_records += service.get_dns_records(ip4, ip6)
return dns_records

View file

@ -3,6 +3,8 @@
# pylint: disable=missing-function-docstring
import os
import pytest
import json
from collections import Counter
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(
authorized_client,
mock_get_ip4,