commit 267feb94b0b437f6b82e0f1295a7973c98d881bd
parent 53e8bf4cb0c040047f41306f7f36ac930db120b0
Author: James Prestwood <prestwoj@gmail.com>
Date: Fri, 24 Jun 2022 16:07:38 -0700
auto-t: fix rekey/reauth logic in a few ways
The rekey/reauth logic was broken in a few different ways.
For rekeys the event list was not being reset so any past 4-way
handshake would allow the call to pass. This actually removes
the need for the sleep in the extended key ID test because the
actual handshake event is waited for correctly.
For both rekeys and reauths, just waiting for the EAP/handshake
events was not enough. Without checking if the client got
disconnected we essentially allow a full disconnect and reconnect,
meaning the rekey/reauth failed.
Now a 'disallow' array can be passed to wait_for_event which will
throw an exception if any events in that array are encountered
while waiting for the target event.
Diffstat:
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/autotests/testWPA2-ext-key-id/connection_test.py b/autotests/testWPA2-ext-key-id/connection_test.py
@@ -50,8 +50,6 @@ class Test(unittest.TestCase):
testutil.test_iface_operstate()
testutil.test_ifaces_connected()
- wd.wait(0.5)
-
device.disconnect()
condition = 'not obj.connected'
diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
@@ -102,23 +102,26 @@ class HostapdCLI(object):
return True
- def _poll_event(self, event):
+ def _poll_event(self, event, disallow):
# Look through the list (most recent is first) until the even is found.
# Once found consume this event and any older ones as to not
# accidentally trigger a false positive later on.
for idx, e in enumerate(self.events):
+ for d in disallow:
+ if d in e:
+ raise Exception('Event %s found while waiting for %s' % (d, event))
if event in e:
self.events = self.events[:idx]
return e
return False
- def wait_for_event(self, event, timeout=10):
+ def wait_for_event(self, event, timeout=10, disallow=[]):
if event == 'AP-ENABLED':
if self.enabled:
return 'AP-ENABLED'
- return ctx.non_block_wait(self._poll_event, timeout, event,
+ return ctx.non_block_wait(self._poll_event, timeout, event, disallow,
exception=TimeoutError("waiting for event"))
def _data_available(self):
@@ -166,8 +169,8 @@ class HostapdCLI(object):
self.events = []
cmd = 'EAPOL_REAUTH ' + client_address
self.ctrl_sock.sendall(cmd.encode('utf-8'))
- self.wait_for_event('CTRL-EVENT-EAP-STARTED')
- self.wait_for_event('CTRL-EVENT-EAP-SUCCESS')
+ self.wait_for_event('CTRL-EVENT-EAP-STARTED', disallow=['AP-STA-DISCONNECTED'])
+ self.wait_for_event('CTRL-EVENT-EAP-SUCCESS', disallow=['AP-STA-DISCONNECTED'])
def reload(self):
# Seemingly all three commands needed for the instance to notice
@@ -234,7 +237,8 @@ class HostapdCLI(object):
if address:
cmd = 'REKEY_PTK %s' % address
self.ctrl_sock.sendall(cmd.encode('utf-8'))
- self.wait_for_event('EAPOL-4WAY-HS-COMPLETED')
+ self.events = []
+ self.wait_for_event('EAPOL-4WAY-HS-COMPLETED', disallow=['AP-STA-DISCONNECTED'])
return
cmd = 'REKEY_GTK'