test-network: add test for an invalid captive portal uri

This could probably be extended to include many more invalid uri
This commit is contained in:
Ronan Pigott
2023-07-03 13:15:47 -07:00
parent 46bc8561f0
commit 1219391c9f

View File

@@ -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):