From d2432b8b7e26840e6781c42cc487d712c8399093 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 31 Jan 2015 13:26:46 +0200 Subject: [PATCH] tests: PMKSA cache size limit in wpa_supplicant Signed-off-by: Jouni Malinen --- tests/hwsim/test_pmksa_cache.py | 45 +++++++++++++++++++++++++++++++++ tests/hwsim/wpasupplicant.py | 4 +-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/tests/hwsim/test_pmksa_cache.py b/tests/hwsim/test_pmksa_cache.py index 2f38553d9..c55c86d5a 100644 --- a/tests/hwsim/test_pmksa_cache.py +++ b/tests/hwsim/test_pmksa_cache.py @@ -606,3 +606,48 @@ def _test_pmksa_cache_preauth_oom(dev, apdev): dev[0].wait_disconnected() dev[0].wait_connected() dev[0].dump_monitor() + +def test_pmksa_cache_size_limit(dev, apdev): + """PMKSA cache size limit in wpa_supplicant""" + try: + _test_pmksa_cache_size_limit(dev, apdev) + finally: + try: + hapd = hostapd.HostapdGlobal() + hapd.flush() + hapd.remove(apdev[0]['ifname']) + except: + pass + params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache") + bssid = apdev[0]['bssid'] + params['bssid'] = bssid + hostapd.add_ap(apdev[0]['ifname'], params) + +def _test_pmksa_cache_size_limit(dev, apdev): + params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache") + id = dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP", + eap="GPSK", identity="gpsk user", + password="abcdefghijklmnop0123456789abcdef", + scan_freq="2412", only_add_network=True) + for i in range(33): + bssid = apdev[0]['bssid'][0:15] + "%02x" % i + logger.info("Iteration with BSSID " + bssid) + params['bssid'] = bssid + hostapd.add_ap(apdev[0]['ifname'], params) + dev[0].request("BSS_FLUSH 0") + dev[0].scan_for_bss(bssid, freq=2412, only_new=True) + dev[0].select_network(id) + dev[0].wait_connected() + dev[0].request("DISCONNECT") + dev[0].wait_disconnected() + dev[0].dump_monitor() + entries = len(dev[0].request("PMKSA").splitlines()) - 1 + if i == 32: + if entries != 32: + raise Exception("Unexpected number of PMKSA entries after expected removal of the oldest entry") + elif i + 1 != entries: + raise Exception("Unexpected number of PMKSA entries") + + hapd = hostapd.HostapdGlobal() + hapd.flush() + hapd.remove(apdev[0]['ifname']) diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 08fd6875a..6d28768ea 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -864,11 +864,11 @@ class WpaSupplicant: if ev is None: raise Exception("Scan timed out") - def scan_for_bss(self, bssid, freq=None, force_scan=False): + def scan_for_bss(self, bssid, freq=None, force_scan=False, only_new=False): if not force_scan and self.get_bss(bssid) is not None: return for i in range(0, 10): - self.scan(freq=freq, type="ONLY") + self.scan(freq=freq, type="ONLY", only_new=only_new) if self.get_bss(bssid) is not None: return raise Exception("Could not find BSS " + bssid + " in scan")