From 1951438f20fc0966209504b10884e639b0e53a9a Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 1 Jul 2022 22:02:44 +0200 Subject: [PATCH] add tests for nsd --- .../2022.03.08/nsd/dictionaries/20_nsd.xml | 1 + .../2022.03.08/nsd/templates/nsd.yml | 12 ++++++++++++ seed/applicationservice/2022.03.08/nsd/tests/FIXME | 1 + .../2022.03.08/nsd/tests/test_dns.py | 14 ++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 seed/applicationservice/2022.03.08/nsd/templates/nsd.yml create mode 100644 seed/applicationservice/2022.03.08/nsd/tests/FIXME create mode 100644 seed/applicationservice/2022.03.08/nsd/tests/test_dns.py diff --git a/seed/applicationservice/2022.03.08/nsd/dictionaries/20_nsd.xml b/seed/applicationservice/2022.03.08/nsd/dictionaries/20_nsd.xml index dd159d28..52800f0f 100644 --- a/seed/applicationservice/2022.03.08/nsd/dictionaries/20_nsd.xml +++ b/seed/applicationservice/2022.03.08/nsd/dictionaries/20_nsd.xml @@ -11,6 +11,7 @@ nsd_reverse_filenames_signed /sysusers.d/0nsd.conf /tmpfiles.d/0nsd.conf + /tests/nsd.yml diff --git a/seed/applicationservice/2022.03.08/nsd/templates/nsd.yml b/seed/applicationservice/2022.03.08/nsd/templates/nsd.yml new file mode 100644 index 00000000..c0809d03 --- /dev/null +++ b/seed/applicationservice/2022.03.08/nsd/templates/nsd.yml @@ -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 diff --git a/seed/applicationservice/2022.03.08/nsd/tests/FIXME b/seed/applicationservice/2022.03.08/nsd/tests/FIXME new file mode 100644 index 00000000..d69f34e4 --- /dev/null +++ b/seed/applicationservice/2022.03.08/nsd/tests/FIXME @@ -0,0 +1 @@ +python3-dnspython diff --git a/seed/applicationservice/2022.03.08/nsd/tests/test_dns.py b/seed/applicationservice/2022.03.08/nsd/tests/test_dns.py new file mode 100644 index 00000000..2eca07c9 --- /dev/null +++ b/seed/applicationservice/2022.03.08/nsd/tests/test_dns.py @@ -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}}"