connection_test.py (3287B)
1 #!/usr/bin/python3 2 3 import unittest 4 import sys 5 6 sys.path.append('../util') 7 from iwd import IWD 8 from iwd import PSKAgent 9 from iwd import NetworkType 10 from hostapd import HostapdCLI 11 import testutil 12 13 class Test(unittest.TestCase): 14 15 def validate_connection(self, wd, ssid, hostapd, expected_group): 16 psk_agent = PSKAgent("secret123") 17 wd.register_psk_agent(psk_agent) 18 19 devices = wd.list_devices(1) 20 self.assertIsNotNone(devices) 21 device = devices[0] 22 23 device.disconnect() 24 25 network = device.get_ordered_network(ssid, full_scan=True) 26 27 self.assertEqual(network.type, NetworkType.psk) 28 29 network.network_object.connect() 30 31 condition = 'obj.state == DeviceState.connected' 32 wd.wait_for_object_condition(device, condition) 33 34 wd.wait(2) 35 36 testutil.test_iface_operstate(intf=device.name) 37 testutil.test_ifaces_connected(if0=device.name, if1=hostapd.ifname) 38 39 # Initial connection PMKSA should not be used. So we should see the 40 # SAE group set. 41 sta_status = hostapd.sta_status(device.address) 42 self.assertEqual(int(sta_status["sae_group"]), expected_group) 43 44 device.disconnect() 45 46 condition = 'not obj.connected' 47 wd.wait_for_object_condition(network.network_object, condition) 48 49 wd.unregister_psk_agent(psk_agent) 50 51 network.network_object.connect(wait=False) 52 53 condition = 'obj.state == DeviceState.connected' 54 wd.wait_for_object_condition(device, condition) 55 56 wd.wait(2) 57 58 testutil.test_iface_operstate(intf=device.name) 59 testutil.test_ifaces_connected(if0=device.name, if1=hostapd.ifname) 60 61 # Having connected once prior we should have a PMKSA and SAE should not 62 # have been used. 63 sta_status = hostapd.sta_status(device.address) 64 self.assertNotIn("sae_group", sta_status.keys()) 65 66 device.disconnect() 67 68 condition = 'not obj.connected' 69 wd.wait_for_object_condition(network.network_object, condition) 70 71 hostapd.pmksa_flush() 72 73 wd.wait(5) 74 75 network.network_object.connect() 76 77 device.wait_for_event("pmksa-invalid-pmkid") 78 79 condition = 'obj.state == DeviceState.connected' 80 wd.wait_for_object_condition(device, condition) 81 82 wd.wait(2) 83 84 testutil.test_iface_operstate(intf=device.name) 85 testutil.test_ifaces_connected(if0=device.name, if1=hostapd.ifname) 86 87 # Manually flushing the PMKSA from the AP then reconnecting we should 88 # have failed (INVALID_PMKID) then retried the same BSS with SAE, not 89 # PMKSA. 90 sta_status = hostapd.sta_status(device.address) 91 self.assertEqual(int(sta_status["sae_group"]), expected_group) 92 93 def test_pmksa_sae(self): 94 self.hostapd.wait_for_event("AP-ENABLED") 95 self.validate_connection(self.wd, "ssidSAE", self.hostapd, 19) 96 97 def setUp(self): 98 self.hostapd.default() 99 self.wd = IWD(True) 100 101 def tearDown(self): 102 self.wd.clear_storage() 103 self.wd = None 104 105 @classmethod 106 def setUpClass(cls): 107 cls.hostapd = HostapdCLI(config='ssidSAE.conf') 108 109 @classmethod 110 def tearDownClass(cls): 111 pass 112 113 if __name__ == '__main__': 114 unittest.main(exit=True)