add tests for nsd

This commit is contained in:
Emmanuel Garette 2022-07-01 22:02:44 +02:00
parent 6dd625670e
commit 1951438f20
4 changed files with 28 additions and 0 deletions

View file

@ -11,6 +11,7 @@
<file file_type="variable" source="nsd.signed" variable="nsd_reverse_filenames">nsd_reverse_filenames_signed</file> <file file_type="variable" source="nsd.signed" variable="nsd_reverse_filenames">nsd_reverse_filenames_signed</file>
<file engine="none" source="sysuser-nsd.conf">/sysusers.d/0nsd.conf</file> <file engine="none" source="sysuser-nsd.conf">/sysusers.d/0nsd.conf</file>
<file engine="none" source="tmpfile-nsd.conf">/tmpfiles.d/0nsd.conf</file> <file engine="none" source="tmpfile-nsd.conf">/tmpfiles.d/0nsd.conf</file>
<file>/tests/nsd.yml</file>
</service> </service>
</services> </services>
<variables> <variables>

View file

@ -0,0 +1,12 @@
address: '%%ip_eth0'
records:
%for %%domain in %%nsd_zones_all
%set %%suffix = %%normalize_family(%%domain)
%set %%hostnames = %%nsd["nsd_zone_" + %%suffix]["hostname_" + %%suffix]["hostname_" + %%suffix]
%for %%nsd in %%hostnames
%set %%type = %%nsd['type_' + %%suffix]
%if %%type == 'A'
%%{nsd}.%%domain: '%%nsd['ip_' + %%suffix]'
%end if
%end for
%end for

View file

@ -0,0 +1 @@
python3-dnspython

View file

@ -0,0 +1,14 @@
# DNSSEC : https://github.com/wubo1994/DNS-resolver-in-python3/blob/master/dnssec.py
from yaml import loads
from dns.resolver import Resolver
def test_nsd():
data = loads('./nsd.yml')
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}}"