tests: Fix DPP capability checking to avoid failures in non-DPP build

"finally" handler should not trigger a new exception when trying to
clear state for non-DPP builds. In addition, couple of checks for DPP
capability in the build were missing.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2020-01-26 13:28:43 +02:00
parent 4c0af8ad6c
commit 5bf51d38b0
3 changed files with 38 additions and 33 deletions

View File

@ -1713,14 +1713,14 @@ def test_dpp_auto_connect_1(dev, apdev):
try: try:
run_dpp_auto_connect(dev, apdev, 1) run_dpp_auto_connect(dev, apdev, 1)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_auto_connect_2(dev, apdev): def test_dpp_auto_connect_2(dev, apdev):
"""DPP and auto connect (2)""" """DPP and auto connect (2)"""
try: try:
run_dpp_auto_connect(dev, apdev, 2) run_dpp_auto_connect(dev, apdev, 2)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_auto_connect_2_connect_cmd(dev, apdev): def test_dpp_auto_connect_2_connect_cmd(dev, apdev):
"""DPP and auto connect (2) using connect_cmd""" """DPP and auto connect (2) using connect_cmd"""
@ -1730,7 +1730,7 @@ def test_dpp_auto_connect_2_connect_cmd(dev, apdev):
try: try:
run_dpp_auto_connect(dev_new, apdev, 2) run_dpp_auto_connect(dev_new, apdev, 2)
finally: finally:
wpas.set("dpp_config_processing", "0") wpas.set("dpp_config_processing", "0", allow_fail=True)
def run_dpp_auto_connect(dev, apdev, processing): def run_dpp_auto_connect(dev, apdev, processing):
check_dpp_capab(dev[0]) check_dpp_capab(dev[0])
@ -1777,28 +1777,28 @@ def test_dpp_auto_connect_legacy(dev, apdev):
try: try:
run_dpp_auto_connect_legacy(dev, apdev) run_dpp_auto_connect_legacy(dev, apdev)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_auto_connect_legacy_ssid_charset(dev, apdev): def test_dpp_auto_connect_legacy_ssid_charset(dev, apdev):
"""DPP and auto connect (legacy, ssid_charset)""" """DPP and auto connect (legacy, ssid_charset)"""
try: try:
run_dpp_auto_connect_legacy(dev, apdev, ssid_charset=12345) run_dpp_auto_connect_legacy(dev, apdev, ssid_charset=12345)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_auto_connect_legacy_sae_1(dev, apdev): def test_dpp_auto_connect_legacy_sae_1(dev, apdev):
"""DPP and auto connect (legacy SAE)""" """DPP and auto connect (legacy SAE)"""
try: try:
run_dpp_auto_connect_legacy(dev, apdev, conf='sta-sae', psk_sae=True) run_dpp_auto_connect_legacy(dev, apdev, conf='sta-sae', psk_sae=True)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_auto_connect_legacy_sae_2(dev, apdev): def test_dpp_auto_connect_legacy_sae_2(dev, apdev):
"""DPP and auto connect (legacy SAE)""" """DPP and auto connect (legacy SAE)"""
try: try:
run_dpp_auto_connect_legacy(dev, apdev, conf='sta-sae', sae_only=True) run_dpp_auto_connect_legacy(dev, apdev, conf='sta-sae', sae_only=True)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_auto_connect_legacy_psk_sae_1(dev, apdev): def test_dpp_auto_connect_legacy_psk_sae_1(dev, apdev):
"""DPP and auto connect (legacy PSK+SAE)""" """DPP and auto connect (legacy PSK+SAE)"""
@ -1806,7 +1806,7 @@ def test_dpp_auto_connect_legacy_psk_sae_1(dev, apdev):
run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk-sae', run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk-sae',
psk_sae=True) psk_sae=True)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_auto_connect_legacy_psk_sae_2(dev, apdev): def test_dpp_auto_connect_legacy_psk_sae_2(dev, apdev):
"""DPP and auto connect (legacy PSK+SAE)""" """DPP and auto connect (legacy PSK+SAE)"""
@ -1814,14 +1814,14 @@ def test_dpp_auto_connect_legacy_psk_sae_2(dev, apdev):
run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk-sae', run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk-sae',
sae_only=True) sae_only=True)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_auto_connect_legacy_psk_sae_3(dev, apdev): def test_dpp_auto_connect_legacy_psk_sae_3(dev, apdev):
"""DPP and auto connect (legacy PSK+SAE)""" """DPP and auto connect (legacy PSK+SAE)"""
try: try:
run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk-sae') run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk-sae')
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk', def run_dpp_auto_connect_legacy(dev, apdev, conf='sta-psk',
ssid_charset=None, ssid_charset=None,
@ -1870,7 +1870,7 @@ def test_dpp_auto_connect_legacy_pmf_required(dev, apdev):
try: try:
run_dpp_auto_connect_legacy_pmf_required(dev, apdev) run_dpp_auto_connect_legacy_pmf_required(dev, apdev)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def run_dpp_auto_connect_legacy_pmf_required(dev, apdev): def run_dpp_auto_connect_legacy_pmf_required(dev, apdev):
check_dpp_capab(dev[0]) check_dpp_capab(dev[0])
@ -2408,21 +2408,21 @@ def test_dpp_own_config(dev, apdev):
try: try:
run_dpp_own_config(dev, apdev) run_dpp_own_config(dev, apdev)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_own_config_group_id(dev, apdev): def test_dpp_own_config_group_id(dev, apdev):
"""DPP configurator signing own connector""" """DPP configurator signing own connector"""
try: try:
run_dpp_own_config(dev, apdev, extra=" group_id=test-group") run_dpp_own_config(dev, apdev, extra=" group_id=test-group")
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_own_config_curve_mismatch(dev, apdev): def test_dpp_own_config_curve_mismatch(dev, apdev):
"""DPP configurator signing own connector using mismatching curve""" """DPP configurator signing own connector using mismatching curve"""
try: try:
run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True) run_dpp_own_config(dev, apdev, own_curve="BP-384", expect_failure=True)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False, def run_dpp_own_config(dev, apdev, own_curve=None, expect_failure=False,
extra=None): extra=None):
@ -2463,21 +2463,21 @@ def test_dpp_own_config_ap(dev, apdev):
try: try:
run_dpp_own_config_ap(dev, apdev) run_dpp_own_config_ap(dev, apdev)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_own_config_ap_group_id(dev, apdev): def test_dpp_own_config_ap_group_id(dev, apdev):
"""DPP configurator (AP) signing own connector (group_id)""" """DPP configurator (AP) signing own connector (group_id)"""
try: try:
run_dpp_own_config_ap(dev, apdev, extra=" group_id=test-group") run_dpp_own_config_ap(dev, apdev, extra=" group_id=test-group")
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_own_config_ap_reconf(dev, apdev): def test_dpp_own_config_ap_reconf(dev, apdev):
"""DPP configurator (AP) signing own connector and configurator reconf""" """DPP configurator (AP) signing own connector and configurator reconf"""
try: try:
run_dpp_own_config_ap(dev, apdev) run_dpp_own_config_ap(dev, apdev)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def run_dpp_own_config_ap(dev, apdev, reconf_configurator=False, extra=None): def run_dpp_own_config_ap(dev, apdev, reconf_configurator=False, extra=None):
check_dpp_capab(dev[0]) check_dpp_capab(dev[0])
@ -2517,10 +2517,10 @@ def test_dpp_intro_mismatch(dev, apdev):
check_dpp_capab(wpas) check_dpp_capab(wpas)
run_dpp_intro_mismatch(dev, apdev, wpas) run_dpp_intro_mismatch(dev, apdev, wpas)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
dev[2].set("dpp_config_processing", "0") dev[2].set("dpp_config_processing", "0", allow_fail=True)
if wpas: if wpas:
wpas.set("dpp_config_processing", "0") wpas.set("dpp_config_processing", "0", allow_fail=True)
def run_dpp_intro_mismatch(dev, apdev, wpas): def run_dpp_intro_mismatch(dev, apdev, wpas):
check_dpp_capab(dev[0]) check_dpp_capab(dev[0])
@ -4001,7 +4001,7 @@ def test_dpp_peer_intro_failures(dev, apdev):
try: try:
run_dpp_peer_intro_failures(dev, apdev) run_dpp_peer_intro_failures(dev, apdev)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def run_dpp_peer_intro_failures(dev, apdev): def run_dpp_peer_intro_failures(dev, apdev):
check_dpp_capab(dev[0]) check_dpp_capab(dev[0])
@ -4229,7 +4229,7 @@ def test_dpp_network_addition_failure(dev, apdev):
try: try:
run_dpp_network_addition_failure(dev, apdev) run_dpp_network_addition_failure(dev, apdev)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def run_dpp_network_addition_failure(dev, apdev): def run_dpp_network_addition_failure(dev, apdev):
check_dpp_capab(dev[0]) check_dpp_capab(dev[0])
@ -4297,6 +4297,7 @@ def test_dpp_conf_file_update(dev, apdev, params):
f.write("update_config=1\n") f.write("update_config=1\n")
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5') wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
wpas.interface_add("wlan5", config=config) wpas.interface_add("wlan5", config=config)
check_dpp_capab(wpas)
wpas.set("dpp_config_processing", "1") wpas.set("dpp_config_processing", "1")
run_dpp_qr_code_auth_unicast([wpas, dev[1]], apdev, None, run_dpp_qr_code_auth_unicast([wpas, dev[1]], apdev, None,
init_extra="conf=sta-dpp", init_extra="conf=sta-dpp",
@ -4392,7 +4393,7 @@ def test_dpp_legacy_and_dpp_akm(dev, apdev):
try: try:
run_dpp_legacy_and_dpp_akm(dev, apdev) run_dpp_legacy_and_dpp_akm(dev, apdev)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def run_dpp_legacy_and_dpp_akm(dev, apdev): def run_dpp_legacy_and_dpp_akm(dev, apdev):
check_dpp_capab(dev[0], min_ver=2) check_dpp_capab(dev[0], min_ver=2)
@ -4472,7 +4473,7 @@ def test_dpp_controller_relay(dev, apdev, params):
try: try:
run_dpp_controller_relay(dev, apdev, params) run_dpp_controller_relay(dev, apdev, params)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
dev[1].request("DPP_CONTROLLER_STOP") dev[1].request("DPP_CONTROLLER_STOP")
def run_dpp_controller_relay(dev, apdev, params): def run_dpp_controller_relay(dev, apdev, params):
@ -4700,28 +4701,28 @@ def test_dpp_conn_status_success(dev, apdev):
try: try:
run_dpp_conn_status(dev, apdev) run_dpp_conn_status(dev, apdev)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_conn_status_wrong_passphrase(dev, apdev): def test_dpp_conn_status_wrong_passphrase(dev, apdev):
"""DPP connection status - wrong passphrase""" """DPP connection status - wrong passphrase"""
try: try:
run_dpp_conn_status(dev, apdev, result=2) run_dpp_conn_status(dev, apdev, result=2)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_conn_status_no_ap(dev, apdev): def test_dpp_conn_status_no_ap(dev, apdev):
"""DPP connection status - no AP""" """DPP connection status - no AP"""
try: try:
run_dpp_conn_status(dev, apdev, result=10) run_dpp_conn_status(dev, apdev, result=10)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_conn_status_connector_mismatch(dev, apdev): def test_dpp_conn_status_connector_mismatch(dev, apdev):
"""DPP connection status - invalid Connector""" """DPP connection status - invalid Connector"""
try: try:
run_dpp_conn_status(dev, apdev, result=8) run_dpp_conn_status(dev, apdev, result=8)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def test_dpp_conn_status_assoc_reject(dev, apdev): def test_dpp_conn_status_assoc_reject(dev, apdev):
"""DPP connection status - association rejection""" """DPP connection status - association rejection"""
@ -4729,7 +4730,7 @@ def test_dpp_conn_status_assoc_reject(dev, apdev):
dev[0].request("TEST_ASSOC_IE 30020000") dev[0].request("TEST_ASSOC_IE 30020000")
run_dpp_conn_status(dev, apdev, assoc_reject=True) run_dpp_conn_status(dev, apdev, assoc_reject=True)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def run_dpp_conn_status(dev, apdev, result=0, assoc_reject=False): def run_dpp_conn_status(dev, apdev, result=0, assoc_reject=False):
check_dpp_capab(dev[0], min_ver=2) check_dpp_capab(dev[0], min_ver=2)
@ -4841,6 +4842,7 @@ def test_dpp_config_save3(dev, apdev, params):
run_dpp_config_save(dev, apdev, config, "\\u0001*\\u00c2\\u00bc\\u00c3\\u009e\\u00c3\\u00bf", '012ac2bcc39ec3bf') run_dpp_config_save(dev, apdev, config, "\\u0001*\\u00c2\\u00bc\\u00c3\\u009e\\u00c3\\u00bf", '012ac2bcc39ec3bf')
def run_dpp_config_save(dev, apdev, config, conf_ssid, exp_ssid): def run_dpp_config_save(dev, apdev, config, conf_ssid, exp_ssid):
check_dpp_capab(dev[1])
with open(config, "w") as f: with open(config, "w") as f:
f.write("update_config=1\n" + f.write("update_config=1\n" +
"dpp_config_processing=1\n") "dpp_config_processing=1\n")

View File

@ -1412,6 +1412,7 @@ def test_sigma_dut_dpp_qr_resp_chan_list(dev, apdev):
def test_sigma_dut_dpp_qr_resp_status_query(dev, apdev): def test_sigma_dut_dpp_qr_resp_status_query(dev, apdev):
"""sigma_dut DPP/QR responder status query""" """sigma_dut DPP/QR responder status query"""
check_dpp_capab(dev[1])
params = hostapd.wpa2_params(ssid="DPPNET01", params = hostapd.wpa2_params(ssid="DPPNET01",
passphrase="ThisIsDppPassphrase") passphrase="ThisIsDppPassphrase")
hapd = hostapd.add_ap(apdev[0], params) hapd = hostapd.add_ap(apdev[0], params)
@ -1420,7 +1421,7 @@ def test_sigma_dut_dpp_qr_resp_status_query(dev, apdev):
dev[1].set("dpp_config_processing", "2") dev[1].set("dpp_config_processing", "2")
run_sigma_dut_dpp_qr_resp(dev, apdev, 3, status_query=True) run_sigma_dut_dpp_qr_resp(dev, apdev, 3, status_query=True)
finally: finally:
dev[1].set("dpp_config_processing", "0") dev[1].set("dpp_config_processing", "0", allow_fail=True)
def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx, chan_list=None, def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx, chan_list=None,
listen_chan=None, status_query=False): listen_chan=None, status_query=False):
@ -2538,7 +2539,7 @@ def test_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent" not in res: if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent" not in res:
raise Exception("Unexpected result: " + res) raise Exception("Unexpected result: " + res)
finally: finally:
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
stop_sigma_dut(sigma) stop_sigma_dut(sigma)
def test_sigma_dut_dpp_self_config(dev, apdev): def test_sigma_dut_dpp_self_config(dev, apdev):
@ -2581,7 +2582,7 @@ def test_sigma_dut_ap_dpp_self_config(dev, apdev, params):
run_sigma_dut_ap_dpp_self_config(dev, apdev) run_sigma_dut_ap_dpp_self_config(dev, apdev)
finally: finally:
stop_sigma_dut(sigma) stop_sigma_dut(sigma)
dev[0].set("dpp_config_processing", "0") dev[0].set("dpp_config_processing", "0", allow_fail=True)
def run_sigma_dut_ap_dpp_self_config(dev, apdev): def run_sigma_dut_ap_dpp_self_config(dev, apdev):
check_dpp_capab(dev[0]) check_dpp_capab(dev[0])

View File

@ -330,8 +330,10 @@ class WpaSupplicant:
if not self.ping(): if not self.ping():
logger.info("No PING response from " + self.ifname + " after reset") logger.info("No PING response from " + self.ifname + " after reset")
def set(self, field, value): def set(self, field, value, allow_fail=False):
if "OK" not in self.request("SET " + field + " " + value): if "OK" not in self.request("SET " + field + " " + value):
if allow_fail:
return
raise Exception("Failed to set wpa_supplicant parameter " + field) raise Exception("Failed to set wpa_supplicant parameter " + field)
def add_network(self): def add_network(self):