def test_connection_success(self): wd = IWD(True) dev1, dev2 = wd.list_devices(2) self.assertIsNotNone(dev1) self.assertIsNotNone(dev2) dev1.start_adhoc("AdHocNetwork", "secret123") sleep(1) dev2.start_adhoc("AdHocNetwork", "InvalidPassword") # dev1.adhoc_wait_for_connected(dev2.address) # dev2.adhoc_wait_for_connected(dev1.address) # testutil.test_iface_operstate(dev1.name) # testutil.test_iface_operstate(dev2.name) # testutil.test_ifaces_connected(dev1.name, dev2.name) del wd
def check_connection_success(self, ssid): wd = IWD() device = wd.list_devices(1)[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network(ssid) condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition)
def test_list_removal_and_addition(self): wd = IWD(start_iwd_daemon=True) known_networks = wd.list_known_networks() self.assertEqual(len(known_networks), 3) wd.forget_known_network(known_networks[0]) known_networks = wd.list_known_networks() self.assertEqual(len(known_networks), 2) self.connect_to_new_network(wd) known_networks = wd.list_known_networks() self.assertEqual(len(known_networks), 3) for net in known_networks: wd.forget_known_network(net) known_networks = wd.list_known_networks() self.assertEqual(len(known_networks), 0)
def tearDown(self): os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') os.system('ifconfig "' + self.bss_hostapd[2].ifname + '" down') os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') os.system('ifconfig "' + self.bss_hostapd[2].ifname + '" up') hwsim = Hwsim() wd = IWD() device = wd.list_devices(1)[0] try: device.disconnect() except: pass condition = 'obj.state == DeviceState.disconnected' wd.wait_for_object_condition(device, condition) for rule in list(hwsim.rules.keys()): del hwsim.rules[rule]
def test_8021x(self): tca = TestConnectAutoConnect() tca.validate('ssidEAP-TLS', True, iwd.NotConfiguredEx) IWD.copy_to_storage('ssidEAP-TLS.8021x') tca.validate('ssidEAP-TLS', True) IWD.clear_storage() IWD.copy_to_storage('ssidEAP-Other.8021x') tca.validate('ssidEAP-Other', False, iwd.NotSupportedEx) IWD.clear_storage()
def test_connection_success(self): auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db') wd = IWD(True) try: self.validate_connection(wd) except: del wd auth.stop() raise del wd auth.stop()
def test_scan(self): wd = IWD(True) try: self.validate_scan(wd) except: del wd raise del wd for ssid, seen in self.dict.items(): self.assertEqual(seen, True)
def check_mfp_connection(self, wd, device, ssid, throws_exception): ordered_network = device.get_ordered_network(ssid) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) if throws_exception: with self.assertRaises(iwd.NotSupportedEx): ordered_network.network_object.connect() return else: ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) IWD.clear_storage()
def test_connection_success(self): hwsim = Hwsim() bss_radio = hwsim.get_radio('rad0') self.assertIsNotNone(bss_radio) wd = IWD() devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidOWE') self.assertEqual(ordered_network.type, NetworkType.open) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) rule0 = hwsim.rules.create() rule0.source = bss_radio.addresses[0] rule0.bidirectional = True rule0.drop = True rule0.prefix = 'b0' # Test Authenticate (b0) and Association (00) timeouts with self.assertRaises(iwd.FailedEx): ordered_network.network_object.connect() rule0.prefix = '00' with self.assertRaises(iwd.FailedEx): ordered_network.network_object.connect()
def list_removal_and_addition(self, wd): known_networks = wd.list_known_networks() self.assertEqual(len(known_networks), 4) for network in known_networks: if network.name == 'ssidTKIP': network.forget() known_networks = wd.list_known_networks() self.assertEqual(len(known_networks), 3) self.connect_to_new_network(wd) known_networks = wd.list_known_networks() self.assertEqual(len(known_networks), 4) IWD.copy_to_storage('known_networks/ssidPSK.psk') condition = 'len(obj.list_known_networks()) == 5' wd.wait_for_object_condition(wd, condition) expected = [ 'ssidNew', 'ssidOpen', 'ssidPSK', 'ssidEAP-TLS', 'Hotspot Network' ] self.assertEqual({n.name for n in wd.list_known_networks()}, set(expected)) IWD.remove_from_storage('ssidPSK.psk') condition = 'len(obj.list_known_networks()) == 4' wd.wait_for_object_condition(wd, condition) for net in known_networks: net.forget() known_networks = wd.list_known_networks() self.assertEqual(len(known_networks), 0)
def test_connection_success(self): wd = IWD(True) psk_agent = PSKAgent('*****@*****.**', ('*****@*****.**', 'testpasswd')) wd.register_psk_agent(psk_agent) try: self.validate_connection(wd) finally: wd.unregister_psk_agent(psk_agent)
def test_push_button_success(self): wd = IWD() devices = wd.list_devices(1) device = devices[0] device.wps_push_button() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) device.disconnect() condition = 'obj.state == DeviceState.disconnected' wd.wait_for_object_condition(device, condition)
def test_connection_success(self): hwsim = Hwsim() non_ht_hostapd = HostapdCLI(config='non-ht-vht.conf') ht_hostapd = HostapdCLI(config='ht.conf') vht_hostapd = HostapdCLI(config='vht.conf') non_ht_radio = hwsim.get_radio('rad0') ht_radio = hwsim.get_radio('rad1') vht_radio = hwsim.get_radio('rad2') self.assertIsNotNone(non_ht_hostapd) self.assertIsNotNone(ht_hostapd) self.assertIsNotNone(vht_hostapd) rule0 = hwsim.rules.create() rule0.source = vht_radio.addresses[0] rule0.bidirectional = True rule0.signal = -2000 rule1 = hwsim.rules.create() rule1.source = ht_radio.addresses[0] rule1.bidirectional = True rule1.signal = -2000 rule2 = hwsim.rules.create() rule2.source = non_ht_radio.addresses[0] rule2.bidirectional = True rule2.signal = -2000 wd = IWD() psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) device = wd.list_devices(1)[0] self.do_connect(wd, device, vht_hostapd) # lower VHT BSS signal, HT should now be preferred rule0.signal = -6000 self.do_connect(wd, device, ht_hostapd) # lower HT BSS signal, basic rate BSS should now be preferred rule1.signal = -6000 self.do_connect(wd, device, non_ht_hostapd) wd.unregister_psk_agent(psk_agent)
def test_connection_with_other_agent(self): wd = IWD() iwctl = subprocess.Popen(['iwctl', '-P', 'secret_ssid2']) # Let iwctl to start and register its agent. wd.wait(2) self.check_connection(wd, 'ssid2') iwctl.terminate() iwctl.communicate() IWD.clear_storage()
def test_scan(self): wd = IWD() devices = wd.list_devices() self.assertIsNotNone(devices) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() seen = [0] * 3 for o_n in ordered_networks: if o_n.name == "ssidOpen": self.assertEqual(o_n.type, NetworkType.open) if seen[0]: raise Exception('Duplicated list entry') else: seen[0] = 1 elif o_n.name == "ssidTKIP": self.assertEqual(o_n.type, NetworkType.psk) if seen[1]: raise Exception('Duplicated list entry') else: seen[1] = 1 elif o_n.name == "ssidCCMP": self.assertEqual(o_n.type, NetworkType.psk) if seen[2]: raise Exception('Duplicated list entry') else: seen[2] = 1 else: raise Exception() for entry in seen: self.assertNotEqual(entry, 0)
def test_connection_success(self): wd = IWD() devices = wd.list_devices(1) device = devices[0] perm_addr = device.address condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) # 1. Test per-network deterministic MAC generation os.system('cat pernetwork.psk > /tmp/iwd/ssidCCMP.psk') new_addr = self.try_connection(wd) self.assertNotEqual(perm_addr, new_addr) # try again to ensure the generation was deterministic new_addr2 = self.try_connection(wd) self.assertEqual(new_addr, new_addr2) # 2. Test FullAddressRandomization os.system('cat full_random.psk > /tmp/iwd/ssidCCMP.psk') new_addr = self.try_connection(wd) self.assertNotEqual(perm_addr, new_addr) # try again to make sure the generation was random new_addr2 = self.try_connection(wd) self.assertNotEqual(new_addr, new_addr2) # 3. Test AddressOverride os.system('cat override.psk > /tmp/iwd/ssidCCMP.psk') new_addr = self.try_connection(wd) self.assertEqual(new_addr, 'e6:f6:38:a9:02:02')
def test_roam_success(self): hwsim = Hwsim() rule0 = hwsim.rules.create() rule0.source = self.bss_radio[0].addresses[0] rule0.bidirectional = True rule1 = hwsim.rules.create() rule1.source = self.bss_radio[1].addresses[0] rule1.bidirectional = True wd = IWD() psk_agent = PSKAgent("EasilyGuessedPassword") wd.register_psk_agent(psk_agent) device = wd.list_devices(1)[0] # Check that iwd selects BSS 0 first rule0.signal = -2000 rule1.signal = -2500 condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('TestFT') self.assertEqual(ordered_network.type, NetworkType.psk) self.assertEqual(ordered_network.signal_strength, -2000) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertFalse(self.bss_hostapd[0].list_sta()) self.assertFalse(self.bss_hostapd[1].list_sta()) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertTrue(self.bss_hostapd[0].list_sta()) self.assertFalse(self.bss_hostapd[1].list_sta()) wd.unregister_psk_agent(psk_agent) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) self.assertRaises(Exception, testutil.test_ifaces_connected, (self.bss_hostapd[1].ifname, device.name)) # Check that iwd starts transition to BSS 1 in less than 10 seconds. # The 10 seconds is longer than needed to scan on just two channels # but short enough that a full scan on the 2.4 + 5.8 bands supported # by mac80211_hwsim will not finish. If this times out then, but # device_roam_trigger_cb has happened, it probably means that # Neighbor Reports are broken. rule0.signal = -8000 condition = 'obj.state == DeviceState.roaming' wd.wait_for_object_condition(device, condition, 10) # Check that iwd is on BSS 1 once out of roaming state and doesn't # go through 'disconnected', 'autoconnect', 'connecting' in between condition = 'obj.state != DeviceState.roaming' wd.wait_for_object_condition(device, condition, 5) self.assertEqual(device.state, iwd.DeviceState.connected) self.assertTrue(self.bss_hostapd[1].list_sta()) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) self.assertRaises(Exception, testutil.test_ifaces_connected, (self.bss_hostapd[0].ifname, device.name))
def tearDownClass(cls): IWD.clear_storage()
def setUpClass(cls): IWD.copy_to_storage('ssidEAP-TTLS-CHAP.8021x')
def test_connection_success(self): hostapd = None for hostapd_if in list(hostapd_map.values()): hpd = HostapdCLI(hostapd_if) if hpd.get_config_value('ssid') == 'ssidEAP-TTLS-CHAP': hostapd = hpd break self.assertIsNotNone(hostapd) wd = IWD() psk_agent = PSKAgent('abc', ('user', 'testpasswd')) wd.register_psk_agent(psk_agent) device = wd.list_devices(1)[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidEAP-TTLS-CHAP') self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) hostapd.eapol_reauth(device.address) wd.wait(10) condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected() device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): wd = IWD() psk_agent = PSKAgent("InvalidPassword") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() ordered_network = ordered_networks[0] self.assertEqual(ordered_network.name, "ssidCCMP") self.assertEqual(ordered_network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) with self.assertRaises(iwd.FailedEx): ordered_network.network_object.connect() wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): wd = IWD(True) self.validate_connection(wd)
def test_connection_success(self): wd = IWD(True, '/tmp/dhcp') # dev1, dev3, and dev4 are all AP's # The configured IP range only supports 2 subnets, so dev4 should fail # to start AP. dev1, dev2, dev3, dev4 = wd.list_devices(4) dev1.start_ap('TestAP2', "Password2") dev3.start_ap('TestAP3', 'Password3') with self.assertRaises(iwd.AlreadyExistsEx): dev4.start_ap('TestAP4', 'Password4') try: condition = 'not obj.scanning' wd.wait_for_object_condition(dev2, condition) dev2.scan() condition = 'obj.scanning' wd.wait_for_object_condition(dev2, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(dev2, condition) ordered_networks = dev2.get_ordered_networks() networks = { n.name: n for n in ordered_networks } self.assertEqual(networks['TestAP2'].type, NetworkType.psk) psk_agent = PSKAgent('Password2') wd.register_psk_agent(psk_agent) try: dev2.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(dev2, condition) except: pass networks['TestAP2'].network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(dev2, condition) testutil.test_iface_operstate(dev2.name) testutil.test_ifaces_connected(dev1.name, dev2.name, group=False) try: testutil.test_ip_address_match(dev1.name, "192.168.80.1") testutil.test_ip_address_match(dev2.name, "192.168.80.2") ip = "192.168.80.1" except: testutil.test_ip_address_match(dev1.name, "192.168.80.17") testutil.test_ip_address_match(dev2.name, "192.168.80.18") ip = "192.168.80.17" wd.unregister_psk_agent(psk_agent) dev2.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(networks['TestAP2'].network_object, condition) # This should release the IP */ dev1.stop_ap() # This should now succeed and the IP should match the old IP dev1 # got initially. dev4.start_ap('TestAP4', 'Password4') testutil.test_ip_address_match(dev4.name, ip) finally: dev1.stop_ap()
def setUpClass(cls): IWD.copy_to_storage('ssidFILS-256.8021x') os.system('ifconfig lo up') pass
def test_connection_success(self): hapd = HostapdCLI(config='ssidFILS-256.conf') wd = IWD(True) psk_agent = PSKAgent('*****@*****.**', ('*****@*****.**', 'secret123')) wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidFILS-256') self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd.ifname) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network = device.get_ordered_network('ssidFILS-256') self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd.ifname) device.disconnect() wd.unregister_psk_agent(psk_agent)
def tearDownClass(cls): IWD.clear_storage() cls.bss_hostapd = None cls.bss_radio = None
def setUpClass(cls): IWD.copy_to_storage('ssidAlreadyKnown.open')
def setUpClass(cls): IWD.copy_to_storage('ssidEAP-TLS.8021x') IWD.copy_to_storage('ssidEAP-TLS2.8021x') IWD.copy_to_storage('ssidEAP-TLS3.8021x')
def do_test_connection_success(self, ssid, passphrase=None): wd = IWD() if passphrase: psk_agent = PSKAgent(passphrase) wd.register_psk_agent(psk_agent) hostapd_ifname = None for ifname in hostapd.hostapd_map: if ssid + '.conf' in hostapd.hostapd_map[ifname].config: hostapd_ifname = ifname break devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) if not device.get_ordered_networks(): device.scan() condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() ordered_network = [n for n in ordered_networks if n.name == ssid][0] self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected(hostapd_ifname, 'wln3') device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) if passphrase: wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): wd = IWD() dev1, dev2 = wd.list_devices() self.client_connect(wd, dev1) dev1.start_ap('TestAP2', 'Password2') condition = 'not obj.scanning' wd.wait_for_object_condition(dev2, condition) dev2.scan() condition = 'obj.scanning' wd.wait_for_object_condition(dev2, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(dev2, condition) ordered_networks = dev2.get_ordered_networks() self.assertEqual(len(ordered_networks), 2) networks = {n.name: n for n in ordered_networks} self.assertEqual(networks['TestAP1'].type, NetworkType.psk) self.assertEqual(networks['TestAP2'].type, NetworkType.psk) psk_agent = PSKAgent('Password2') wd.register_psk_agent(psk_agent) try: dev2.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(dev2, condition) except: pass networks['TestAP2'].network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(networks['TestAP2'].network_object, condition) testutil.test_iface_operstate(dev2.name) testutil.test_ifaces_connected(dev1.name, dev2.name) wd.unregister_psk_agent(psk_agent) dev2.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(networks['TestAP2'].network_object, condition) dev1.stop_ap() # Finally test dev1 can go to client mode and connect again self.client_connect(wd, dev1)