diff mbox series

[v2,4/5] auto-t: add DPP tests for state change checks

Message ID 20240722182932.4091008-4-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [v2,1/5] dpp: factor out PKEX/DPP start prep into function | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood July 22, 2024, 6:29 p.m. UTC
---
 autotests/testDPP/pkex_test.py         |  20 ++++-
 autotests/testDPP/state_change_test.py | 107 +++++++++++++++++++++++++
 2 files changed, 126 insertions(+), 1 deletion(-)
 create mode 100644 autotests/testDPP/state_change_test.py
diff mbox series

Patch

diff --git a/autotests/testDPP/pkex_test.py b/autotests/testDPP/pkex_test.py
index db355225..3d3ea6d1 100644
--- a/autotests/testDPP/pkex_test.py
+++ b/autotests/testDPP/pkex_test.py
@@ -4,7 +4,7 @@  import unittest
 import sys
 
 sys.path.append('../util')
-from iwd import IWD, SharedCodeAgent
+from iwd import IWD, SharedCodeAgent, DeviceState
 from iwd import DeviceProvisioning
 from wpas import Wpas
 from hostapd import HostapdCLI
@@ -210,6 +210,24 @@  class Test(unittest.TestCase):
 
         self.assertIn("SendHostname=true", settings)
 
+    def test_existing_incorrect_profile(self):
+        self.hapd.reload()
+        self.hapd.wait_for_event('AP-ENABLED')
+        IWD.copy_to_storage("existingProfile.psk", "/tmp/ns0/", "ssidCCMP.psk")
+
+        # Start connecting
+        self.device[1].autoconnect = True
+        self.wd.wait_for_object_condition(self.device[1], 'obj.state == DeviceState.connecting')
+
+        # We should be able to start DPP despite the connecting state
+        self.device[1].dpp_pkex_enroll('secret123', identifier="test")
+
+        self.start_iwd_pkex_configurator(self.device[0])
+        self.assertEqual(self.device[1].state, DeviceState.disconnected)
+
+        condition = 'obj.state == DeviceState.connected'
+        self.wd.wait_for_object_condition(self.device[1], condition)
+
     def test_existing_hidden_network(self):
         self.hapd_hidden.reload()
         self.hapd_hidden.wait_for_event('AP-ENABLED')
diff --git a/autotests/testDPP/state_change_test.py b/autotests/testDPP/state_change_test.py
new file mode 100644
index 00000000..d52f2b12
--- /dev/null
+++ b/autotests/testDPP/state_change_test.py
@@ -0,0 +1,107 @@ 
+#!/usr/bin/python3
+
+import unittest
+import sys
+
+sys.path.append('../util')
+from iwd import IWD, SharedCodeAgent, DeviceState
+from iwd import DeviceProvisioning
+from wpas import Wpas
+from hostapd import HostapdCLI
+from hwsim import Hwsim
+from config import ctx
+from time import time
+import os
+
+class Test(unittest.TestCase):
+    def auto_connect(self):
+        IWD.copy_to_storage('ssidCCMP.psk')
+        self.device.autoconnect = True
+
+        condition = 'obj.state == DeviceState.connected'
+        self.wd.wait_for_object_condition(self.device, condition)
+
+    def test_configurator_stops_on_disconnect(self):
+        self.auto_connect()
+
+        self.device.dpp_start_configurator()
+
+        self.device.disconnect()
+
+        condition = 'obj.state == DeviceState.disconnected'
+        self.wd.wait_for_object_condition(self.device, condition)
+
+        self.assertEqual(self.device._device_provisioning.started, False)
+
+    def test_enrollee_stops_on_connect(self):
+        # Scan to get a list of networks
+        self.device.scan()
+        self.wd.wait_for_object_condition(self.device, 'obj.scanning == True')
+        self.wd.wait_for_object_condition(self.device, 'obj.scanning == False')
+
+        self.device.dpp_start_enrollee()
+
+        network = self.device.get_ordered_network("ssidCCMP")
+        network.network_object.connect()
+
+        condition = 'obj.state == DeviceState.connected'
+        self.wd.wait_for_object_condition(self.device, condition)
+
+        self.assertEqual(self.device._device_provisioning.started, False)
+
+    def test_enrollee_disconnects_automatically(self):
+        self.auto_connect()
+
+        self.device.dpp_start_enrollee()
+
+        condition = 'obj.state == DeviceState.disconnected'
+        self.wd.wait_for_object_condition(self.device, condition)
+
+    def test_enrollee_autoconnect_stays_on(self):
+        # Put in an autoconnecting state, no saved profile though
+        self.device.autoconnect = True
+
+        self.device.dpp_start_enrollee()
+
+        # DPP should set autoconnect false, but then re-enable after it stops
+        self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False")
+        self.wd.wait_for_object_condition(self.device._device_provisioning, "obj.started == True")
+
+        # Stop DPP
+        self.device.dpp_stop()
+        self.wd.wait_for_object_condition(self.device, "obj.autoconnect == True")
+
+    def test_enrollee_autoconnect_stays_off(self):
+        # Autoconnect should be off by default
+
+        self.device.dpp_start_enrollee()
+
+        # DPP should set autoconnect false, but stay off after it stops
+        self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False")
+        self.wd.wait_for_object_condition(self.device._device_provisioning, "obj.started == True")
+
+        # Stop DPP
+        self.device.dpp_stop()
+        self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False")
+
+    def setUp(self):
+        self.wd = IWD(True)
+        self.device = self.wd.list_devices(1)[0]
+
+    def tearDown(self):
+        self.wd.stop()
+        self.wd = None
+
+    @classmethod
+    def setUpClass(cls):
+        hapd = HostapdCLI(config="hostapd.conf")
+        hapd.reload()
+
+        hapd.wait_for_event("AP-ENABLED")
+
+    @classmethod
+    def tearDownClass(cls):
+        pass
+
+if __name__ == '__main__':
+    unittest.main(exit=True)
\ No newline at end of file