2021-11-23 14:31:53 +01:00
|
|
|
from app.dns_utils import (
|
|
|
|
get_mx_domains,
|
2024-09-17 16:15:10 +02:00
|
|
|
get_network_dns_client,
|
2021-11-23 14:31:53 +01:00
|
|
|
is_mx_equivalent,
|
2024-09-17 16:15:10 +02:00
|
|
|
InMemoryDNSClient,
|
2024-10-02 15:46:10 +02:00
|
|
|
MxRecord,
|
2021-11-23 14:31:53 +01:00
|
|
|
)
|
2020-01-05 19:01:38 +01:00
|
|
|
|
2024-09-17 16:15:10 +02:00
|
|
|
from tests.utils import random_domain
|
|
|
|
|
2020-01-05 19:01:38 +01:00
|
|
|
# use our own domain for test
|
|
|
|
_DOMAIN = "simplelogin.io"
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_mx_domains():
|
|
|
|
r = get_mx_domains(_DOMAIN)
|
|
|
|
|
|
|
|
assert len(r) > 0
|
|
|
|
|
|
|
|
for x in r:
|
2024-10-02 15:46:10 +02:00
|
|
|
assert x.priority > 0
|
|
|
|
assert x.domain
|
2020-01-05 19:01:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_spf_domain():
|
2024-09-17 16:15:10 +02:00
|
|
|
r = get_network_dns_client().get_spf_domain(_DOMAIN)
|
2020-01-05 19:01:38 +01:00
|
|
|
assert r == ["simplelogin.co"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_txt_record():
|
2024-09-17 16:15:10 +02:00
|
|
|
r = get_network_dns_client().get_txt_record(_DOMAIN)
|
2020-01-05 19:01:38 +01:00
|
|
|
assert len(r) > 0
|
2021-11-23 14:31:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_is_mx_equivalent():
|
|
|
|
assert is_mx_equivalent([], [])
|
|
|
|
assert is_mx_equivalent(
|
2024-10-02 15:46:10 +02:00
|
|
|
mx_domains=[MxRecord(1, "domain")], ref_mx_domains=[MxRecord(1, "domain")]
|
2021-11-23 14:31:53 +01:00
|
|
|
)
|
|
|
|
assert is_mx_equivalent(
|
2024-10-02 15:46:10 +02:00
|
|
|
mx_domains=[MxRecord(10, "domain1"), MxRecord(20, "domain2")],
|
|
|
|
ref_mx_domains=[MxRecord(10, "domain1"), MxRecord(20, "domain2")],
|
2021-11-23 14:31:53 +01:00
|
|
|
)
|
2022-02-24 17:25:48 +01:00
|
|
|
assert is_mx_equivalent(
|
2024-10-02 15:46:10 +02:00
|
|
|
mx_domains=[MxRecord(5, "domain1"), MxRecord(10, "domain2")],
|
|
|
|
ref_mx_domains=[MxRecord(10, "domain1"), MxRecord(20, "domain2")],
|
|
|
|
)
|
|
|
|
assert is_mx_equivalent(
|
|
|
|
mx_domains=[
|
|
|
|
MxRecord(5, "domain1"),
|
|
|
|
MxRecord(10, "domain2"),
|
|
|
|
MxRecord(20, "domain3"),
|
|
|
|
],
|
|
|
|
ref_mx_domains=[MxRecord(10, "domain1"), MxRecord(20, "domain2")],
|
2022-02-24 17:25:48 +01:00
|
|
|
)
|
|
|
|
assert not is_mx_equivalent(
|
2024-10-02 15:46:10 +02:00
|
|
|
mx_domains=[MxRecord(5, "domain1"), MxRecord(10, "domain2")],
|
|
|
|
ref_mx_domains=[
|
|
|
|
MxRecord(10, "domain1"),
|
|
|
|
MxRecord(20, "domain2"),
|
|
|
|
MxRecord(20, "domain3"),
|
|
|
|
],
|
2022-02-24 17:25:48 +01:00
|
|
|
)
|
2024-09-17 16:15:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_spf_record():
|
|
|
|
client = InMemoryDNSClient()
|
|
|
|
|
|
|
|
sl_domain = random_domain()
|
|
|
|
domain = random_domain()
|
|
|
|
|
|
|
|
spf_record = f"v=spf1 include:{sl_domain}"
|
|
|
|
client.set_txt_record(domain, [spf_record, "another record"])
|
|
|
|
res = client.get_spf_domain(domain)
|
|
|
|
assert res == [sl_domain]
|