From 2c0bb06d1a664b21cdf446a4dfd6995f720d42be Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Thu, 16 Jun 2022 02:02:28 +0200 Subject: [PATCH] auto-t: Verify DNS entries added from DHCP/static Add a fake resolvconf executable to verify that the right nameserver addresses were actually committed by iwd. Again use unique nameserver addresses to reduce the possibility that the test succeeds by pure luck. --- autotests/testNetconfig/connection_test.py | 15 ++++++++++++++- autotests/testNetconfig/dhcpd-v6.conf | 2 +- autotests/testNetconfig/dhcpd.conf | 2 +- autotests/testNetconfig/main.conf | 2 +- autotests/testNetconfig/resolvconf | 2 ++ autotests/testNetconfig/ssidTKIP.psk | 2 ++ autotests/testNetconfig/static_test.py | 15 ++++++++++++++- 7 files changed, 35 insertions(+), 5 deletions(-) create mode 100755 autotests/testNetconfig/resolvconf diff --git a/autotests/testNetconfig/connection_test.py b/autotests/testNetconfig/connection_test.py index db3327ef..4b05c745 100644 --- a/autotests/testNetconfig/connection_test.py +++ b/autotests/testNetconfig/connection_test.py @@ -77,6 +77,14 @@ class Test(unittest.TestCase): self.assertEqual(expected_routes4, set(testutil.get_routes4(ifname))) self.assertEqual(expected_routes6, set(testutil.get_routes6(ifname))) + rclog = open('/tmp/resolvconf.log', 'r') + entries = rclog.readlines() + rclog.close() + expected_rclog = ['-a wlan1.dns\n', 'nameserver 192.168.1.2\n', 'nameserver 3ffe:501:ffff:100::2\n'] + # Every real resolvconf -a run overwrites the previous settings. Check the last three lines + # of our log since we care about the end result here. + self.assertEqual(expected_rclog, entries[-3:]) + device.disconnect() condition = 'not obj.connected' @@ -133,6 +141,10 @@ class Test(unittest.TestCase): config.close() cls.radvd_pid = ctx.start_process(['radvd', '-n', '-d5', '-p', '/tmp/radvd.pid', '-C', '/tmp/radvd.conf']) + cls.orig_path = os.environ['PATH'] + os.environ['PATH'] = '/tmp/test-bin:' + os.environ['PATH'] + IWD.copy_to_storage('resolvconf', '/tmp/test-bin') + @classmethod def tearDownClass(cls): IWD.clear_storage() @@ -142,7 +154,8 @@ class Test(unittest.TestCase): cls.dhcpd6_pid = None ctx.stop_process(cls.radvd_pid) cls.radvd_pid = None - os.remove('/tmp/radvd.conf') + os.system('rm -rf /tmp/radvd.conf /tmp/resolvconf.log /tmp/test-bin') + os.environ['PATH'] = cls.orig_path if __name__ == '__main__': unittest.main(exit=True) diff --git a/autotests/testNetconfig/dhcpd-v6.conf b/autotests/testNetconfig/dhcpd-v6.conf index 917ee8a3..45057ab8 100644 --- a/autotests/testNetconfig/dhcpd-v6.conf +++ b/autotests/testNetconfig/dhcpd-v6.conf @@ -1,6 +1,6 @@ subnet6 3ffe:501:ffff:100::/72 { - option dhcp6.name-servers 3ffe:501:ffff:100::1; + option dhcp6.name-servers 3ffe:501:ffff:100::2; range6 3ffe:501:ffff:100::10 3ffe:501:ffff:100::20; range6 3ffe:501:ffff:100::100 3ffe:501:ffff:100::200; } diff --git a/autotests/testNetconfig/dhcpd.conf b/autotests/testNetconfig/dhcpd.conf index ea9957a3..d8a9d24c 100644 --- a/autotests/testNetconfig/dhcpd.conf +++ b/autotests/testNetconfig/dhcpd.conf @@ -9,7 +9,7 @@ subnet 192.168.0.0 netmask 255.255.128.0 { option routers 192.168.1.1; option subnet-mask 255.255.128.0; - option domain-name-servers 192.168.1.1; + option domain-name-servers 192.168.1.2; range 192.168.1.10 192.168.1.20; range 192.168.1.100 192.168.1.200; } diff --git a/autotests/testNetconfig/main.conf b/autotests/testNetconfig/main.conf index 1ffe2be1..8641a390 100644 --- a/autotests/testNetconfig/main.conf +++ b/autotests/testNetconfig/main.conf @@ -3,4 +3,4 @@ EnableNetworkConfiguration=true [Network] EnableIPv6=true -NameResolvingService=none +NameResolvingService=resolvconf diff --git a/autotests/testNetconfig/resolvconf b/autotests/testNetconfig/resolvconf new file mode 100755 index 00000000..7c56c616 --- /dev/null +++ b/autotests/testNetconfig/resolvconf @@ -0,0 +1,2 @@ +#! /bin/sh +(echo "$*" ; [ "$1" = -a ] && cat) >> /tmp/resolvconf.log 2> /dev/null diff --git a/autotests/testNetconfig/ssidTKIP.psk b/autotests/testNetconfig/ssidTKIP.psk index e371c97f..032e2185 100644 --- a/autotests/testNetconfig/ssidTKIP.psk +++ b/autotests/testNetconfig/ssidTKIP.psk @@ -4,11 +4,13 @@ Address=192.168.1.10 Netmask=255.255.255.128 Gateway=192.168.1.3 +DNS=192.168.1.4 [IPv6] # Use a different subnet than DHCP on purpose Address=3ffe:501:ffff:200::10/80 Gateway=3ffe:501:ffff:200::3 +DNS=3ffe:501:ffff:200::4 [Settings] AutoConnect=false diff --git a/autotests/testNetconfig/static_test.py b/autotests/testNetconfig/static_test.py index cd147894..ac525b28 100644 --- a/autotests/testNetconfig/static_test.py +++ b/autotests/testNetconfig/static_test.py @@ -72,6 +72,14 @@ class Test(unittest.TestCase): self.assertEqual(expected_routes4, set(testutil.get_routes4(ifname))) self.assertEqual(expected_routes6, set(testutil.get_routes6(ifname))) + rclog = open('/tmp/resolvconf.log', 'r') + entries = rclog.readlines() + rclog.close() + expected_rclog = ['-a wlan1.dns\n', 'nameserver 192.168.1.4\n', 'nameserver 3ffe:501:ffff:200::4\n'] + # Every resolvconf -a run overwrites the previous settings. Check the last three lines + # of the log since we care about the end result here. + self.assertEqual(expected_rclog, entries[-3:]) + ordered_network = dev2.get_ordered_network('ssidTKIP') condition = 'not obj.connected' @@ -121,10 +129,15 @@ class Test(unittest.TestCase): hapd.ifname], cleanup=remove_lease) IWD.copy_to_storage('ssidTKIP.psk', '/tmp/storage') + cls.orig_path = os.environ['PATH'] + os.environ['PATH'] = '/tmp/test-bin:' + os.environ['PATH'] + IWD.copy_to_storage('resolvconf', '/tmp/test-bin') + @classmethod def tearDownClass(cls): - IWD.clear_storage(storage_dir='/tmp/storage') cls.dhcpd_pid.kill() + os.system('rm -rf /tmp/resolvconf.log /tmp/test-bin /tmp/storage') + os.environ['PATH'] = cls.orig_path if __name__ == '__main__': unittest.main(exit=True)