mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-23 22:42:37 +01:00
69fe274c7d
The single AP test worked fine, but adding a failure test caused some problems. Since the kernel is never restarted between tests it maintains old stale scan results from the previous test. This was causing an assert to sometimes fail in the second test being run because it was returning > 1 ordered networks. This change iterates through the ordered network list and chooses the appropriate network rather than assuming get_ordered_networks() will always return only one network object
107 lines
3.0 KiB
Python
107 lines
3.0 KiB
Python
#! /usr/bin/python3
|
|
|
|
import unittest
|
|
import sys, os
|
|
|
|
sys.path.append('../util')
|
|
import iwd
|
|
from iwd import IWD
|
|
from iwd import PSKAgent
|
|
from iwd import NetworkType
|
|
import hostapd
|
|
import testutil
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
def client_connect(self, wd, dev):
|
|
condition = 'not obj.scanning'
|
|
wd.wait_for_object_condition(dev, condition)
|
|
|
|
if not dev.get_ordered_networks():
|
|
dev.scan()
|
|
condition = 'obj.scanning'
|
|
wd.wait_for_object_condition(dev, condition)
|
|
condition = 'not obj.scanning'
|
|
wd.wait_for_object_condition(dev, condition)
|
|
|
|
ordered_networks = dev.get_ordered_networks()
|
|
|
|
ordered_network = None
|
|
for network in ordered_networks:
|
|
if network.name == 'TestAP1':
|
|
ordered_network = network
|
|
break
|
|
|
|
self.assertNotEqual(ordered_network, None)
|
|
self.assertEqual(ordered_network.name, 'TestAP1')
|
|
self.assertEqual(ordered_network.type, NetworkType.psk)
|
|
|
|
psk_agent = PSKAgent('Password1')
|
|
wd.register_psk_agent(psk_agent)
|
|
|
|
ordered_network.network_object.connect()
|
|
|
|
condition = 'obj.connected'
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
testutil.test_iface_operstate(dev.name)
|
|
testutil.test_ifaces_connected(list(hostapd.hostapd_map.keys())[0],
|
|
dev.name)
|
|
|
|
self.assertRaises(iwd.dbus.DBusException, dev.start_ap,
|
|
'TestAP2', 'Password2')
|
|
|
|
dev.disconnect()
|
|
|
|
condition = 'not obj.connected'
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
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('InvalidPassword')
|
|
wd.register_psk_agent(psk_agent)
|
|
|
|
with self.assertRaises(iwd.FailedEx):
|
|
networks['TestAP2'].network_object.connect()
|
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
dev1.stop_ap()
|
|
|
|
# Finally test dev1 can go to client mode and connect again
|
|
self.client_connect(wd, dev1)
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
pass
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
IWD.clear_storage()
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main(exit=True)
|