tests: Convert connect() to use kwargs
This makes it more convenient to add new network block parameters. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
a3b2bdaf24
commit
6f939e591e
2 changed files with 34 additions and 113 deletions
|
@ -16,32 +16,14 @@ import os.path
|
||||||
import hwsim_utils
|
import hwsim_utils
|
||||||
import hostapd
|
import hostapd
|
||||||
|
|
||||||
def eap_connect(dev, ap, method, identity, anonymous_identity=None,
|
def eap_connect(dev, ap, method, identity,
|
||||||
password=None,
|
sha256=False, expect_failure=False, local_error_report=False,
|
||||||
phase1=None, phase2=None, ca_cert=None,
|
**kwargs):
|
||||||
domain_suffix_match=None, password_hex=None,
|
|
||||||
client_cert=None, private_key=None, sha256=False,
|
|
||||||
fragment_size=None, expect_failure=False,
|
|
||||||
local_error_report=False,
|
|
||||||
ca_cert2=None, client_cert2=None, private_key2=None,
|
|
||||||
pac_file=None, subject_match=None, altsubject_match=None,
|
|
||||||
private_key_passwd=None, ocsp=None, dh_file=None):
|
|
||||||
hapd = hostapd.Hostapd(ap['ifname'])
|
hapd = hostapd.Hostapd(ap['ifname'])
|
||||||
id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
|
id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
|
||||||
eap=method, identity=identity,
|
eap=method, identity=identity,
|
||||||
anonymous_identity=anonymous_identity,
|
wait_connect=False, scan_freq="2412", ieee80211w="1",
|
||||||
password=password, phase1=phase1, phase2=phase2,
|
**kwargs)
|
||||||
ca_cert=ca_cert, domain_suffix_match=domain_suffix_match,
|
|
||||||
wait_connect=False, scan_freq="2412",
|
|
||||||
password_hex=password_hex,
|
|
||||||
client_cert=client_cert, private_key=private_key,
|
|
||||||
ieee80211w="1", fragment_size=fragment_size,
|
|
||||||
ca_cert2=ca_cert2, client_cert2=client_cert2,
|
|
||||||
private_key2=private_key2, pac_file=pac_file,
|
|
||||||
subject_match=subject_match,
|
|
||||||
altsubject_match=altsubject_match,
|
|
||||||
private_key_passwd=private_key_passwd,
|
|
||||||
ocsp=ocsp, dh_file=dh_file)
|
|
||||||
eap_check_auth(dev, method, True, sha256=sha256,
|
eap_check_auth(dev, method, True, sha256=sha256,
|
||||||
expect_failure=expect_failure,
|
expect_failure=expect_failure,
|
||||||
local_error_report=local_error_report)
|
local_error_report=local_error_report)
|
||||||
|
|
|
@ -591,105 +591,44 @@ class WpaSupplicant:
|
||||||
raise Exception("Failed to request TDLS teardown")
|
raise Exception("Failed to request TDLS teardown")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def connect(self, ssid=None, ssid2=None, psk=None, proto=None,
|
def connect(self, ssid=None, ssid2=None, **kwargs):
|
||||||
key_mgmt=None, wep_key0=None,
|
|
||||||
ieee80211w=None, pairwise=None, group=None, scan_freq=None,
|
|
||||||
eap=None, identity=None, anonymous_identity=None,
|
|
||||||
password=None, phase1=None, phase2=None, ca_cert=None,
|
|
||||||
domain_suffix_match=None, password_hex=None,
|
|
||||||
client_cert=None, private_key=None, peerkey=False, okc=False,
|
|
||||||
eapol_flags=None, fragment_size=None,
|
|
||||||
wait_connect=True, only_add_network=False,
|
|
||||||
ca_cert2=None, client_cert2=None, private_key2=None,
|
|
||||||
scan_ssid=None, raw_psk=None, pac_file=None,
|
|
||||||
subject_match=None, altsubject_match=None,
|
|
||||||
private_key_passwd=None, ocsp=None, auth_alg=None,
|
|
||||||
dh_file=None):
|
|
||||||
logger.info("Connect STA " + self.ifname + " to AP")
|
logger.info("Connect STA " + self.ifname + " to AP")
|
||||||
id = self.add_network()
|
id = self.add_network()
|
||||||
if ssid:
|
if ssid:
|
||||||
self.set_network_quoted(id, "ssid", ssid)
|
self.set_network_quoted(id, "ssid", ssid)
|
||||||
elif ssid2:
|
elif ssid2:
|
||||||
self.set_network(id, "ssid", ssid2)
|
self.set_network(id, "ssid", ssid2)
|
||||||
if psk:
|
|
||||||
self.set_network_quoted(id, "psk", psk)
|
quoted = [ "psk", "identity", "anonymous_identity", "password",
|
||||||
if raw_psk:
|
"ca_cert", "client_cert", "private_key",
|
||||||
self.set_network(id, "psk", raw_psk)
|
"private_key_passwd", "ca_cert2", "client_cert2",
|
||||||
if proto:
|
"private_key2", "phase1", "phase2", "domain_suffix_match",
|
||||||
self.set_network(id, "proto", proto)
|
"altsubject_match", "subject_match", "pac_file", "dh_file" ]
|
||||||
if key_mgmt:
|
for field in quoted:
|
||||||
self.set_network(id, "key_mgmt", key_mgmt)
|
if field in kwargs and kwargs[field]:
|
||||||
if ieee80211w:
|
self.set_network_quoted(id, field, kwargs[field])
|
||||||
self.set_network(id, "ieee80211w", ieee80211w)
|
|
||||||
if pairwise:
|
not_quoted = [ "proto", "key_mgmt", "ieee80211w", "pairwise",
|
||||||
self.set_network(id, "pairwise", pairwise)
|
"group", "wep_key0", "scan_freq", "eap",
|
||||||
if group:
|
"eapol_flags", "fragment_size", "scan_ssid", "auth_alg" ]
|
||||||
self.set_network(id, "group", group)
|
for field in not_quoted:
|
||||||
if wep_key0:
|
if field in kwargs and kwargs[field]:
|
||||||
self.set_network(id, "wep_key0", wep_key0)
|
self.set_network(id, field, kwargs[field])
|
||||||
if scan_freq:
|
|
||||||
self.set_network(id, "scan_freq", scan_freq)
|
if "raw_psk" in kwargs and kwargs['raw_psk']:
|
||||||
if eap:
|
self.set_network(id, "psk", kwargs['raw_psk'])
|
||||||
self.set_network(id, "eap", eap)
|
if "password_hex" in kwargs and kwargs['password_hex']:
|
||||||
if identity:
|
self.set_network(id, "password", kwargs['password_hex'])
|
||||||
self.set_network_quoted(id, "identity", identity)
|
if "peerkey" in kwargs and kwargs['peerkey']:
|
||||||
if anonymous_identity:
|
|
||||||
self.set_network_quoted(id, "anonymous_identity",
|
|
||||||
anonymous_identity)
|
|
||||||
if password:
|
|
||||||
self.set_network_quoted(id, "password", password)
|
|
||||||
if password_hex:
|
|
||||||
self.set_network(id, "password", password_hex)
|
|
||||||
if ca_cert:
|
|
||||||
self.set_network_quoted(id, "ca_cert", ca_cert)
|
|
||||||
if client_cert:
|
|
||||||
self.set_network_quoted(id, "client_cert", client_cert)
|
|
||||||
if private_key:
|
|
||||||
self.set_network_quoted(id, "private_key", private_key)
|
|
||||||
if private_key_passwd:
|
|
||||||
self.set_network_quoted(id, "private_key_passwd",
|
|
||||||
private_key_passwd)
|
|
||||||
if ca_cert2:
|
|
||||||
self.set_network_quoted(id, "ca_cert2", ca_cert2)
|
|
||||||
if client_cert2:
|
|
||||||
self.set_network_quoted(id, "client_cert2", client_cert2)
|
|
||||||
if private_key2:
|
|
||||||
self.set_network_quoted(id, "private_key2", private_key2)
|
|
||||||
if phase1:
|
|
||||||
self.set_network_quoted(id, "phase1", phase1)
|
|
||||||
if phase2:
|
|
||||||
self.set_network_quoted(id, "phase2", phase2)
|
|
||||||
if domain_suffix_match:
|
|
||||||
self.set_network_quoted(id, "domain_suffix_match",
|
|
||||||
domain_suffix_match)
|
|
||||||
if altsubject_match:
|
|
||||||
self.set_network_quoted(id, "altsubject_match",
|
|
||||||
altsubject_match)
|
|
||||||
if subject_match:
|
|
||||||
self.set_network_quoted(id, "subject_match",
|
|
||||||
subject_match)
|
|
||||||
if peerkey:
|
|
||||||
self.set_network(id, "peerkey", "1")
|
self.set_network(id, "peerkey", "1")
|
||||||
if okc:
|
if "okc" in kwargs and kwargs['okc']:
|
||||||
self.set_network(id, "proactive_key_caching", "1")
|
self.set_network(id, "proactive_key_caching", "1")
|
||||||
if eapol_flags:
|
if "ocsp" in kwargs and kwargs['ocsp']:
|
||||||
self.set_network(id, "eapol_flags", eapol_flags)
|
self.set_network(id, "ocsp", str(kwargs['ocsp']))
|
||||||
if fragment_size:
|
if "only_add_network" in kwargs and kwargs['only_add_network']:
|
||||||
self.set_network(id, "fragment_size", fragment_size)
|
|
||||||
if scan_ssid:
|
|
||||||
self.set_network(id, "scan_ssid", scan_ssid)
|
|
||||||
if pac_file:
|
|
||||||
self.set_network_quoted(id, "pac_file", pac_file)
|
|
||||||
if ocsp:
|
|
||||||
self.set_network(id, "ocsp", str(ocsp))
|
|
||||||
if auth_alg:
|
|
||||||
self.set_network(id, "auth_alg", auth_alg)
|
|
||||||
if dh_file:
|
|
||||||
self.set_network_quoted(id, "dh_file", dh_file)
|
|
||||||
if only_add_network:
|
|
||||||
return id
|
return id
|
||||||
if wait_connect:
|
if "wait_connect" not in kwargs or kwargs['wait_connect']:
|
||||||
if eap:
|
if "eap" in kwargs:
|
||||||
self.connect_network(id, timeout=20)
|
self.connect_network(id, timeout=20)
|
||||||
else:
|
else:
|
||||||
self.connect_network(id)
|
self.connect_network(id)
|
||||||
|
|
Loading…
Reference in a new issue