connection_test.py (1990B)
1 #!/usr/bin/python3 2 3 import unittest 4 import sys 5 6 sys.path.append('../util') 7 import iwd 8 from iwd import IWD 9 from iwd import PSKAgent 10 from iwd import NetworkType 11 from hostapd import HostapdCLI 12 13 class Test(unittest.TestCase): 14 15 def test_connection_success(self): 16 hostapd = HostapdCLI(config='ssidCCMP.conf') 17 18 wd = IWD() 19 20 psk_agent = PSKAgent("secret123") 21 wd.register_psk_agent(psk_agent) 22 23 devices = wd.list_devices(1) 24 device = devices[0] 25 26 ordered_network = device.get_ordered_network('ssidCCMP') 27 28 self.assertEqual(ordered_network.type, NetworkType.psk) 29 30 condition = 'not obj.connected' 31 wd.wait_for_object_condition(ordered_network.network_object, condition) 32 33 ordered_network.network_object.connect() 34 35 condition = 'obj.state == DeviceState.connected' 36 wd.wait_for_object_condition(device, condition) 37 38 # Make AP go down ungracefully, when hostapd comes back up it should 39 # send an unprotected disassociate frame so the client will re-auth. 40 # This will kick off the SA Query procedure 41 hostapd.interface.set_interface_state('down') 42 hostapd.interface.set_interface_state('up') 43 44 hostapd.wait_for_event('INTERFACE-ENABLED') 45 46 condition = 'not obj.connected' 47 wd.wait_for_object_condition(ordered_network.network_object, condition) 48 49 # IWD should now try and re-connect to the AP 50 51 condition = 'obj.state == DeviceState.connected' 52 wd.wait_for_object_condition(device, condition) 53 54 hostapd.wait_for_event('AP-STA-CONNECTED') 55 56 device.disconnect() 57 58 condition = 'not obj.connected' 59 wd.wait_for_object_condition(ordered_network.network_object, condition) 60 61 wd.unregister_psk_agent(psk_agent) 62 63 @classmethod 64 def setUpClass(cls): 65 pass 66 67 @classmethod 68 def tearDownClass(cls): 69 IWD.clear_storage() 70 71 if __name__ == '__main__': 72 unittest.main(exit=True)