2020-03-19 23:59:02 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
sys.path.append('../util')
|
|
|
|
import iwd
|
|
|
|
from iwd import IWD
|
|
|
|
from iwd import NetworkType
|
|
|
|
import testutil
|
|
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
def try_connection(self, wd):
|
|
|
|
devices = wd.list_devices(1)
|
|
|
|
device = devices[0]
|
|
|
|
|
|
|
|
ordered_network = device.get_ordered_network('ssidCCMP')
|
|
|
|
|
|
|
|
self.assertEqual(ordered_network.type, NetworkType.psk)
|
|
|
|
|
|
|
|
condition = 'not obj.connected'
|
|
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
|
|
|
|
ordered_network.network_object.connect()
|
|
|
|
|
2020-09-14 23:02:33 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2020-03-19 23:59:02 +01:00
|
|
|
|
|
|
|
testutil.test_iface_operstate()
|
|
|
|
testutil.test_ifaces_connected()
|
|
|
|
|
|
|
|
device.disconnect()
|
|
|
|
|
|
|
|
condition = 'not obj.connected'
|
|
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
|
|
|
|
return device.address
|
|
|
|
|
|
|
|
def test_connection_success(self):
|
2020-03-24 21:24:02 +01:00
|
|
|
wd = IWD()
|
2020-03-19 23:59:02 +01:00
|
|
|
|
|
|
|
devices = wd.list_devices(1)
|
|
|
|
device = devices[0]
|
|
|
|
|
|
|
|
perm_addr = device.address
|
|
|
|
|
|
|
|
condition = 'not obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
device.scan()
|
|
|
|
|
|
|
|
condition = 'not obj.scanning'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
|
|
|
|
|
|
|
# 1. Test per-network deterministic MAC generation
|
2020-11-03 21:51:14 +01:00
|
|
|
os.system('cat pernetwork.psk > /tmp/iwd/ssidCCMP.psk')
|
2020-03-19 23:59:02 +01:00
|
|
|
new_addr = self.try_connection(wd)
|
|
|
|
self.assertNotEqual(perm_addr, new_addr)
|
|
|
|
# try again to ensure the generation was deterministic
|
|
|
|
new_addr2 = self.try_connection(wd)
|
|
|
|
self.assertEqual(new_addr, new_addr2)
|
|
|
|
|
|
|
|
# 2. Test FullAddressRandomization
|
2020-11-03 21:51:14 +01:00
|
|
|
os.system('cat full_random.psk > /tmp/iwd/ssidCCMP.psk')
|
2020-03-19 23:59:02 +01:00
|
|
|
new_addr = self.try_connection(wd)
|
|
|
|
self.assertNotEqual(perm_addr, new_addr)
|
|
|
|
# try again to make sure the generation was random
|
|
|
|
new_addr2 = self.try_connection(wd)
|
|
|
|
self.assertNotEqual(new_addr, new_addr2)
|
|
|
|
|
|
|
|
# 3. Test AddressOverride
|
2020-11-03 21:51:14 +01:00
|
|
|
os.system('cat override.psk > /tmp/iwd/ssidCCMP.psk')
|
2020-03-19 23:59:02 +01:00
|
|
|
new_addr = self.try_connection(wd)
|
|
|
|
self.assertEqual(new_addr, 'e6:f6:38:a9:02:02')
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
IWD.clear_storage()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|