2017-10-21 01:27:22 +02:00
|
|
|
#! /usr/bin/python3
|
|
|
|
|
|
|
|
import unittest
|
2022-11-02 23:51:16 +01:00
|
|
|
import os
|
2017-10-21 01:27:22 +02:00
|
|
|
|
|
|
|
from iwd import IWD
|
2022-06-30 20:03:31 +02:00
|
|
|
from config import ctx
|
2022-06-30 20:03:30 +02:00
|
|
|
from validation import validate, client_connect
|
2017-10-21 01:27:22 +02:00
|
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
def test_connection_success(self):
|
2022-11-02 23:51:16 +01:00
|
|
|
IWD.copy_to_storage('TestAP1.psk')
|
|
|
|
|
2020-10-27 20:57:49 +01:00
|
|
|
wd = IWD(True)
|
2017-10-21 01:27:22 +02:00
|
|
|
|
2018-07-02 19:02:08 +02:00
|
|
|
dev1, dev2 = wd.list_devices(2)
|
2017-10-21 01:27:22 +02:00
|
|
|
|
2022-06-30 20:03:30 +02:00
|
|
|
client_connect(wd, dev1, 'TestAP1')
|
2017-10-21 01:27:22 +02:00
|
|
|
|
|
|
|
dev1.start_ap('TestAP2', 'Password2')
|
|
|
|
|
2022-06-30 20:03:30 +02:00
|
|
|
validate(wd, dev2, dev1, 'TestAP2', 'Password2')
|
2017-10-21 01:27:22 +02:00
|
|
|
|
|
|
|
# Finally test dev1 can go to client mode and connect again
|
2022-06-30 20:03:30 +02:00
|
|
|
client_connect(wd, dev1, 'TestAP1')
|
2017-10-21 01:27:22 +02:00
|
|
|
|
2022-06-30 20:03:31 +02:00
|
|
|
def test_client_start_ap(self):
|
2022-11-02 23:51:16 +01:00
|
|
|
IWD.copy_to_storage('TestAP1.psk')
|
|
|
|
|
2022-06-30 20:03:31 +02:00
|
|
|
wd = IWD(True)
|
|
|
|
|
|
|
|
dev1, dev2 = wd.list_devices(2)
|
|
|
|
|
|
|
|
ctx.start_process(['iwctl', 'device', dev1.name, 'set-property', 'Mode', 'ap'], check=True)
|
|
|
|
ctx.start_process(['iwctl', 'ap', dev1.name, 'start', 'TestAP2', 'Password2'], check=True)
|
|
|
|
|
|
|
|
iwctl = ctx.start_process(['iwctl', 'ap', 'list'], check=True)
|
|
|
|
|
|
|
|
self.assertIn(dev1.name, iwctl.out)
|
|
|
|
|
|
|
|
iwctl = ctx.start_process(['iwctl', 'ap', dev1.name, 'show'], check=True)
|
|
|
|
|
|
|
|
self.assertIn('TestAP2', iwctl.out)
|
|
|
|
|
|
|
|
validate(wd, dev2, dev1, 'TestAP2', 'Password2')
|
|
|
|
|
2022-11-02 23:51:16 +01:00
|
|
|
def test_valid_ciphers(self):
|
|
|
|
ciphers = ['TKIP', 'CCMP-128', 'GCMP-128', 'CCMP-256', 'GCMP-256']
|
|
|
|
|
|
|
|
for group in ciphers:
|
|
|
|
for pairwise in ciphers:
|
|
|
|
IWD.copy_to_ap('TestAP2.ap')
|
|
|
|
os.system('echo "PairwiseCiphers=%s" >> /tmp/iwd/ap/TestAP2.ap' % pairwise)
|
|
|
|
os.system('echo "GroupCipher=%s" >> /tmp/iwd/ap/TestAP2.ap' % group)
|
|
|
|
|
|
|
|
wd = IWD(True)
|
|
|
|
|
|
|
|
dev1, dev2 = wd.list_devices(2)
|
|
|
|
|
|
|
|
dev1.start_ap('TestAP2')
|
|
|
|
|
|
|
|
self.assertTrue(dev1.group_cipher == group)
|
2022-11-04 17:37:59 +01:00
|
|
|
self.assertIn(pairwise, dev1.pairwise_ciphers)
|
2022-11-02 23:51:16 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
validate(wd, dev2, dev1, 'TestAP2', 'Password2', ip_checks=False)
|
|
|
|
except:
|
|
|
|
raise Exception("Failed with pairwise=%s group=%s" % (pairwise, group))
|
|
|
|
finally:
|
|
|
|
IWD.clear_storage()
|
|
|
|
del wd
|
2017-10-21 01:27:22 +02:00
|
|
|
|
2022-11-02 23:51:16 +01:00
|
|
|
def tearDown(self):
|
2017-10-21 01:27:22 +02:00
|
|
|
IWD.clear_storage()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|