2018-11-30 15:12:03 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append('../util')
|
|
|
|
import iwd
|
|
|
|
from iwd import IWD
|
|
|
|
from iwd import PSKAgent
|
|
|
|
from iwd import NetworkType
|
|
|
|
import testutil
|
|
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_connection_success(self):
|
|
|
|
wd = IWD()
|
|
|
|
|
2018-12-14 20:15:26 +01:00
|
|
|
devices = wd.list_devices(1)
|
2018-11-30 15:12:03 +01:00
|
|
|
device = devices[0]
|
|
|
|
|
|
|
|
device.disconnect()
|
|
|
|
condition = 'obj.state == DeviceState.disconnected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
condition = 'not obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
if not device.get_ordered_networks():
|
|
|
|
device.scan()
|
|
|
|
condition = 'obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
condition = 'not obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
2019-01-07 19:38:08 +01:00
|
|
|
ordered_network = device.get_ordered_network("ssidCCMP")
|
2018-11-30 15:12:03 +01:00
|
|
|
self.assertEqual(ordered_network.type, NetworkType.psk)
|
|
|
|
network = ordered_network.network_object
|
|
|
|
|
|
|
|
# 0 chars
|
|
|
|
psk_agent = PSKAgent("")
|
|
|
|
wd.register_psk_agent(psk_agent)
|
2018-12-03 15:40:45 +01:00
|
|
|
self.assertRaises(iwd.InvalidFormatEx, network.connect)
|
2018-11-30 15:12:03 +01:00
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
|
|
|
|
# 7 chars
|
|
|
|
psk_agent = PSKAgent("a" * 7)
|
|
|
|
wd.register_psk_agent(psk_agent)
|
2018-12-03 15:40:45 +01:00
|
|
|
self.assertRaises(iwd.InvalidFormatEx, network.connect)
|
2018-11-30 15:12:03 +01:00
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
|
|
|
|
# 64 chars
|
|
|
|
psk_agent = PSKAgent("a" * 64)
|
|
|
|
wd.register_psk_agent(psk_agent)
|
2018-12-03 15:40:45 +01:00
|
|
|
self.assertRaises(iwd.InvalidFormatEx, network.connect)
|
2018-11-30 15:12:03 +01:00
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
|
|
|
|
# 64k chars
|
|
|
|
psk_agent = PSKAgent("a" * 65536)
|
|
|
|
wd.register_psk_agent(psk_agent)
|
2018-12-03 15:40:45 +01:00
|
|
|
self.assertRaises(iwd.InvalidFormatEx, network.connect)
|
2018-11-30 15:12:03 +01:00
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
IWD.clear_storage()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|