dataset/seed/nsd/tests/test_dns.py

21 lines
809 B
Python
Raw Permalink Normal View History

2022-07-01 22:02:44 +02:00
# DNSSEC : https://github.com/wubo1994/DNS-resolver-in-python3/blob/master/dnssec.py
# python3-pytest python3-yaml
from yaml import load, SafeLoader
2022-07-01 22:02:44 +02:00
from dns.resolver import Resolver
from os import environ
2022-07-01 22:02:44 +02:00
def test_nsd():
if 'MACHINE_TEST_DIR' not in environ:
return
conf_file = f'{environ["MACHINE_TEST_DIR"]}/nsd.yml'
with open(conf_file) as yaml:
data = load(yaml, Loader=SafeLoader)
2022-07-01 22:02:44 +02:00
resolver = Resolver()
resolver.nameservers = [data['address']]
for dns, ip in data['records'].items():
records = resolver.resolve(dns, 'A')
ips = [record.address for record in records]
assert len(ips) == 1, f"le domaine {dns} n'a pas qu'une ip {ips}"
assert ips[0] == ip, f"l'IP du domaine {dns} n'est pas correct, attendu : {ip}, obtenu {ips[0]}"