2022-07-01 22:02:44 +02:00
|
|
|
# DNSSEC : https://github.com/wubo1994/DNS-resolver-in-python3/blob/master/dnssec.py
|
2022-07-04 15:44:18 +02:00
|
|
|
# python3-pytest python3-yaml
|
|
|
|
from yaml import load, SafeLoader
|
2022-07-01 22:02:44 +02:00
|
|
|
from dns.resolver import Resolver
|
2022-07-04 15:44:18 +02:00
|
|
|
from os import environ
|
2022-07-01 22:02:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_nsd():
|
2022-07-04 15:44:18 +02:00
|
|
|
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}"
|
2022-07-04 15:44:18 +02:00
|
|
|
assert ips[0] == ip, f"l'IP du domaine {dns} n'est pas correct, attendu : {ip}, obtenu {ips[0]}"
|