mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-02 18:19: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.
103 lines
3.1 KiB
Python
103 lines
3.1 KiB
Python
#!/usr/bin/python3
|
|
|
|
import unittest
|
|
import sys
|
|
|
|
sys.path.append('../util')
|
|
import iwd
|
|
from iwd import IWD
|
|
import testutil
|
|
import subprocess
|
|
from config import ctx
|
|
|
|
class Test(unittest.TestCase):
|
|
def check_connection_success(self, ssid):
|
|
device = self.wd.list_devices(1)[0]
|
|
|
|
ordered_network = device.get_ordered_network(ssid)
|
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
self.wd.wait_for_object_condition(device, condition)
|
|
|
|
device.disconnect()
|
|
|
|
condition = 'not obj.connected'
|
|
self.wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
def establish_network(self, ssid):
|
|
device = self.wd.list_devices(1)[0]
|
|
device.get_ordered_network(ssid)
|
|
|
|
def test_connection_with_passphrase(self):
|
|
ssid = 'ssidPassphrase'
|
|
|
|
self.establish_network(ssid)
|
|
device = self.wd.list_devices(1)[0]
|
|
|
|
# Use --dontaks cmd-line option
|
|
with self.assertRaises(subprocess.CalledProcessError):
|
|
ctx.start_process(['iwctl', 'd', 'station', device.name, 'connect', ssid], check=True)
|
|
|
|
ctx.start_process(['iwctl', '-P', 'passphrase', 'station', device.name, 'connect', ssid],
|
|
check=True)
|
|
|
|
self.check_connection_success(ssid)
|
|
|
|
def test_connection_with_username_and_password(self):
|
|
ssid = 'ssidUNameAndPWord'
|
|
|
|
self.establish_network(ssid)
|
|
device = self.wd.list_devices(1)[0]
|
|
|
|
ctx.start_process(['iwctl', '-u', 'user', '-p', 'password', 'station', \
|
|
device.name, 'connect', ssid], check=True)
|
|
self.check_connection_success(ssid)
|
|
|
|
def test_connection_with_password(self):
|
|
ssid = 'ssidPWord'
|
|
|
|
self.establish_network(ssid)
|
|
device = self.wd.list_devices(1)[0]
|
|
|
|
ctx.start_process(['iwctl', '-p', 'password', 'station', device.name, 'connect', ssid],
|
|
check=True)
|
|
|
|
self.check_connection_success(ssid)
|
|
|
|
def test_connection_failure(self):
|
|
ssid = 'ssidPassphrase'
|
|
|
|
self.establish_network(ssid)
|
|
device = self.wd.list_devices(1)[0]
|
|
|
|
with self.assertRaises(subprocess.CalledProcessError):
|
|
ctx.start_process(['iwctl', '-P', 'incorrect_passphrase', 'station', device.name, \
|
|
'connect', ssid], check=True)
|
|
|
|
def test_invalid_command_line_option(self):
|
|
ssid = 'ssidPassphrase'
|
|
|
|
self.establish_network(ssid)
|
|
device = self.wd.list_devices(1)[0]
|
|
|
|
with self.assertRaises(subprocess.CalledProcessError):
|
|
ctx.start_process(['iwctl', '-z', 'station', device.name, 'connect', ssid], check=True)
|
|
|
|
def test_invalid_command(self):
|
|
with self.assertRaises(subprocess.CalledProcessError):
|
|
ctx.start_process(['iwctl', 'inexistent', 'command'], check=True)
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
IWD.copy_to_storage('ssidUNameAndPWord.8021x')
|
|
IWD.copy_to_storage('ssidPWord.8021x')
|
|
|
|
cls.wd = IWD()
|
|
|
|
@classmethod
|
|
def tearDownClass(cls):
|
|
IWD.clear_storage()
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main(exit=True)
|