mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-22 06:29:23 +01:00
a773aa6a07
All tests which could avoid calling scan() directly have been changed to use the 'full_scan' argument to get_ordered_network. This was done because of unreliable scanning behavior on slower systems, like VMs. If we get unlucky with the scheduler some beacons are not received in time and in turn scan results are missing. Using full_scan=True works around this issue by repeatedly scanning until the SSID is found.
81 lines
2.1 KiB
Python
81 lines
2.1 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
|
|
from hostapd import HostapdCLI
|
|
import testutil
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
def client_connect(self, wd, dev):
|
|
hostapd = HostapdCLI(config='psk-ccmp.conf')
|
|
|
|
ordered_network = dev.get_ordered_network('TestAP1', True)
|
|
|
|
self.assertEqual(ordered_network.type, NetworkType.psk)
|
|
|
|
psk_agent = PSKAgent('Password1')
|
|
wd.register_psk_agent(psk_agent)
|
|
|
|
ordered_network.network_object.connect()
|
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
wd.wait_for_object_condition(dev, condition)
|
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
testutil.test_iface_operstate(dev.name)
|
|
testutil.test_ifaces_connected(hostapd.ifname, dev.name)
|
|
|
|
dev.disconnect()
|
|
|
|
condition = 'not obj.connected'
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
def test_connection_failure(self):
|
|
wd = IWD(True)
|
|
|
|
dev1, dev2 = wd.list_devices(2)
|
|
|
|
self.client_connect(wd, dev1)
|
|
|
|
dev1.start_ap('TestAP2', 'Password2')
|
|
|
|
try:
|
|
networks = {}
|
|
networks['TestAP1'] = dev2.get_ordered_network('TestAP1', full_scan=True)
|
|
networks['TestAP2'] = dev2.get_ordered_network('TestAP2', full_scan=True)
|
|
|
|
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)
|
|
finally:
|
|
dev1.stop_ap()
|
|
|
|
# Finally test dev1 can go to client mode and connect again
|
|
self.client_connect(wd, dev1)
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
IWD.copy_to_storage('TestAP1.psk')
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
IWD.clear_storage()
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main(exit=True)
|