]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: add test for an invalid captive portal uri 28245/head
authorRonan Pigott <ronan@rjp.ie>
Mon, 3 Jul 2023 20:15:47 +0000 (13:15 -0700)
committerRonan Pigott <ronan@rjp.ie>
Mon, 3 Jul 2023 20:47:12 +0000 (13:47 -0700)
This could probably be extended to include many more invalid uri

test/test-network/systemd-networkd-tests.py

index 902614712e8e4d2935ab5aacbd2c090bba6665a6..be3ac6721616e1a4d4b4f5b90f656944cb9b8cb4 100755 (executable)
@@ -5202,6 +5202,44 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         check(self, False, True)
         check(self, False, False)
 
+    def test_dhcp_client_reject_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)
+            self.assertNotIn('Captive Portal: ', output)
+            self.assertNotIn('invalid/url', 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'])
+        masq = lambda bs: ':'.join(f'{b:02x}' for b in bs)
+        start_dnsmasq('--dhcp-option=114,' + masq(b'http://\x00invalid/url'),
+                      '--dhcp-option=option6:103,' + masq(b'http://\x00/invalid/url'))
+
+        check(self, True, True)
+        check(self, True, False)
+        check(self, False, True)
+        check(self, False, False)
+
 class NetworkdDHCPPDTests(unittest.TestCase, Utilities):
 
     def setUp(self):