From: Ronan Pigott Date: Thu, 29 Jun 2023 23:38:55 +0000 (-0700) Subject: test-network: add tests for captive portal dhcp options X-Git-Tag: v254-rc1~51^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dbe960f07fbb86f6fd614368db4cc860d468d44e;p=thirdparty%2Fsystemd.git test-network: add tests for captive portal dhcp options --- diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index b5ef83a9c08..681b14732a3 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -5135,6 +5135,45 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): check(self, False, True) check(self, False, False) + def test_dhcp_client_use_captive_portal(self): + def check(self, ipv4, ipv6): + os.makedirs(os.path.join(network_unit_dir, '25-dhcp-client.network.d'), exist_ok=True) + with open(os.path.join(network_unit_dir, '25-dhcp-client.network.d/override.conf'), mode='w', encoding='utf-8') as f: + f.write('[DHCPv4]\nUseCaptivePortal=') + f.write('yes' if ipv4 else 'no') + f.write('\n[DHCPv6]\nUseCaptivePortal=') + f.write('yes' if ipv6 else 'no') + f.write('\n[IPv6AcceptRA]\nUseCaptivePortal=no') + + networkctl_reload() + self.wait_online(['veth99:routable']) + + # link becomes 'routable' when at least one protocol provide an valid address. Hence, we need to explicitly wait for both addresses. + self.wait_address('veth99', r'inet 192.168.5.[0-9]*/24 metric 1024 brd 192.168.5.255 scope global dynamic', ipv='-4') + self.wait_address('veth99', r'inet6 2600::[0-9a-f]*/128 scope global (dynamic noprefixroute|noprefixroute dynamic)', ipv='-6') + + output = check_output(*networkctl_cmd, 'status', 'veth99', env=env) + print(output) + if ipv4 or ipv6: + self.assertIn('Captive Portal: http://systemd.io', output) + else: + self.assertNotIn('Captive Portal: http://systemd.io', output) + + # TODO: check json string + check_output(*networkctl_cmd, '--json=short', 'status', env=env) + + copy_network_unit('25-veth.netdev', '25-dhcp-server-veth-peer.network', '25-dhcp-client.network', copy_dropins=False) + + start_networkd() + self.wait_online(['veth-peer:carrier']) + start_dnsmasq('--dhcp-option=114,http://systemd.io', + '--dhcp-option=option6:103,http://systemd.io') + + check(self, True, True) + check(self, True, False) + check(self, False, True) + check(self, False, False) + class NetworkdDHCPPDTests(unittest.TestCase, Utilities): def setUp(self):