2018-06-27 21:31:47 +02:00
|
|
|
#! /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
|
2020-09-11 01:12:22 +02:00
|
|
|
from hostapd import HostapdCLI
|
2018-06-27 21:31:47 +02:00
|
|
|
import testutil
|
|
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
|
|
|
|
def client_connect(self, wd, dev):
|
2020-09-11 01:12:22 +02:00
|
|
|
hostapd = HostapdCLI(config='psk-ccmp.conf')
|
2018-06-27 21:31:47 +02:00
|
|
|
|
2020-05-07 21:20:22 +02:00
|
|
|
ordered_network = dev.get_ordered_network('TestAP1', True)
|
2018-06-30 01:25:00 +02:00
|
|
|
|
2018-06-27 21:31:47 +02:00
|
|
|
self.assertEqual(ordered_network.type, NetworkType.psk)
|
|
|
|
|
|
|
|
psk_agent = PSKAgent('Password1')
|
|
|
|
wd.register_psk_agent(psk_agent)
|
|
|
|
|
|
|
|
ordered_network.network_object.connect()
|
|
|
|
|
2020-09-14 23:02:33 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(dev, condition)
|
2018-06-27 21:31:47 +02:00
|
|
|
|
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
|
|
|
|
testutil.test_iface_operstate(dev.name)
|
2020-09-11 01:12:22 +02:00
|
|
|
testutil.test_ifaces_connected(hostapd.ifname, dev.name)
|
2018-06-27 21:31:47 +02:00
|
|
|
|
|
|
|
dev.disconnect()
|
|
|
|
|
|
|
|
condition = 'not obj.connected'
|
|
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
|
2020-05-07 21:20:20 +02:00
|
|
|
def test_connection_failure(self):
|
2020-10-27 20:57:49 +01:00
|
|
|
wd = IWD(True)
|
2018-06-27 21:31:47 +02:00
|
|
|
|
2018-07-02 19:02:08 +02:00
|
|
|
dev1, dev2 = wd.list_devices(2)
|
2018-06-27 21:31:47 +02:00
|
|
|
|
|
|
|
self.client_connect(wd, dev1)
|
|
|
|
|
|
|
|
dev1.start_ap('TestAP2', 'Password2')
|
|
|
|
|
2018-08-24 03:37:49 +02:00
|
|
|
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)
|
2018-06-27 21:31:47 +02:00
|
|
|
|
2018-08-24 03:37:49 +02:00
|
|
|
ordered_networks = dev2.get_ordered_networks()
|
|
|
|
networks = { n.name: n for n in ordered_networks }
|
|
|
|
self.assertEqual(networks['TestAP1'].type, NetworkType.psk)
|
|
|
|
self.assertEqual(networks['TestAP2'].type, NetworkType.psk)
|
2018-06-27 21:31:47 +02:00
|
|
|
|
2018-08-24 03:37:49 +02:00
|
|
|
psk_agent = PSKAgent('InvalidPassword')
|
|
|
|
wd.register_psk_agent(psk_agent)
|
2018-06-27 21:31:47 +02:00
|
|
|
|
2018-08-24 03:37:49 +02:00
|
|
|
with self.assertRaises(iwd.FailedEx):
|
|
|
|
networks['TestAP2'].network_object.connect()
|
2018-06-27 21:31:47 +02:00
|
|
|
|
2018-08-24 03:37:49 +02:00
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
finally:
|
|
|
|
dev1.stop_ap()
|
2018-06-27 21:31:47 +02:00
|
|
|
|
|
|
|
# Finally test dev1 can go to client mode and connect again
|
|
|
|
self.client_connect(wd, dev1)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2018-09-14 18:36:10 +02:00
|
|
|
IWD.copy_to_storage('TestAP1.psk')
|
2018-06-27 21:31:47 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
IWD.clear_storage()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|