1# Test whether DNS resolving returns multiple records and all address families.
2import ./make-test-python.nix ({ pkgs, ... } : {
3 name = "resolv";
4 meta = with pkgs.lib.maintainers; {
5 maintainers = [ ckauhaus ];
6 };
7
8 nodes.resolv = { ... }: {
9 networking.extraHosts = ''
10 # IPv4 only
11 192.0.2.1 host-ipv4.example.net
12 192.0.2.2 host-ipv4.example.net
13 # IP6 only
14 2001:db8::2:1 host-ipv6.example.net
15 2001:db8::2:2 host-ipv6.example.net
16 # dual stack
17 192.0.2.1 host-dual.example.net
18 192.0.2.2 host-dual.example.net
19 2001:db8::2:1 host-dual.example.net
20 2001:db8::2:2 host-dual.example.net
21 '';
22 };
23
24 testScript = ''
25 def addrs_in(hostname, addrs):
26 res = resolv.succeed("getent ahosts {}".format(hostname))
27 for addr in addrs:
28 assert addr in res, "Expected output '{}' not found in\n{}".format(addr, res)
29
30
31 start_all()
32 resolv.wait_for_unit("nscd")
33
34 ipv4 = ["192.0.2.1", "192.0.2.2"]
35 ipv6 = ["2001:db8::2:1", "2001:db8::2:2"]
36
37 with subtest("IPv4 resolves"):
38 addrs_in("host-ipv4.example.net", ipv4)
39
40 with subtest("IPv6 resolves"):
41 addrs_in("host-ipv6.example.net", ipv6)
42
43 with subtest("Dual stack resolves"):
44 addrs_in("host-dual.example.net", ipv4 + ipv6)
45 '';
46})