connection_test.py (2799B)
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 12 class TestMFP(unittest.TestCase): 13 ''' 14 The below test cases excesise the following MFP option setting scenarios: 15 16 IWD_MFP: AP_MFP: Result: 17 0 0 No MFP, connection succeeds 18 0 1 No MFP, connection succeeds 19 0 2 Not capable error 20 1 0 No MFP, connection succeeds 21 1 1 MFP enabled, connection succeeds 22 1 2 MFP enabled, connection succeeds 23 2 0 Not capable error 24 2 1 MFP enabled, connection succeeds 25 2 2 MFP enabled, connection succeeds 26 27 where: 28 0 - MFP is disabled 29 1 - MFP is optional 30 2 - MFP is required 31 ''' 32 33 def check_mfp_connection(self, wd, device, ssid, throws_exception): 34 ordered_network = device.get_ordered_network(ssid) 35 36 condition = 'not obj.connected' 37 wd.wait_for_object_condition(ordered_network.network_object, condition) 38 39 if throws_exception: 40 with self.assertRaises(iwd.NotSupportedEx): 41 ordered_network.network_object.connect() 42 return 43 else: 44 ordered_network.network_object.connect() 45 46 condition = 'obj.state == DeviceState.connected' 47 wd.wait_for_object_condition(device, condition) 48 49 device.disconnect() 50 51 condition = 'not obj.connected' 52 wd.wait_for_object_condition(ordered_network.network_object, condition) 53 54 IWD.clear_storage() 55 56 def stage_iwd(self, wd, config_dir): 57 psk_agent = PSKAgent( ['secret123', 'secret123', 'secret123'] ) 58 wd.register_psk_agent(psk_agent) 59 60 devices = wd.list_devices(1) 61 self.assertIsNotNone(devices) 62 device = devices[0] 63 64 if config_dir == '/tmp/IWD-MFP2': 65 self.check_mfp_connection(wd, device, 'ssidMFP0', True) 66 else: 67 self.check_mfp_connection(wd, device, 'ssidMFP0', False) 68 69 self.check_mfp_connection(wd, device, 'ssidMFP1', False) 70 71 if config_dir == '/tmp/IWD-MFP0': 72 self.check_mfp_connection(wd, device, 'ssidMFP2', True) 73 else: 74 self.check_mfp_connection(wd, device, 'ssidMFP2', False) 75 76 wd.unregister_psk_agent(psk_agent) 77 78 def test_iwd_mfp0(self): 79 wd = IWD(True, '/tmp/IWD-MFP0') 80 81 self.stage_iwd(wd, '/tmp/IWD-MFP0') 82 83 def test_iwd_mfp1(self): 84 wd = IWD(True, '/tmp/IWD-MFP1') 85 86 self.stage_iwd(wd, '/tmp/IWD-MFP1') 87 88 def test_iwd_mfp2(self): 89 wd = IWD(True, '/tmp/IWD-MFP2') 90 91 self.stage_iwd(wd, '/tmp/IWD-MFP2') 92 93 if __name__ == '__main__': 94 unittest.main(exit=True)