tests: Use dictionary as add_cred_values() parameter

This makes it more convenient to use this function for cases that modify
credential parameters.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
Jouni Malinen 2013-11-04 13:09:46 +02:00 committed by Jouni Malinen
parent 5c5656c37a
commit 2232edf8e2
2 changed files with 35 additions and 32 deletions

View file

@ -130,14 +130,15 @@ def test_ap_hs20_select(dev, apdev):
hostapd.add_ap(apdev[0]['ifname'], params) hostapd.add_ap(apdev[0]['ifname'], params)
dev[0].hs20_enable() dev[0].hs20_enable()
id = dev[0].add_cred_values(realm="example.com", username="test", id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
password="secret", domain="example.com") 'password': "secret",
'domain': "example.com" })
interworking_select(dev[0], bssid, "home") interworking_select(dev[0], bssid, "home")
dev[0].remove_cred(id) dev[0].remove_cred(id)
id = dev[0].add_cred_values(realm="example.com", username="test", id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test",
password="secret", 'password': "secret",
domain="no.match.example.com") 'domain': "no.match.example.com" })
interworking_select(dev[0], bssid, "roaming") interworking_select(dev[0], bssid, "roaming")
dev[0].set_cred_quoted(id, "realm", "no.match.example.com"); dev[0].set_cred_quoted(id, "realm", "no.match.example.com");
@ -156,7 +157,7 @@ def test_ap_hs20_ext_sim(dev, apdev):
dev[0].hs20_enable() dev[0].hs20_enable()
dev[0].request("SET external_sim 1") dev[0].request("SET external_sim 1")
dev[0].add_cred_values(imsi="23201-0000000000", eap="SIM") dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM" })
interworking_select(dev[0], "home") interworking_select(dev[0], "home")
interworking_ext_sim_connect(dev[0], bssid, "SIM") interworking_ext_sim_connect(dev[0], bssid, "SIM")
check_sp_type(dev[0], "home") check_sp_type(dev[0], "home")
@ -174,7 +175,7 @@ def test_ap_hs20_ext_sim_roaming(dev, apdev):
dev[0].hs20_enable() dev[0].hs20_enable()
dev[0].request("SET external_sim 1") dev[0].request("SET external_sim 1")
dev[0].add_cred_values(imsi="23201-0000000000", eap="SIM") dev[0].add_cred_values({ 'imsi': "23201-0000000000", 'eap': "SIM" })
interworking_select(dev[0], "roaming") interworking_select(dev[0], "roaming")
interworking_ext_sim_connect(dev[0], bssid, "SIM") interworking_ext_sim_connect(dev[0], bssid, "SIM")
check_sp_type(dev[0], "roaming") check_sp_type(dev[0], "roaming")
@ -187,8 +188,10 @@ def test_ap_hs20_username(dev, apdev):
hostapd.add_ap(apdev[0]['ifname'], params) hostapd.add_ap(apdev[0]['ifname'], params)
dev[0].hs20_enable() dev[0].hs20_enable()
id = dev[0].add_cred_values(realm="example.com", username="hs20-test", id = dev[0].add_cred_values({ 'realm': "example.com",
password="password", domain="example.com") 'username': "hs20-test",
'password': "password",
'domain': "example.com" })
interworking_select(dev[0], bssid, "home") interworking_select(dev[0], bssid, "home")
interworking_connect(dev[0], bssid, "TTLS") interworking_connect(dev[0], bssid, "TTLS")
check_sp_type(dev[0], "home") check_sp_type(dev[0], "home")
@ -205,9 +208,10 @@ def test_ap_hs20_username_roaming(dev, apdev):
hostapd.add_ap(apdev[0]['ifname'], params) hostapd.add_ap(apdev[0]['ifname'], params)
dev[0].hs20_enable() dev[0].hs20_enable()
id = dev[0].add_cred_values(realm="roaming.example.com", id = dev[0].add_cred_values({ 'realm': "roaming.example.com",
username="hs20-test", 'username': "hs20-test",
password="password", domain="example.com") 'password': "password",
'domain': "example.com" })
interworking_select(dev[0], bssid, "roaming") interworking_select(dev[0], bssid, "roaming")
interworking_connect(dev[0], bssid, "TTLS") interworking_connect(dev[0], bssid, "TTLS")
check_sp_type(dev[0], "roaming") check_sp_type(dev[0], "roaming")
@ -220,9 +224,9 @@ def test_ap_hs20_username_unknown(dev, apdev):
hostapd.add_ap(apdev[0]['ifname'], params) hostapd.add_ap(apdev[0]['ifname'], params)
dev[0].hs20_enable() dev[0].hs20_enable()
id = dev[0].add_cred_values(realm="example.com", id = dev[0].add_cred_values({ 'realm': "example.com",
username="hs20-test", 'username': "hs20-test",
password="password") 'password': "password" })
interworking_select(dev[0], bssid, "unknown") interworking_select(dev[0], bssid, "unknown")
interworking_connect(dev[0], bssid, "TTLS") interworking_connect(dev[0], bssid, "TTLS")
check_sp_type(dev[0], "unknown") check_sp_type(dev[0], "unknown")
@ -236,9 +240,10 @@ def test_ap_hs20_username_unknown2(dev, apdev):
hostapd.add_ap(apdev[0]['ifname'], params) hostapd.add_ap(apdev[0]['ifname'], params)
dev[0].hs20_enable() dev[0].hs20_enable()
id = dev[0].add_cred_values(realm="example.com", id = dev[0].add_cred_values({ 'realm': "example.com",
username="hs20-test", 'username': "hs20-test",
password="password", domain="example.com") 'password': "password",
'domain': "example.com" })
interworking_select(dev[0], bssid, "unknown") interworking_select(dev[0], bssid, "unknown")
interworking_connect(dev[0], bssid, "TTLS") interworking_connect(dev[0], bssid, "TTLS")
check_sp_type(dev[0], "unknown") check_sp_type(dev[0], "unknown")

View file

@ -146,21 +146,19 @@ class WpaSupplicant:
raise Exception("SET_CRED failed") raise Exception("SET_CRED failed")
return None return None
def add_cred_values(self, realm=None, username=None, password=None, def add_cred_values(self, params):
domain=None, imsi=None, eap=None):
id = self.add_cred() id = self.add_cred()
if realm:
self.set_cred_quoted(id, "realm", realm) quoted = [ "realm", "username", "password", "domain", "imsi" ]
if username: for field in quoted:
self.set_cred_quoted(id, "username", username) if field in params:
if password: self.set_cred_quoted(id, field, params[field])
self.set_cred_quoted(id, "password", password)
if domain: not_quoted = [ "eap" ]
self.set_cred_quoted(id, "domain", domain) for field in not_quoted:
if imsi: if field in params:
self.set_cred_quoted(id, "imsi", imsi) self.set_cred(id, field, params[field])
if eap:
self.set_cred(id, "eap", eap)
return id; return id;
def select_network(self, id): def select_network(self, id):