From 2232edf8e249a6578905a93ff81f2fffd0b0f609 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 4 Nov 2013 13:09:46 +0200 Subject: [PATCH] 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 --- tests/hwsim/test_ap_hs20.py | 41 ++++++++++++++++++++---------------- tests/hwsim/wpasupplicant.py | 26 +++++++++++------------ 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/tests/hwsim/test_ap_hs20.py b/tests/hwsim/test_ap_hs20.py index d8bfe964c..ec907b328 100644 --- a/tests/hwsim/test_ap_hs20.py +++ b/tests/hwsim/test_ap_hs20.py @@ -130,14 +130,15 @@ def test_ap_hs20_select(dev, apdev): hostapd.add_ap(apdev[0]['ifname'], params) dev[0].hs20_enable() - id = dev[0].add_cred_values(realm="example.com", username="test", - password="secret", domain="example.com") + id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test", + 'password': "secret", + 'domain': "example.com" }) interworking_select(dev[0], bssid, "home") dev[0].remove_cred(id) - id = dev[0].add_cred_values(realm="example.com", username="test", - password="secret", - domain="no.match.example.com") + id = dev[0].add_cred_values({ 'realm': "example.com", 'username': "test", + 'password': "secret", + 'domain': "no.match.example.com" }) interworking_select(dev[0], bssid, "roaming") 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].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_ext_sim_connect(dev[0], bssid, "SIM") 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].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_ext_sim_connect(dev[0], bssid, "SIM") check_sp_type(dev[0], "roaming") @@ -187,8 +188,10 @@ def test_ap_hs20_username(dev, apdev): hostapd.add_ap(apdev[0]['ifname'], params) dev[0].hs20_enable() - id = dev[0].add_cred_values(realm="example.com", username="hs20-test", - password="password", domain="example.com") + id = dev[0].add_cred_values({ 'realm': "example.com", + 'username': "hs20-test", + 'password': "password", + 'domain': "example.com" }) interworking_select(dev[0], bssid, "home") interworking_connect(dev[0], bssid, "TTLS") 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) dev[0].hs20_enable() - id = dev[0].add_cred_values(realm="roaming.example.com", - username="hs20-test", - password="password", domain="example.com") + id = dev[0].add_cred_values({ 'realm': "roaming.example.com", + 'username': "hs20-test", + 'password': "password", + 'domain': "example.com" }) interworking_select(dev[0], bssid, "roaming") interworking_connect(dev[0], bssid, "TTLS") 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) dev[0].hs20_enable() - id = dev[0].add_cred_values(realm="example.com", - username="hs20-test", - password="password") + id = dev[0].add_cred_values({ 'realm': "example.com", + 'username': "hs20-test", + 'password': "password" }) interworking_select(dev[0], bssid, "unknown") interworking_connect(dev[0], bssid, "TTLS") 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) dev[0].hs20_enable() - id = dev[0].add_cred_values(realm="example.com", - username="hs20-test", - password="password", domain="example.com") + id = dev[0].add_cred_values({ 'realm': "example.com", + 'username': "hs20-test", + 'password': "password", + 'domain': "example.com" }) interworking_select(dev[0], bssid, "unknown") interworking_connect(dev[0], bssid, "TTLS") check_sp_type(dev[0], "unknown") diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index 8259f869f..0501d0257 100644 --- a/tests/hwsim/wpasupplicant.py +++ b/tests/hwsim/wpasupplicant.py @@ -146,21 +146,19 @@ class WpaSupplicant: raise Exception("SET_CRED failed") return None - def add_cred_values(self, realm=None, username=None, password=None, - domain=None, imsi=None, eap=None): + def add_cred_values(self, params): id = self.add_cred() - if realm: - self.set_cred_quoted(id, "realm", realm) - if username: - self.set_cred_quoted(id, "username", username) - if password: - self.set_cred_quoted(id, "password", password) - if domain: - self.set_cred_quoted(id, "domain", domain) - if imsi: - self.set_cred_quoted(id, "imsi", imsi) - if eap: - self.set_cred(id, "eap", eap) + + quoted = [ "realm", "username", "password", "domain", "imsi" ] + for field in quoted: + if field in params: + self.set_cred_quoted(id, field, params[field]) + + not_quoted = [ "eap" ] + for field in not_quoted: + if field in params: + self.set_cred(id, field, params[field]) + return id; def select_network(self, id):