2019-08-15 20:40:44 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append('../util')
|
|
|
|
import iwd
|
|
|
|
from iwd import IWD
|
|
|
|
import testutil
|
|
|
|
import subprocess
|
2020-09-11 01:12:39 +02:00
|
|
|
from config import ctx
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
def check_connection_success(self, ssid):
|
2020-09-11 01:12:22 +02:00
|
|
|
device = self.wd.list_devices(1)[0]
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
ordered_network = device.get_ordered_network(ssid)
|
|
|
|
|
2020-09-14 23:02:33 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
self.wd.wait_for_object_condition(device, condition)
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
device.disconnect()
|
|
|
|
|
|
|
|
condition = 'not obj.connected'
|
2020-09-11 01:12:22 +02:00
|
|
|
self.wd.wait_for_object_condition(ordered_network.network_object, condition)
|
2019-08-15 20:40:44 +02:00
|
|
|
|
2022-03-30 22:23:11 +02:00
|
|
|
def establish_network(self, ssid):
|
|
|
|
device = self.wd.list_devices(1)[0]
|
|
|
|
device.get_ordered_network(ssid)
|
|
|
|
|
2019-08-15 20:40:44 +02:00
|
|
|
def test_connection_with_passphrase(self):
|
|
|
|
ssid = 'ssidPassphrase'
|
|
|
|
|
2022-03-30 22:23:11 +02:00
|
|
|
self.establish_network(ssid)
|
2020-09-11 01:12:22 +02:00
|
|
|
device = self.wd.list_devices(1)[0]
|
2019-08-15 20:40:44 +02:00
|
|
|
|
2019-09-19 19:16:32 +02:00
|
|
|
# Use --dontaks cmd-line option
|
|
|
|
with self.assertRaises(subprocess.CalledProcessError):
|
2020-09-11 01:12:39 +02:00
|
|
|
ctx.start_process(['iwctl', 'd', 'station', device.name, 'connect', ssid], check=True)
|
2019-09-19 19:16:32 +02:00
|
|
|
|
2020-09-11 01:12:39 +02:00
|
|
|
ctx.start_process(['iwctl', '-P', 'passphrase', 'station', device.name, 'connect', ssid],
|
|
|
|
check=True)
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
self.check_connection_success(ssid)
|
|
|
|
|
|
|
|
def test_connection_with_username_and_password(self):
|
|
|
|
ssid = 'ssidUNameAndPWord'
|
|
|
|
|
2022-03-30 22:23:11 +02:00
|
|
|
self.establish_network(ssid)
|
2020-09-11 01:12:22 +02:00
|
|
|
device = self.wd.list_devices(1)[0]
|
2019-08-15 20:40:44 +02:00
|
|
|
|
2020-09-11 01:12:39 +02:00
|
|
|
ctx.start_process(['iwctl', '-u', 'user', '-p', 'password', 'station', \
|
|
|
|
device.name, 'connect', ssid], check=True)
|
2019-08-15 20:40:44 +02:00
|
|
|
self.check_connection_success(ssid)
|
|
|
|
|
|
|
|
def test_connection_with_password(self):
|
|
|
|
ssid = 'ssidPWord'
|
|
|
|
|
2022-03-30 22:23:11 +02:00
|
|
|
self.establish_network(ssid)
|
2020-09-11 01:12:22 +02:00
|
|
|
device = self.wd.list_devices(1)[0]
|
2019-08-15 20:40:44 +02:00
|
|
|
|
2020-09-11 01:12:39 +02:00
|
|
|
ctx.start_process(['iwctl', '-p', 'password', 'station', device.name, 'connect', ssid],
|
|
|
|
check=True)
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
self.check_connection_success(ssid)
|
|
|
|
|
|
|
|
def test_connection_failure(self):
|
|
|
|
ssid = 'ssidPassphrase'
|
|
|
|
|
2022-03-30 22:23:11 +02:00
|
|
|
self.establish_network(ssid)
|
2020-09-11 01:12:22 +02:00
|
|
|
device = self.wd.list_devices(1)[0]
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
with self.assertRaises(subprocess.CalledProcessError):
|
2020-09-11 01:12:39 +02:00
|
|
|
ctx.start_process(['iwctl', '-P', 'incorrect_passphrase', 'station', device.name, \
|
|
|
|
'connect', ssid], check=True)
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
def test_invalid_command_line_option(self):
|
|
|
|
ssid = 'ssidPassphrase'
|
|
|
|
|
2022-03-30 22:23:11 +02:00
|
|
|
self.establish_network(ssid)
|
2020-09-11 01:12:22 +02:00
|
|
|
device = self.wd.list_devices(1)[0]
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
with self.assertRaises(subprocess.CalledProcessError):
|
2020-09-11 01:12:39 +02:00
|
|
|
ctx.start_process(['iwctl', '-z', 'station', device.name, 'connect', ssid], check=True)
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
def test_invalid_command(self):
|
|
|
|
with self.assertRaises(subprocess.CalledProcessError):
|
2020-09-11 01:12:39 +02:00
|
|
|
ctx.start_process(['iwctl', 'inexistent', 'command'], check=True)
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
IWD.copy_to_storage('ssidUNameAndPWord.8021x')
|
|
|
|
IWD.copy_to_storage('ssidPWord.8021x')
|
|
|
|
|
2020-09-11 01:12:22 +02:00
|
|
|
cls.wd = IWD()
|
2019-08-15 20:40:44 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
IWD.clear_storage()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|