connection_test.py (5426B)
1 #! /usr/bin/python3 2 3 import unittest 4 import sys, os 5 6 sys.path.append('../util') 7 from iwd import IWD 8 from iwd import NetworkType 9 from hostapd import HostapdCLI 10 import testutil 11 12 class Test(unittest.TestCase): 13 def validate_connection(self, wd): 14 device = wd.list_devices(1)[0] 15 16 # Scanning is unavoidable in this case since both FILS-SHA256 and 17 # FILS-SHA384 are tested. Without a new scan the cached scan results 18 # would cause IWD to choose an incorrect AKM for the second test. 19 ordered_network = device.get_ordered_network('TestFT', full_scan=True) 20 21 self.assertEqual(ordered_network.type, NetworkType.eap) 22 23 self.assertFalse(self.bss_hostapd[0].list_sta()) 24 self.assertFalse(self.bss_hostapd[1].list_sta()) 25 26 device.connect_bssid(self.bss_hostapd[0].bssid) 27 28 condition = 'obj.state == DeviceState.connected' 29 wd.wait_for_object_condition(device, condition) 30 31 self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address) 32 33 self.assertFalse(self.bss_hostapd[1].list_sta()) 34 35 testutil.test_iface_operstate(device.name) 36 testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) 37 self.assertRaises(Exception, testutil.test_ifaces_connected, 38 (self.bss_hostapd[1].ifname, device.name, True, True)) 39 40 device.disconnect() 41 42 condition = 'not obj.connected' 43 wd.wait_for_object_condition(ordered_network.network_object, condition) 44 45 ordered_network = device.get_ordered_network('TestFT') 46 47 self.assertEqual(ordered_network.type, NetworkType.eap) 48 49 # TODO: verify FILS was actually used on this second connection 50 device.connect_bssid(self.bss_hostapd[0].bssid) 51 52 condition = 'obj.state == DeviceState.connected' 53 wd.wait_for_object_condition(device, condition) 54 55 self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address) 56 57 self.assertFalse(self.bss_hostapd[1].list_sta()) 58 59 testutil.test_iface_operstate(device.name) 60 testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) 61 self.assertRaises(Exception, testutil.test_ifaces_connected, 62 (self.bss_hostapd[1].ifname, device.name, True, True)) 63 64 # Check that iwd starts transition to BSS 1 in less than 10 seconds. 65 # The 10 seconds is longer than needed to scan on just two channels 66 # but short enough that a full scan on the 2.4 + 5.8 bands supported 67 # by mac80211_hwsim will not finish. If this times out then, but 68 # device_roam_trigger_cb has happened, it probably means that 69 # Neighbor Reports are broken. 70 #rule0.signal = -8000 71 device.roam(self.bss_hostapd[1].bssid) 72 73 # Check that iwd is on BSS 1 once out of roaming state and doesn't 74 # go through 'disconnected', 'autoconnect', 'connecting' in between 75 from_condition = 'obj.state == DeviceState.roaming' 76 to_condition = 'obj.state == DeviceState.connected' 77 wd.wait_for_object_change(device, from_condition, to_condition) 78 79 self.bss_hostapd[1].wait_for_event('AP-STA-CONNECTED %s' % device.address) 80 81 testutil.test_iface_operstate(device.name) 82 testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) 83 self.assertRaises(Exception, testutil.test_ifaces_connected, 84 (self.bss_hostapd[0].ifname, device.name, True, True)) 85 86 self.bss_hostapd[1].rekey(device.address) 87 88 def test_fils_ft_roam_sha256(self): 89 wd = IWD(True) 90 91 self.bss_hostapd[0].set_value('wpa_key_mgmt', 'FT-EAP FILS-SHA256 FT-FILS-SHA256') 92 self.bss_hostapd[0].reload() 93 self.bss_hostapd[0].wait_for_event("AP-ENABLED") 94 95 self.bss_hostapd[1].set_value('wpa_key_mgmt', 'FT-EAP FILS-SHA256 FT-FILS-SHA256') 96 self.bss_hostapd[1].reload() 97 self.bss_hostapd[1].wait_for_event("AP-ENABLED") 98 99 self.validate_connection(wd) 100 101 def test_fils_ft_roam_sha384(self): 102 wd = IWD(True) 103 104 self.bss_hostapd[0].set_value('wpa_key_mgmt', 'FT-EAP FILS-SHA384 FT-FILS-SHA384') 105 self.bss_hostapd[0].reload() 106 self.bss_hostapd[0].wait_for_event("AP-ENABLED") 107 108 self.bss_hostapd[1].set_value('wpa_key_mgmt', 'FT-EAP FILS-SHA384 FT-FILS-SHA384') 109 self.bss_hostapd[1].reload() 110 self.bss_hostapd[1].wait_for_event("AP-ENABLED") 111 112 self.validate_connection(wd) 113 114 def tearDown(self): 115 os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down') 116 os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down') 117 os.system('ip link set "' + self.bss_hostapd[0].ifname + '" up') 118 os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up') 119 120 @classmethod 121 def setUpClass(cls): 122 IWD.copy_to_storage('TestFT.8021x') 123 124 cls.bss_hostapd = [ HostapdCLI(config='ft-eap-ccmp-1.conf'), 125 HostapdCLI(config='ft-eap-ccmp-2.conf') ] 126 127 cls.bss_hostapd[0].set_address('12:00:00:00:00:01') 128 cls.bss_hostapd[1].set_address('12:00:00:00:00:02') 129 130 HostapdCLI.group_neighbors(*cls.bss_hostapd) 131 132 @classmethod 133 def tearDownClass(cls): 134 IWD.clear_storage() 135 cls.bss_hostapd = None 136 #cls.bss_radio = None 137 138 if __name__ == '__main__': 139 unittest.main(exit=True)