Skip to contentSkip to conversation

auto-t: iwd.py: add DPP properties

PATCH In review James Prestwood 2 participants 8 messages Jun 30, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 auto-t: iwd.py: add DPP properties

---
 autotests/util/iwd.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)
autotests/util/iwd.py +12 -0
index 5591d7e1..df310a32 100755
@@ -294,6 +294,18 @@ class DeviceProvisioning(IWDDBusAbstract):
     def stop(self):
         self._iface.Stop()
 
+    @property
+    def uri(self):
+        return self._properties['URI']
+
+    @property
+    def started(self):
+        return self._properties['Started']
+
+    @property
+    def role(self):
+        return self._properties['Role']
+
 class Device(IWDDBusAbstract):
     '''
         Class represents a network device object: net.connman.iwd.Device
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/7 auto-t: add client test to testKnownNetworks

Tests iwctl functionality with known-networks command

---
 .../testKnownNetworks/known_network_test.py   | 23 +++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
autotests/testKnownNetworks/known_network_test.py +21 -2
index 2bdcc955..a383e5ff 100644
@@ -2,10 +2,11 @@
 
 import unittest
 import sys
+import subprocess
 
 sys.path.append('../util')
-import iwd
 from iwd import IWD
+from config import ctx
 
 class Test(unittest.TestCase):
 
@@ -70,8 +71,26 @@ class Test(unittest.TestCase):
 
         self.list_removal_and_addition(wd)
 
+    def test_client_known_networks(self):
+        networks = ['Hotspot Network', 'ssidOpen', 'ssidTKIP', 'ssidEAP-TLS']
+        wd = IWD(True)
+
+        iwctl = ctx.start_process(['iwctl', 'known-networks', 'list'], check=True)
+
+        for n in networks:
+            self.assertIn(n, iwctl.out)
+
+        for n in networks:
+            ctx.start_process(['iwctl', 'known-networks', n, 'show'], check=True)
+
+        networks.remove('ssidOpen')
+        ctx.start_process(['iwctl', 'known-networks', 'ssidOpen', 'forget'], check=True)
+
+        with self.assertRaises(subprocess.CalledProcessError):
+            ctx.start_process(['iwctl', 'known-networks', 'ssidOpen', 'show'], check=True)
+
     @classmethod
-    def setUpClass(cls):
+    def setUp(self):
         IWD.copy_to_storage('known_networks/ssidOpen.open')
         IWD.copy_to_storage('known_networks/ssidTKIP.psk')
         IWD.copy_to_storage('known_networks/ssidEAP-TLS.8021x')
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/7 auto-t: add client test to testEAP-WPS

In reply to James Prestwood

Tests iwctl functionality with wsc commands

---
 autotests/testEAP-WPS/four_digit_pin_test.py | 16 +++++++++++-----
 autotests/testEAP-WPS/push_button_test.py    | 17 ++++++++++++-----
 2 files changed, 23 insertions(+), 10 deletions(-)
autotests/testEAP-WPS/four_digit_pin_test.py +11 -5
index 7bdb57cb..d30492fb 100644
@@ -4,22 +4,23 @@ import unittest
 import sys
 
 sys.path.append('../util')
-import iwd
 from iwd import IWD
-from iwd import DeviceState
-
 from hostapd import HostapdCLI
+from config import ctx
 
 class Test(unittest.TestCase):
 
-    def four_digit_pin_success(self, wd):
+    def four_digit_pin_success(self, wd, client=False):
 
         devices = wd.list_devices(1)
         device = devices[0]
         pin = '1234'
         self.hostapd.wps_pin(pin)
 
-        device.wps_start_pin(pin)
+        if not client:
+            device.wps_start_pin(pin)
+        else:
+            ctx.start_process(['iwctl', 'wsc', device.name, 'start-user-pin', pin], check=True)
 
         condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_condition(device, condition)
@@ -36,6 +37,11 @@ class Test(unittest.TestCase):
 
         self.four_digit_pin_success(wd)
 
+    def test_client_four_digit_pin(self):
+        wd = IWD(True)
+
+        self.four_digit_pin_success(wd, client=True)
+
     @classmethod
     def setUpClass(cls):
         cls.hostapd = HostapdCLI(config='ssidWPS.conf')
autotests/testEAP-WPS/push_button_test.py +12 -5
index 08463f15..e2b4c2b2 100644
@@ -4,20 +4,22 @@ import unittest
 import sys
 
 sys.path.append('../util')
-import iwd
 from iwd import IWD
-from iwd import DeviceState
-
 from hostapd import HostapdCLI
+from config import ctx
+
 class Test(unittest.TestCase):
 
-    def push_button_success(self, wd):
+    def push_button_success(self, wd, client=False):
         self.hostapd.wps_push_button()
 
         devices = wd.list_devices(1)
         device = devices[0]
 
-        device.wps_push_button()
+        if not client:
+            device.wps_push_button()
+        else:
+            ctx.start_process(['iwctl', 'wsc', device.name, 'push-button'], check=True)
 
         condition = 'obj.state == DeviceState.connected'
         wd.wait_for_object_condition(device, condition)
@@ -34,6 +36,11 @@ class Test(unittest.TestCase):
 
         self.push_button_success(wd)
 
+    def test_client_push_button(self):
+        wd = IWD(True)
+
+        self.push_button_success(wd, client=True)
+
     @classmethod
     def setUpClass(cls):
         cls.hostapd = HostapdCLI(config='ssidWPS.conf')
Signature · 1 line
2.34.1
#3 lore raw

PATCH 4/7 auto-t: add client test to testAdHoc

In reply to James Prestwood

Tests iwctl functionality with ad-hoc commands

---
 autotests/testAdHoc/adhoc_test.py | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
autotests/testAdHoc/adhoc_test.py +15 -4
index 13c0c016..4c5d5023 100644
@@ -2,16 +2,16 @@
 
 import unittest
 import sys
-import time
 
 sys.path.append('../util')
-import iwd
 from iwd import IWD
+from iwd import AdHocDevice
+from config import ctx
 import testutil
 
 class Test(unittest.TestCase):
 
-    def validate_connection(self, wd):
+    def validate_connection(self, wd, client=False):
         dev1, dev2 = wd.list_devices(2)
 
         self.assertIsNotNone(dev1)
@@ -22,7 +22,14 @@ class Test(unittest.TestCase):
         condition = 'obj.started == True'
         wd.wait_for_object_condition(adhoc1, condition)
 
-        adhoc2 = dev2.start_adhoc("AdHocNetwork", "secret123")
+        if not client:
+            adhoc2 = dev2.start_adhoc("AdHocNetwork", "secret123")
+        else:
+            ctx.start_process(['iwctl', 'device', dev2.name, 'set-property',
+                                'Mode', 'ad-hoc'], check=True)
+            ctx.start_process(['iwctl', 'ad-hoc', dev2.name, 'start',
+                                'AdHocNetwork', 'secret123'], check=True)
+            adhoc2 = AdHocDevice(dev2.device_path)
 
         condition = 'obj.started == True'
         wd.wait_for_object_condition(adhoc1, condition)
@@ -42,6 +49,10 @@ class Test(unittest.TestCase):
 
         self.validate_connection(wd)
 
+    def test_client_adhoc(self):
+        wd = IWD(True)
+        self.validate_connection(wd, client=True)
+
     @classmethod
     def setUpClass(cls):
         pass
Signature · 1 line
2.34.1
#4 lore raw

PATCH 5/7 auto-t: add client test to testDPP

In reply to James Prestwood

Tests iwctl functionality with dpp commands

---
 autotests/testDPP/connection_test.py | 34 ++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
autotests/testDPP/connection_test.py +34 -0
index 0f9b8f1c..0cab5ff1 100644
@@ -5,9 +5,11 @@ import sys
 
 sys.path.append('../util')
 from iwd import IWD
+from iwd import DeviceProvisioning
 from wpas import Wpas
 from hostapd import HostapdCLI
 from hwsim import Hwsim
+from config import ctx
 
 class Test(unittest.TestCase):
     def test_iwd_as_enrollee(self):
@@ -98,6 +100,38 @@ class Test(unittest.TestCase):
 
         self.wpas.wait_for_event('DPP-CONF-RECEIVED', timeout=30)
 
+    def test_client_as_configurator(self):
+        self.hapd.reload()
+        self.hapd.wait_for_event('AP-ENABLED')
+
+        IWD.copy_to_storage('ssidCCMP.psk')
+        self.device.autoconnect = True
+
+        condition = 'obj.state == DeviceState.connected'
+        self.wd.wait_for_object_condition(self.device, condition)
+
+        ctx.start_process(['iwctl', 'dpp', self.device.name, 'start-configurator'], check=True)
+
+        dpp = DeviceProvisioning(self.device.device_path)
+
+        self.wpas.dpp_enrollee_start(dpp.uri)
+
+        self.wpas.wait_for_event('DPP-CONF-RECEIVED', timeout=30)
+
+    def test_client_as_enrollee(self):
+        self.device.autoconnect = True
+        self.hapd.reload()
+
+        ctx.start_process(['iwctl', 'dpp', self.device.name, 'start-enrollee'], check=True)
+
+        dpp = DeviceProvisioning(self.device.device_path)
+
+        self.wpas.dpp_configurator_create(dpp.uri)
+        self.wpas.dpp_configurator_start('ssidCCMP', 'secret123')
+
+        condition = 'obj.state == DeviceState.connected'
+        self.wd.wait_for_object_condition(self.device, condition)
+
     def setUp(self):
         self.wpas = Wpas('wpas.conf')
         self.wd = IWD(True)
Signature · 1 line
2.34.1
#5 lore raw

PATCH 6/7 auto-t: refactor testAP to reuse code

In reply to James Prestwood

All the AP tests were basically doing the same validation. Refactor this code into validation.py and import that into the tests.

---
 autotests/testAP/connection_test.py  | 74 ++--------------------------
 autotests/testAP/dhcp_config_test.py | 49 ++----------------
 autotests/testAP/dhcp_test.py        | 69 +++++++++-----------------
 autotests/testAP/validation.py       | 71 ++++++++++++++++++++++++++
 4 files changed, 102 insertions(+), 161 deletions(-)
 create mode 100644 autotests/testAP/validation.py
autotests/testAP/connection_test.py +4 -70
index 02213947..273c333c 100644
@@ -1,90 +1,24 @@
 #! /usr/bin/python3
 
 import unittest
-import sys, os
 
-import iwd
 from iwd import IWD
-from iwd import PSKAgent
-from iwd import NetworkType
-from hostapd import HostapdCLI
-import testutil
+from validation import validate, client_connect
 
 class Test(unittest.TestCase):
-
-    def client_connect(self, wd, dev):
-        hostapd = HostapdCLI(config='psk-ccmp.conf')
-
-        ordered_network = dev.get_ordered_network('TestAP1')
-
-        self.assertEqual(ordered_network.type, NetworkType.psk)
-
-        psk_agent = PSKAgent('Password1')
-        wd.register_psk_agent(psk_agent)
-
-        ordered_network.network_object.connect()
-
-        condition = 'obj.state == DeviceState.connected'
-        wd.wait_for_object_condition(dev, condition)
-
-        wd.unregister_psk_agent(psk_agent)
-
-        testutil.test_iface_operstate(dev.name)
-        testutil.test_ifaces_connected(hostapd.ifname, dev.name)
-
-        dev.disconnect()
-
-        condition = 'not obj.connected'
-        wd.wait_for_object_condition(ordered_network.network_object, condition)
-
     def test_connection_success(self):
         wd = IWD(True)
 
         dev1, dev2 = wd.list_devices(2)
 
-        self.client_connect(wd, dev1)
+        client_connect(wd, dev1, 'TestAP1')
 
         dev1.start_ap('TestAP2', 'Password2')
 
-        try:
-            networks = {}
-            networks['TestAP1'] = dev2.get_ordered_network('TestAP1', full_scan=True)
-            networks['TestAP2'] = dev2.get_ordered_network('TestAP2', full_scan=True)
-
-            self.assertEqual(networks['TestAP1'].type, NetworkType.psk)
-            self.assertEqual(networks['TestAP2'].type, NetworkType.psk)
-
-            psk_agent = PSKAgent('Password2')
-            wd.register_psk_agent(psk_agent)
-
-            try:
-                dev2.disconnect()
-
-                condition = 'not obj.connected'
-                wd.wait_for_object_condition(dev2, condition)
-            except:
-                pass
-
-            networks['TestAP2'].network_object.connect()
-
-            condition = 'obj.state == DeviceState.connected'
-            wd.wait_for_object_condition(dev2, condition)
-
-            testutil.test_iface_operstate(dev2.name)
-            testutil.test_ifaces_connected(dev1.name, dev2.name, group=False)
-
-            wd.unregister_psk_agent(psk_agent)
-
-            dev2.disconnect()
-
-            condition = 'not obj.connected'
-            wd.wait_for_object_condition(networks['TestAP2'].network_object,
-                                         condition)
-        finally:
-            dev1.stop_ap()
+        validate(wd, dev2, dev1, 'TestAP2', 'Password2')
 
         # Finally test dev1 can go to client mode and connect again
-        self.client_connect(wd, dev1)
+        client_connect(wd, dev1, 'TestAP1')
 
     @classmethod
     def setUpClass(cls):
autotests/testAP/dhcp_config_test.py +3 -46

64 lines not on this page · raw message

autotests/testAP/dhcp_test.py +24 -45

89 lines not on this page · raw message

autotests/testAP/validation.py new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
2.34.1
#6 lore raw

PATCH 7/7 auto-t: add client test to testAP

In reply to James Prestwood

Tests iwctl functionality with ap commands

---
 autotests/testAP/connection_test.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
autotests/testAP/connection_test.py +19 -0
index 273c333c..dff415e7 100644
@@ -3,6 +3,7 @@
 import unittest
 
 from iwd import IWD
+from config import ctx
 from validation import validate, client_connect
 
 class Test(unittest.TestCase):
@@ -20,6 +21,24 @@ class Test(unittest.TestCase):
         # Finally test dev1 can go to client mode and connect again
         client_connect(wd, dev1, 'TestAP1')
 
+    def test_client_start_ap(self):
+        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')
+
     @classmethod
     def setUpClass(cls):
         IWD.copy_to_storage('TestAP1.psk')
Signature · 1 line
2.34.1