parent
918c2ca01a
commit
8d36536c2e
|
@ -21,57 +21,26 @@ import ./make-test-python.nix ({ pkgs, ... } : {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = let
|
testScript = ''
|
||||||
getaddrinfo_py = pkgs.writeScript "getaddrinfo.py" ''
|
def addrs_in(hostname, addrs):
|
||||||
import socket
|
res = resolv.succeed("getent ahosts {}".format(hostname))
|
||||||
import sys
|
for addr in addrs:
|
||||||
|
assert addr in res, "Expected output '{}' not found in\n{}".format(addr, res)
|
||||||
result = set()
|
|
||||||
for gai in socket.getaddrinfo(sys.argv[1], 0):
|
|
||||||
result.add(gai[4][0])
|
|
||||||
|
|
||||||
print(' '.join(sorted(list(result))))
|
|
||||||
'';
|
|
||||||
|
|
||||||
getaddrinfo = "${pkgs.python3.interpreter} ${getaddrinfo_py}";
|
|
||||||
|
|
||||||
in
|
|
||||||
''
|
|
||||||
def compare(test, should, is_):
|
|
||||||
should = should.strip()
|
|
||||||
is_ = is_.strip()
|
|
||||||
resolv.log("{}: expected '{}', actual '{}'".format(test, should, is_))
|
|
||||||
if should == is_:
|
|
||||||
resolv.log("* OK")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
resolv.log("* FAILED")
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
start_all()
|
start_all()
|
||||||
resolv.wait_for_unit("nscd")
|
resolv.wait_for_unit("nscd")
|
||||||
res = []
|
|
||||||
|
|
||||||
out = resolv.succeed(
|
ipv4 = ["192.0.2.1", "192.0.2.2"]
|
||||||
"${getaddrinfo} host-ipv4.example.net"
|
ipv6 = ["2001:db8::2:1", "2001:db8::2:2"]
|
||||||
)
|
|
||||||
res.append(compare("resolve IPv4", "192.0.2.1 192.0.2.2", out))
|
|
||||||
|
|
||||||
out = resolv.succeed(
|
with subtest("IPv4 resolves"):
|
||||||
"${getaddrinfo} host-ipv6.example.net"
|
addrs_in("host-ipv4.example.net", ipv4)
|
||||||
)
|
|
||||||
res.append(compare("resolve IPv6", "2001:db8::2:1 2001:db8::2:2", out))
|
|
||||||
|
|
||||||
out = resolv.succeed(
|
with subtest("IPv6 resolves"):
|
||||||
"${getaddrinfo} host-dual.example.net"
|
addrs_in("host-ipv6.example.net", ipv6)
|
||||||
)
|
|
||||||
res.append(
|
|
||||||
compare(
|
|
||||||
"resolve dual stack", "192.0.2.1 192.0.2.2 2001:db8::2:1 2001:db8::2:2", out
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
assert all(res) is True
|
with subtest("Dual stack resolves"):
|
||||||
|
addrs_in("host-dual.example.net", ipv4 + ipv6)
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue