Skip to contentSkip to conversation

network: handle NULL/hotspot networks when removing secrets

PATCH Superseded James Prestwood 1 participant 4 messages Aug 18, 2021

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 network: handle NULL/hotspot networks when removing secrets

The hotspot case can actually result in network being NULL which ends up crashing when accessing "->secrets". In addition any secrets on this network were never removed for hotspot networks since everything happened in network_unset_hotspot.

---
 src/network.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
src/network.c +9 -2
index 79f3bd33..b794e609 100644
@@ -1823,6 +1823,11 @@ static void network_unset_hotspot(struct network *network, void *user_data)
 		return;
 
 	network_set_info(network, NULL);
+
+	if (network->secrets) {
+		l_queue_destroy(network->secrets, eap_secret_info_free);
+		network->secrets = NULL;
+	}
 }
 
 static void emit_known_network_removed(struct station *station, void *user_data)
@@ -1850,8 +1855,10 @@ static void emit_known_network_removed(struct station *station, void *user_data)
 	if (network && was_hidden)
 		station_hide_network(station, network);
 
-	l_queue_destroy(network->secrets, eap_secret_info_free);
-	network->secrets = NULL;
+	if (network && network->secrets) {
+		l_queue_destroy(network->secrets, eap_secret_info_free);
+		network->secrets = NULL;
+	}
 }
 
 static void network_update_hotspot(struct network *network, void *user_data)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 2/4 hwsim: add Rule.remove_all()

There are really no cases where a test wants to remove a single rule. Most loop through and remove rules individually so this is being added as a convenience.

---
 autotests/util/hwsim.py | 4 ++++
 1 file changed, 4 insertions(+)
autotests/util/hwsim.py +4 -0
index 320e9dfa..4e3b8ec2 100755
@@ -202,6 +202,10 @@ class RuleSet(collections.Mapping):
         self._dict[path] = obj
         return obj
 
+    def remove_all(self):
+        for rule in self._dict.values():
+            rule.remove()
+
 class Radio(HwsimDBusAbstract):
     _iface_name = HWSIM_RADIO_INTERFACE
 
Signature · 1 line
2.31.1
#2 lore raw

PATCH 3/4 auto-t: fix error handling in testHotspot

In reply to James Prestwood

testHotspot suffered from improper cleanup and if a single test failed all subsequent tests would fail due to IWD still running since IWD() was never cleaned up.

In addition the PSK agent and hwsim rules are now set onto the cls object and removed in tearDownClass()

---
 autotests/testHotspot/anqp_delay_test.py  | 38 ++++++++++++++---------
 autotests/testHotspot/autoconnect_test.py |  6 +++-
 autotests/testHotspot/hessid_test.py      |  6 +++-
 autotests/testHotspot/hotspot_test.py     |  6 +++-
 autotests/testHotspot/roaming_test.py     | 14 +++++----
 5 files changed, 46 insertions(+), 24 deletions(-)
autotests/testHotspot/anqp_delay_test.py +23 -15
index 04e5a1d7..22a5bdbe 100644
@@ -17,19 +17,9 @@ from time import sleep
 class Test(unittest.TestCase):
 
     def test_connection_success(self):
-        hwsim = Hwsim()
-
-        bss_radio = hwsim.get_radio('rad0')
-        rule0 = hwsim.rules.create()
-        rule0.source = bss_radio.addresses[0]
-        rule0.bidirectional = True
-
-        wd = IWD(True)
-
-        hapd = HostapdCLI(config='ssidHotspot.conf')
-
-        psk_agent = PSKAgent('abc', ('domain\\user', 'testpasswd'))
-        wd.register_psk_agent(psk_agent)
+        wd = self.wd
+        hapd = self.hapd
+        rule0 = self.rule0
 
         devices = wd.list_devices(1)
         device = devices[0]
@@ -82,17 +72,35 @@ class Test(unittest.TestCase):
         condition = 'not obj.connected'
         wd.wait_for_object_condition(ordered_network.network_object, condition)
 
-        wd.unregister_psk_agent(psk_agent)
-
     @classmethod
     def setUpClass(cls):
+        cls.hwsim = Hwsim()
+
+        bss_radio = cls.hwsim.get_radio('rad0')
+        cls.rule0 = cls.hwsim.rules.create()
+        cls.rule0.source = bss_radio.addresses[0]
+        cls.rule0.bidirectional = True
+
+        cls.hapd = HostapdCLI(config='ssidHotspot.conf')
+
         IWD.copy_to_hotspot('example.conf')
         IWD.copy_to_storage('anqp_enabled.conf', storage_dir=IWD_CONFIG_DIR, name='main.conf')
 
+        cls.wd = IWD(True)
+        cls.psk_agent = PSKAgent('abc', ('domain\\user', 'testpasswd'))
+        cls.wd.register_psk_agent(cls.psk_agent)
+
     @classmethod
     def tearDownClass(cls):
         IWD.clear_storage()
+
+        cls.wd.unregister_psk_agent(cls.psk_agent)
+        cls.psk_agent = None
         os.remove('/tmp/main.conf')
 
+        cls.hwsim.rules.remove_all()
+        cls.hwsim = None
+        cls.wd = None
+
 if __name__ == '__main__':
     unittest.main(exit=True)
autotests/testHotspot/autoconnect_test.py +5 -1
index 777a0670..8b718dc7 100644
@@ -14,7 +14,7 @@ import testutil
 class Test(unittest.TestCase):
 
     def test_connection_success(self):
-        wd = IWD(True, '/tmp')
+        wd = self.wd
 
         hapd_hotspot = HostapdCLI(config='ssidHotspot.conf')
         hapd_wpa = HostapdCLI(config='ssidWPA2-1.conf')
@@ -111,10 +111,14 @@ class Test(unittest.TestCase):
         IWD.copy_to_storage('ssidWPA2-1.psk')
         IWD.copy_to_storage('anqp_enabled.conf', storage_dir=IWD_CONFIG_DIR, name='main.conf')
 
+        cls.wd = IWD(True)
+
     @classmethod
     def tearDownClass(cls):
         IWD.clear_storage()
         os.remove('/tmp/main.conf')
 
+        cls.wd = None
+
 if __name__ == '__main__':
     unittest.main(exit=True)
autotests/testHotspot/hessid_test.py +5 -1
index 88e750de..4a47e5c7 100644
@@ -15,7 +15,7 @@ import testutil
 class Test(unittest.TestCase):
 
     def test_connection_success(self):
-        wd = IWD(True, '/tmp')
+        wd = self.wd
 
         hapd = HostapdCLI(config='ssidHotspot.conf')
 
@@ -52,10 +52,14 @@ class Test(unittest.TestCase):
         IWD.copy_to_hotspot('hessid.conf')
         IWD.copy_to_storage('anqp_disabled.conf', storage_dir=IWD_CONFIG_DIR, name='main.conf')
 
+        cls.wd = IWD(True)
+
     @classmethod
     def tearDownClass(cls):
         IWD.clear_storage()
         os.remove('/tmp/main.conf')
 
+        cls.wd = None
+
 if __name__ == '__main__':
     unittest.main(exit=True)
autotests/testHotspot/hotspot_test.py +5 -1
index f49477dc..054a1a8f 100644
@@ -15,7 +15,7 @@ import testutil
 class Test(unittest.TestCase):
 
     def test_connection_success(self):
-        wd = IWD(True, '/tmp')
+        wd = self.wd
 
         hapd = HostapdCLI(config='ssidHotspot.conf')
 
@@ -52,10 +52,14 @@ class Test(unittest.TestCase):
         IWD.copy_to_hotspot('example.conf')
         IWD.copy_to_storage('anqp_enabled.conf', storage_dir=IWD_CONFIG_DIR, name='main.conf')
 
+        cls.wd = IWD(True)
+
     @classmethod
     def tearDownClass(cls):
         IWD.clear_storage()
         os.remove('/tmp/main.conf')
 
+        cls.wd = None
+
 if __name__ == '__main__':
     unittest.main(exit=True)
autotests/testHotspot/roaming_test.py +8 -6
index 6cdd6922..1d785700 100644
@@ -15,13 +15,10 @@ import testutil
 class Test(unittest.TestCase):
 
     def test_connection_success(self):
-        wd = IWD(True, '/tmp')
+        wd = self.wd
 
         hapd = HostapdCLI(config='ssidHotspot.conf')
 
-        psk_agent = PSKAgent('abc', ('domain\\user', 'testpasswd'))
-        wd.register_psk_agent(psk_agent)
-
         devices = wd.list_devices(1)
         device = devices[0]
 
@@ -45,17 +42,22 @@ class Test(unittest.TestCase):
         condition = 'not obj.connected'
         wd.wait_for_object_condition(ordered_network.network_object, condition)
 
-        wd.unregister_psk_agent(psk_agent)
-
     @classmethod
     def setUpClass(cls):
         IWD.copy_to_hotspot('roaming.conf')
         IWD.copy_to_storage('anqp_disabled.conf', storage_dir=IWD_CONFIG_DIR, name='main.conf')
 
+        cls.wd = IWD(True)
+        cls.psk_agent = PSKAgent('abc', ('domain\\user', 'testpasswd'))
+        cls.wd.register_psk_agent(cls.psk_agent)
+
     @classmethod
     def tearDownClass(cls):
         IWD.clear_storage()
         os.remove('/tmp/main.conf')
 
+        cls.wd.unregister_psk_agent(cls.psk_agent)
+        cls.wd = None
+
 if __name__ == '__main__':
     unittest.main(exit=True)
Signature · 1 line
2.31.1
#3 lore raw

PATCH 4/4 test-runner: fix subtest option

In reply to James Prestwood

This was not working correctly and would run all subtests when only a single was requested

---
 tools/test-runner | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
tools/test-runner +6 -4
index dc65cca4..a19ce1d9 100755
@@ -1271,16 +1271,18 @@ def pre_test(ctx, test, copied):
 	# Prune down any subtests if needed
 	if ctx.args.sub_tests:
 		ctx.args.sub_tests = ctx.args.sub_tests.split(',')
+
+		to_run = [x.split('.')[0] for x in ctx.args.sub_tests]
 		pruned = []
 
 		for s in subtests:
-			file = s
+			no_ext = s
 			# Handle <file>.<test function> format
 			if '.' in s:
-				file = s.split('.')[0] + '.py'
+				no_ext = s.split('.')[0]
 
-			if file == s:
-				pruned.append(file)
+			if no_ext in to_run:
+				pruned.append(no_ext + '.py')
 
 		subtests = pruned
 
Signature · 1 line
2.31.1