mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-08 09:30:21 +01:00
ifcfg-rh: test case for WEP ASCII keys
This commit is contained in:
parent
36cc9d2e6e
commit
6793eaa38d
6 changed files with 607 additions and 1 deletions
|
|
@ -60,7 +60,11 @@ EXTRA_DIST = \
|
|||
ifcfg-test-wired-static-no-prefix-24 \
|
||||
ifcfg-test-wired-ipv6-only \
|
||||
ifcfg-test-wifi-wep-passphrase \
|
||||
keys-test-wifi-wep-passphrase
|
||||
keys-test-wifi-wep-passphrase \
|
||||
ifcfg-test-wifi-wep-40-ascii \
|
||||
keys-test-wifi-wep-40-ascii \
|
||||
ifcfg-test-wifi-wep-104-ascii \
|
||||
keys-test-wifi-wep-104-ascii
|
||||
|
||||
check-local:
|
||||
@for f in $(EXTRA_DIST); do \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
TYPE=Wireless
|
||||
DEVICE=eth2
|
||||
HWADDR=00:16:41:11:22:33
|
||||
NM_CONTROLLED=yes
|
||||
BOOTPROTO=dhcp
|
||||
ESSID=blahblah
|
||||
CHANNEL=1
|
||||
MODE=Managed
|
||||
RATE=auto
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
PEERDNS=yes
|
||||
IPV6INIT=no
|
||||
SECURITYMODE=open
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
TYPE=Wireless
|
||||
DEVICE=eth2
|
||||
HWADDR=00:16:41:11:22:33
|
||||
NM_CONTROLLED=yes
|
||||
BOOTPROTO=dhcp
|
||||
ESSID=blahblah
|
||||
CHANNEL=1
|
||||
MODE=Managed
|
||||
RATE=auto
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
PEERDNS=yes
|
||||
IPV6INIT=no
|
||||
SECURITYMODE=open
|
||||
|
|
@ -0,0 +1 @@
|
|||
KEY1=s:LoremIpsumSit
|
||||
|
|
@ -0,0 +1 @@
|
|||
KEY1=s:Lorem
|
||||
|
|
@ -3680,6 +3680,272 @@ test_read_wifi_wep_passphrase (void)
|
|||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
#define TEST_IFCFG_WIFI_WEP_40_ASCII TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-wep-40-ascii"
|
||||
|
||||
static void
|
||||
test_read_wifi_wep_40_ascii (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingWireless *s_wireless;
|
||||
NMSettingWirelessSecurity *s_wsec;
|
||||
char *unmanaged = NULL;
|
||||
char *keyfile = NULL;
|
||||
char *routefile = NULL;
|
||||
char *route6file = NULL;
|
||||
gboolean ignore_error = FALSE;
|
||||
GError *error = NULL;
|
||||
const char *tmp;
|
||||
const char *expected_wep_key0 = "Lorem";
|
||||
NMWepKeyType key_type;
|
||||
|
||||
connection = connection_from_file (TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&routefile,
|
||||
&route6file,
|
||||
&error,
|
||||
&ignore_error);
|
||||
ASSERT (connection != NULL,
|
||||
"wifi-wep-40-ascii-read", "failed to read %s: %s", TEST_IFCFG_WIFI_WEP_40_ASCII, error->message);
|
||||
|
||||
ASSERT (nm_connection_verify (connection, &error),
|
||||
"wifi-wep-40-ascii-verify", "failed to verify %s: %s", TEST_IFCFG_WIFI_WEP_40_ASCII, error->message);
|
||||
|
||||
/* ===== CONNECTION SETTING ===== */
|
||||
|
||||
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
|
||||
ASSERT (s_con != NULL,
|
||||
"wifi-wep-40-ascii-verify-connection", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME);
|
||||
|
||||
/* ===== WIRELESS SETTING ===== */
|
||||
|
||||
s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
|
||||
ASSERT (s_wireless != NULL,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SETTING_NAME);
|
||||
|
||||
/* Security */
|
||||
tmp = nm_setting_wireless_get_security (s_wireless);
|
||||
ASSERT (tmp != NULL,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: missing %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SEC);
|
||||
ASSERT (strcmp (tmp, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) == 0,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SEC);
|
||||
|
||||
/* ===== WIRELESS SECURITY SETTING ===== */
|
||||
|
||||
s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY));
|
||||
ASSERT (s_wsec != NULL,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
|
||||
|
||||
/* Key management */
|
||||
ASSERT (strcmp (nm_setting_wireless_security_get_key_mgmt (s_wsec), "none") == 0,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: missing %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT);
|
||||
|
||||
/* WEP key index */
|
||||
ASSERT (nm_setting_wireless_security_get_wep_tx_keyidx (s_wsec) == 0,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX);
|
||||
|
||||
/* WEP key type */
|
||||
key_type = nm_setting_wireless_security_get_wep_key_type (s_wsec);
|
||||
ASSERT (key_type == NM_WEP_KEY_TYPE_UNKNOWN || key_type == NM_WEP_KEY_TYPE_KEY,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: unexpected WEP key type %d",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
key_type);
|
||||
|
||||
/* WEP key index 0 */
|
||||
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 0);
|
||||
ASSERT (tmp != NULL,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: missing %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
|
||||
ASSERT (strcmp (tmp, expected_wep_key0) == 0,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
|
||||
|
||||
/* WEP key index 1 */
|
||||
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 1);
|
||||
ASSERT (tmp == NULL,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY1);
|
||||
|
||||
/* WEP key index 2 */
|
||||
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 2);
|
||||
ASSERT (tmp == NULL,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY2);
|
||||
|
||||
/* WEP key index 3 */
|
||||
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 3);
|
||||
ASSERT (tmp == NULL,
|
||||
"wifi-wep-40-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_40_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY3);
|
||||
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
#define TEST_IFCFG_WIFI_WEP_104_ASCII TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-wep-104-ascii"
|
||||
|
||||
static void
|
||||
test_read_wifi_wep_104_ascii (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingWireless *s_wireless;
|
||||
NMSettingWirelessSecurity *s_wsec;
|
||||
char *unmanaged = NULL;
|
||||
char *keyfile = NULL;
|
||||
char *routefile = NULL;
|
||||
char *route6file = NULL;
|
||||
gboolean ignore_error = FALSE;
|
||||
GError *error = NULL;
|
||||
const char *tmp;
|
||||
const char *expected_wep_key0 = "LoremIpsumSit";
|
||||
NMWepKeyType key_type;
|
||||
|
||||
connection = connection_from_file (TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&routefile,
|
||||
&route6file,
|
||||
&error,
|
||||
&ignore_error);
|
||||
ASSERT (connection != NULL,
|
||||
"wifi-wep-104-ascii-read", "failed to read %s: %s", TEST_IFCFG_WIFI_WEP_104_ASCII, error->message);
|
||||
|
||||
ASSERT (nm_connection_verify (connection, &error),
|
||||
"wifi-wep-104-ascii-verify", "failed to verify %s: %s", TEST_IFCFG_WIFI_WEP_104_ASCII, error->message);
|
||||
|
||||
/* ===== CONNECTION SETTING ===== */
|
||||
|
||||
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
|
||||
ASSERT (s_con != NULL,
|
||||
"wifi-wep-104-ascii-verify-connection", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_CONNECTION_SETTING_NAME);
|
||||
|
||||
/* ===== WIRELESS SETTING ===== */
|
||||
|
||||
s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS));
|
||||
ASSERT (s_wireless != NULL,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SETTING_NAME);
|
||||
|
||||
/* Security */
|
||||
tmp = nm_setting_wireless_get_security (s_wireless);
|
||||
ASSERT (tmp != NULL,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: missing %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SEC);
|
||||
ASSERT (strcmp (tmp, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) == 0,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SEC);
|
||||
|
||||
/* ===== WIRELESS SECURITY SETTING ===== */
|
||||
|
||||
s_wsec = NM_SETTING_WIRELESS_SECURITY (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY));
|
||||
ASSERT (s_wsec != NULL,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: missing %s setting",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
|
||||
|
||||
/* Key management */
|
||||
ASSERT (strcmp (nm_setting_wireless_security_get_key_mgmt (s_wsec), "none") == 0,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: missing %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT);
|
||||
|
||||
/* WEP key index */
|
||||
ASSERT (nm_setting_wireless_security_get_wep_tx_keyidx (s_wsec) == 0,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX);
|
||||
|
||||
/* WEP key type */
|
||||
key_type = nm_setting_wireless_security_get_wep_key_type (s_wsec);
|
||||
ASSERT (key_type == NM_WEP_KEY_TYPE_UNKNOWN || key_type == NM_WEP_KEY_TYPE_KEY,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: unexpected WEP key type %d",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
key_type);
|
||||
|
||||
/* WEP key index 0 */
|
||||
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 0);
|
||||
ASSERT (tmp != NULL,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: missing %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
|
||||
ASSERT (strcmp (tmp, expected_wep_key0) == 0,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key value",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY0);
|
||||
|
||||
/* WEP key index 1 */
|
||||
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 1);
|
||||
ASSERT (tmp == NULL,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY1);
|
||||
|
||||
/* WEP key index 2 */
|
||||
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 2);
|
||||
ASSERT (tmp == NULL,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY2);
|
||||
|
||||
/* WEP key index 3 */
|
||||
tmp = nm_setting_wireless_security_get_wep_key (s_wsec, 3);
|
||||
ASSERT (tmp == NULL,
|
||||
"wifi-wep-104-ascii-verify-wireless", "failed to verify %s: unexpected %s / %s key",
|
||||
TEST_IFCFG_WIFI_WEP_104_ASCII,
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_KEY3);
|
||||
|
||||
g_object_unref (connection);
|
||||
}
|
||||
|
||||
#define TEST_IFCFG_WIFI_LEAP TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-leap"
|
||||
|
||||
static void
|
||||
|
|
@ -6751,6 +7017,308 @@ test_write_wifi_wep_passphrase (void)
|
|||
g_object_unref (reread);
|
||||
}
|
||||
|
||||
static void
|
||||
test_write_wifi_wep_40_ascii (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMConnection *reread;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingWireless *s_wifi;
|
||||
NMSettingWirelessSecurity *s_wsec;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMSettingIP6Config *s_ip6;
|
||||
char *uuid;
|
||||
gboolean success;
|
||||
GError *error = NULL;
|
||||
char *testfile = NULL;
|
||||
char *unmanaged = NULL;
|
||||
char *keyfile = NULL;
|
||||
char *routefile = NULL;
|
||||
char *route6file = NULL;
|
||||
gboolean ignore_error = FALSE;
|
||||
GByteArray *ssid;
|
||||
const unsigned char ssid_data[] = "blahblah40";
|
||||
struct stat statbuf;
|
||||
|
||||
connection = nm_connection_new ();
|
||||
ASSERT (connection != NULL,
|
||||
"wifi-wep-40-ascii-write", "failed to allocate new connection");
|
||||
|
||||
/* Connection setting */
|
||||
s_con = (NMSettingConnection *) nm_setting_connection_new ();
|
||||
ASSERT (s_con != NULL,
|
||||
"wifi-wep-40-ascii-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_CONNECTION_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
||||
|
||||
uuid = nm_utils_uuid_generate ();
|
||||
g_object_set (s_con,
|
||||
NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 40 ASCII",
|
||||
NM_SETTING_CONNECTION_UUID, uuid,
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
|
||||
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
NULL);
|
||||
g_free (uuid);
|
||||
|
||||
/* Wifi setting */
|
||||
s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
|
||||
ASSERT (s_wifi != NULL,
|
||||
"wifi-wep-40-ascii-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_WIRELESS_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
|
||||
|
||||
ssid = g_byte_array_sized_new (sizeof (ssid_data));
|
||||
g_byte_array_append (ssid, ssid_data, sizeof (ssid_data));
|
||||
|
||||
g_object_set (s_wifi,
|
||||
NM_SETTING_WIRELESS_SSID, ssid,
|
||||
NM_SETTING_WIRELESS_MODE, "infrastructure",
|
||||
NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NULL);
|
||||
|
||||
g_byte_array_free (ssid, TRUE);
|
||||
|
||||
/* Wireless security setting */
|
||||
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
|
||||
ASSERT (s_wsec != NULL,
|
||||
"wifi-wep-40-ascii-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
|
||||
|
||||
g_object_set (s_wsec,
|
||||
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none",
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, 2,
|
||||
NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "shared",
|
||||
NULL);
|
||||
nm_setting_wireless_security_set_wep_key (s_wsec, 0, "lorem");
|
||||
nm_setting_wireless_security_set_wep_key (s_wsec, 1, "ipsum");
|
||||
nm_setting_wireless_security_set_wep_key (s_wsec, 2, "dolor");
|
||||
nm_setting_wireless_security_set_wep_key (s_wsec, 3, "donec");
|
||||
|
||||
/* IP4 setting */
|
||||
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
|
||||
ASSERT (s_ip4 != NULL,
|
||||
"wifi-wep-40-ascii-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
|
||||
|
||||
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
|
||||
|
||||
/* IP6 setting */
|
||||
s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
|
||||
ASSERT (s_ip6 != NULL,
|
||||
"wifi-wep-40-ascii-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_IP6_CONFIG_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
|
||||
|
||||
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL);
|
||||
|
||||
ASSERT (nm_connection_verify (connection, &error) == TRUE,
|
||||
"wifi-wep-40-ascii-write", "failed to verify connection: %s",
|
||||
(error && error->message) ? error->message : "(unknown)");
|
||||
|
||||
/* Save the ifcfg */
|
||||
success = writer_new_connection (connection,
|
||||
TEST_SCRATCH_DIR "/network-scripts/",
|
||||
&testfile,
|
||||
&error);
|
||||
ASSERT (success == TRUE,
|
||||
"wifi-wep-40-ascii-write", "failed to write connection to disk: %s",
|
||||
(error && error->message) ? error->message : "(unknown)");
|
||||
|
||||
ASSERT (testfile != NULL,
|
||||
"wifi-wep-40-ascii-write", "didn't get ifcfg file path back after writing connection");
|
||||
|
||||
/* re-read the connection for comparison */
|
||||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&routefile,
|
||||
&route6file,
|
||||
&error,
|
||||
&ignore_error);
|
||||
unlink (testfile);
|
||||
|
||||
ASSERT (keyfile != NULL,
|
||||
"wifi-wep-40-ascii-write-reread", "expected keyfile for '%s'", testfile);
|
||||
|
||||
ASSERT (stat (keyfile, &statbuf) == 0,
|
||||
"wifi-wep-40-ascii-write-reread", "couldn't stat() '%s'", keyfile);
|
||||
ASSERT (S_ISREG (statbuf.st_mode),
|
||||
"wifi-wep-40-ascii-write-reread", "keyfile '%s' wasn't a normal file", keyfile);
|
||||
ASSERT ((statbuf.st_mode & 0077) == 0,
|
||||
"wifi-wep-40-ascii-write-reread", "keyfile '%s' wasn't readable only by its owner", keyfile);
|
||||
|
||||
unlink (keyfile);
|
||||
|
||||
ASSERT (reread != NULL,
|
||||
"wifi-wep-40-ascii-write-reread", "failed to read %s: %s", testfile, error->message);
|
||||
|
||||
ASSERT (nm_connection_verify (reread, &error),
|
||||
"wifi-wep-40-ascii-write-reread-verify", "failed to verify %s: %s", testfile, error->message);
|
||||
|
||||
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
|
||||
"wifi-wep-40-ascii-write", "written and re-read connection weren't the same.");
|
||||
|
||||
g_free (testfile);
|
||||
g_object_unref (connection);
|
||||
g_object_unref (reread);
|
||||
}
|
||||
|
||||
static void
|
||||
test_write_wifi_wep_104_ascii (void)
|
||||
{
|
||||
NMConnection *connection;
|
||||
NMConnection *reread;
|
||||
NMSettingConnection *s_con;
|
||||
NMSettingWireless *s_wifi;
|
||||
NMSettingWirelessSecurity *s_wsec;
|
||||
NMSettingIP4Config *s_ip4;
|
||||
NMSettingIP6Config *s_ip6;
|
||||
char *uuid;
|
||||
gboolean success;
|
||||
GError *error = NULL;
|
||||
char *testfile = NULL;
|
||||
char *unmanaged = NULL;
|
||||
char *keyfile = NULL;
|
||||
char *routefile = NULL;
|
||||
char *route6file = NULL;
|
||||
gboolean ignore_error = FALSE;
|
||||
GByteArray *ssid;
|
||||
const unsigned char ssid_data[] = "blahblah104";
|
||||
struct stat statbuf;
|
||||
|
||||
connection = nm_connection_new ();
|
||||
ASSERT (connection != NULL,
|
||||
"wifi-wep-104-ascii-write", "failed to allocate new connection");
|
||||
|
||||
/* Connection setting */
|
||||
s_con = (NMSettingConnection *) nm_setting_connection_new ();
|
||||
ASSERT (s_con != NULL,
|
||||
"wifi-wep-104-ascii-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_CONNECTION_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_con));
|
||||
|
||||
uuid = nm_utils_uuid_generate ();
|
||||
g_object_set (s_con,
|
||||
NM_SETTING_CONNECTION_ID, "Test Write Wifi WEP 104 ASCII",
|
||||
NM_SETTING_CONNECTION_UUID, uuid,
|
||||
NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
|
||||
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRELESS_SETTING_NAME,
|
||||
NULL);
|
||||
g_free (uuid);
|
||||
|
||||
/* Wifi setting */
|
||||
s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
|
||||
ASSERT (s_wifi != NULL,
|
||||
"wifi-wep-104-ascii-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_WIRELESS_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_wifi));
|
||||
|
||||
ssid = g_byte_array_sized_new (sizeof (ssid_data));
|
||||
g_byte_array_append (ssid, ssid_data, sizeof (ssid_data));
|
||||
|
||||
g_object_set (s_wifi,
|
||||
NM_SETTING_WIRELESS_SSID, ssid,
|
||||
NM_SETTING_WIRELESS_MODE, "infrastructure",
|
||||
NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
|
||||
NULL);
|
||||
|
||||
g_byte_array_free (ssid, TRUE);
|
||||
|
||||
/* Wireless security setting */
|
||||
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
|
||||
ASSERT (s_wsec != NULL,
|
||||
"wifi-wep-104-ascii-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_wsec));
|
||||
|
||||
g_object_set (s_wsec,
|
||||
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none",
|
||||
NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, 0,
|
||||
NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "open",
|
||||
NULL);
|
||||
nm_setting_wireless_security_set_wep_key (s_wsec, 0, "LoremIpsumSit");
|
||||
nm_setting_wireless_security_set_wep_key (s_wsec, 1, "AlfaBetaGamma");
|
||||
nm_setting_wireless_security_set_wep_key (s_wsec, 2, "WEP-104 ASCII");
|
||||
nm_setting_wireless_security_set_wep_key (s_wsec, 3, "thisismyascii");
|
||||
|
||||
/* IP4 setting */
|
||||
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
|
||||
ASSERT (s_ip4 != NULL,
|
||||
"wifi-wep-104-ascii-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_IP4_CONFIG_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
|
||||
|
||||
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
|
||||
|
||||
/* IP6 setting */
|
||||
s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
|
||||
ASSERT (s_ip6 != NULL,
|
||||
"wifi-wep-104-ascii-write", "failed to allocate new %s setting",
|
||||
NM_SETTING_IP6_CONFIG_SETTING_NAME);
|
||||
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
|
||||
|
||||
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL);
|
||||
|
||||
ASSERT (nm_connection_verify (connection, &error) == TRUE,
|
||||
"wifi-wep-104-ascii-write", "failed to verify connection: %s",
|
||||
(error && error->message) ? error->message : "(unknown)");
|
||||
|
||||
/* Save the ifcfg */
|
||||
success = writer_new_connection (connection,
|
||||
TEST_SCRATCH_DIR "/network-scripts/",
|
||||
&testfile,
|
||||
&error);
|
||||
ASSERT (success == TRUE,
|
||||
"wifi-wep-104-ascii-write", "failed to write connection to disk: %s",
|
||||
(error && error->message) ? error->message : "(unknown)");
|
||||
|
||||
ASSERT (testfile != NULL,
|
||||
"wifi-wep-104-ascii-write", "didn't get ifcfg file path back after writing connection");
|
||||
|
||||
/* re-read the connection for comparison */
|
||||
reread = connection_from_file (testfile,
|
||||
NULL,
|
||||
TYPE_WIRELESS,
|
||||
NULL,
|
||||
&unmanaged,
|
||||
&keyfile,
|
||||
&routefile,
|
||||
&route6file,
|
||||
&error,
|
||||
&ignore_error);
|
||||
unlink (testfile);
|
||||
|
||||
ASSERT (keyfile != NULL,
|
||||
"wifi-wep-104-ascii-write-reread", "expected keyfile for '%s'", testfile);
|
||||
|
||||
ASSERT (stat (keyfile, &statbuf) == 0,
|
||||
"wifi-wep-104-ascii-write-reread", "couldn't stat() '%s'", keyfile);
|
||||
ASSERT (S_ISREG (statbuf.st_mode),
|
||||
"wifi-wep-104-ascii-write-reread", "keyfile '%s' wasn't a normal file", keyfile);
|
||||
ASSERT ((statbuf.st_mode & 0077) == 0,
|
||||
"wifi-wep-104-ascii-write-reread", "keyfile '%s' wasn't readable only by its owner", keyfile);
|
||||
|
||||
unlink (keyfile);
|
||||
|
||||
ASSERT (reread != NULL,
|
||||
"wifi-wep-104-ascii-write-reread", "failed to read %s: %s", testfile, error->message);
|
||||
|
||||
ASSERT (nm_connection_verify (reread, &error),
|
||||
"wifi-wep-104-ascii-write-reread-verify", "failed to verify %s: %s", testfile, error->message);
|
||||
|
||||
ASSERT (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
|
||||
"wifi-wep-104-ascii-write", "written and re-read connection weren't the same.");
|
||||
|
||||
g_free (testfile);
|
||||
g_object_unref (connection);
|
||||
g_object_unref (reread);
|
||||
}
|
||||
|
||||
static void
|
||||
test_write_wifi_leap (void)
|
||||
{
|
||||
|
|
@ -8441,6 +9009,8 @@ int main (int argc, char **argv)
|
|||
test_read_wifi_wep ();
|
||||
test_read_wifi_wep_adhoc ();
|
||||
test_read_wifi_wep_passphrase ();
|
||||
test_read_wifi_wep_40_ascii ();
|
||||
test_read_wifi_wep_104_ascii ();
|
||||
test_read_wifi_leap ();
|
||||
test_read_wifi_wpa_psk ();
|
||||
test_read_wifi_wpa_psk_unquoted ();
|
||||
|
|
@ -8462,6 +9032,8 @@ int main (int argc, char **argv)
|
|||
test_write_wifi_wep ();
|
||||
test_write_wifi_wep_adhoc ();
|
||||
test_write_wifi_wep_passphrase ();
|
||||
test_write_wifi_wep_40_ascii ();
|
||||
test_write_wifi_wep_104_ascii ();
|
||||
test_write_wifi_leap ();
|
||||
test_write_wifi_wpa_psk ("Test Write Wifi WPA PSK",
|
||||
"wifi-wpa-psk-write",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue