]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_wpas_config.py
1 # wpa_supplicant config file
2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger
= logging
.getLogger()
12 from wpasupplicant
import WpaSupplicant
14 def check_config(config
):
15 with
open(config
, "r") as f
:
17 if "update_config=1\n" not in data
:
18 raise Exception("Missing update_config")
19 if "device_name=name\n" not in data
:
20 raise Exception("Missing device_name")
21 if "eapol_version=2\n" not in data
:
22 raise Exception("Missing eapol_version")
23 if "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=" not in data
:
24 raise Exception("Missing ctrl_interface")
25 if "blob-base64-foo={" not in data
:
26 raise Exception("Missing blob")
27 if "cred={" not in data
:
28 raise Exception("Missing cred")
29 if "network={" not in data
:
30 raise Exception("Missing network")
33 def test_wpas_config_file(dev
):
34 """wpa_supplicant config file parsing/writing"""
35 config
= "/tmp/test_wpas_config_file.conf"
36 if os
.path
.exists(config
):
37 subprocess
.call(['sudo', 'rm', config
])
39 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
41 wpas
.interface_add("wlan5", config
=config
)
46 raise Exception("Missing config file did not result in an error")
49 with
open(config
, "w") as f
:
50 f
.write("update_config=1 \t\r\n")
53 f
.write(" \t\reapol_version=2")
54 for i
in range(0, 100):
57 f
.write("device_name=name#foo\n")
59 wpas
.interface_add("wlan5", config
=config
)
61 id = wpas
.add_network()
62 wpas
.set_network_quoted(id, "ssid", "foo")
63 wpas
.set_network_quoted(id, "psk", "12345678")
64 wpas
.set_network(id, "bssid", "00:11:22:33:44:55")
65 wpas
.set_network(id, "proto", "RSN")
66 wpas
.set_network(id, "key_mgmt", "WPA-PSK-SHA256")
67 wpas
.set_network(id, "pairwise", "CCMP")
68 wpas
.set_network(id, "group", "CCMP")
69 wpas
.set_network(id, "auth_alg", "OPEN")
72 wpas
.set_cred(id, "priority", "3")
73 wpas
.set_cred(id, "sp_priority", "6")
74 wpas
.set_cred(id, "update_identifier", "4")
75 wpas
.set_cred(id, "ocsp", "1")
76 wpas
.set_cred(id, "eap", "TTLS")
77 wpas
.set_cred(id, "req_conn_capab", "6:1234")
78 wpas
.set_cred_quoted(id, "realm", "example.com")
79 wpas
.set_cred_quoted(id, "provisioning_sp", "example.com")
80 wpas
.set_cred_quoted(id, "domain", "example.com")
81 wpas
.set_cred_quoted(id, "domain_suffix_match", "example.com")
82 wpas
.set_cred(id, "roaming_consortium", "112233")
83 wpas
.set_cred(id, "required_roaming_consortium", "112233")
84 wpas
.set_cred_quoted(id, "roaming_partner",
85 "roaming.example.net,1,127,*")
86 wpas
.set_cred_quoted(id, "ca_cert", "/tmp/ca.pem")
87 wpas
.set_cred_quoted(id, "username", "user")
88 wpas
.set_cred_quoted(id, "password", "secret")
89 ev
= wpas
.wait_event(["CRED-MODIFIED 0 password"])
91 wpas
.request("SET blob foo 12345678")
93 if "OK" not in wpas
.request("SAVE_CONFIG"):
94 raise Exception("Failed to save configuration file")
95 if "OK" not in wpas
.global_request("SAVE_CONFIG"):
96 raise Exception("Failed to save configuration file")
98 wpas
.interface_remove("wlan5")
99 data1
= check_config(config
)
101 wpas
.interface_add("wlan5", config
=config
)
102 if len(wpas
.list_networks()) != 1:
103 raise Exception("Unexpected number of networks")
104 if len(wpas
.request("LIST_CREDS").splitlines()) != 2:
105 raise Exception("Unexpected number of credentials")
107 if "OK" not in wpas
.request("SAVE_CONFIG"):
108 raise Exception("Failed to save configuration file")
109 data2
= check_config(config
)
114 raise Exception("Unexpected configuration change")
116 wpas
.request("SET update_config 0")
117 if "OK" in wpas
.request("SAVE_CONFIG"):
118 raise Exception("SAVE_CONFIG succeeded unexpectedly")
119 if "OK" in wpas
.global_request("SAVE_CONFIG"):
120 raise Exception("SAVE_CONFIG (global) succeeded unexpectedly")
122 # symlink config file to itself to break writing
123 subprocess
.call(['rm', config
])
124 subprocess
.call(['ln', '-s', config
, config
])
125 wpas
.request("SET update_config 1")
126 if "OK" in wpas
.request("SAVE_CONFIG"):
127 raise Exception("SAVE_CONFIG succeeded unexpectedly")
128 if "OK" in wpas
.global_request("SAVE_CONFIG"):
129 raise Exception("SAVE_CONFIG (global) succeeded unexpectedly")
132 subprocess
.call(['sudo', 'rm', config
])