hotspot_test.py (2428B)
1 #!/usr/bin/python3 2 3 import unittest 4 import sys 5 import os 6 7 sys.path.append('../util') 8 from iwd import IWD 9 from iwd import IWD_CONFIG_DIR 10 from iwd import PSKAgent 11 from iwd import NetworkType 12 from hostapd import HostapdCLI 13 import testutil 14 15 class Test(unittest.TestCase): 16 17 def validate_connection(self, wd, hapd, dgaf_disable=False): 18 psk_agent = PSKAgent('abc', ('domain\\user', 'testpasswd')) 19 wd.register_psk_agent(psk_agent) 20 21 devices = wd.list_devices(1) 22 device = devices[0] 23 24 ordered_network = device.get_ordered_network('Hotspot') 25 26 self.assertEqual(ordered_network.type, NetworkType.eap) 27 28 condition = 'not obj.connected' 29 wd.wait_for_object_condition(ordered_network.network_object, condition) 30 31 ordered_network.network_object.connect() 32 33 condition = 'obj.state == DeviceState.connected' 34 wd.wait_for_object_condition(device, condition) 35 36 testutil.test_iface_operstate() 37 38 if not dgaf_disable: 39 testutil.test_ifaces_connected(device.name, hapd.ifname) 40 else: 41 # This is expected to fail with group traffic 42 with self.assertRaises(Exception): 43 testutil.test_ifaces_connected(device.name, hapd.ifname, expect_fail=True) 44 45 # Now try again without testing group traffic 46 testutil.test_ifaces_connected(device.name, hapd.ifname, group=False) 47 48 device.disconnect() 49 50 condition = 'not obj.connected' 51 wd.wait_for_object_condition(ordered_network.network_object, condition) 52 53 wd.unregister_psk_agent(psk_agent) 54 55 def test_hotspot(self): 56 hapd = HostapdCLI(config='ssidHotspot.conf') 57 hapd.set_value('disable_dgaf', '0') 58 hapd.reload() 59 60 self.validate_connection(self.wd, hapd) 61 62 def test_dgaf_disabled(self): 63 hapd = HostapdCLI(config='ssidHotspot.conf') 64 hapd.set_value('disable_dgaf', '1') 65 hapd.reload() 66 67 self.validate_connection(self.wd, hapd, dgaf_disable=True) 68 69 @classmethod 70 def setUpClass(cls): 71 IWD.copy_to_hotspot('example.conf') 72 IWD.copy_to_storage('anqp_enabled.conf', storage_dir=IWD_CONFIG_DIR, name='main.conf') 73 74 cls.wd = IWD(True) 75 76 @classmethod 77 def tearDownClass(cls): 78 IWD.clear_storage() 79 os.remove('/tmp/main.conf') 80 81 cls.wd = None 82 83 if __name__ == '__main__': 84 unittest.main(exit=True)