summaryrefslogtreecommitdiff
path: root/src/tests/test-wifi-ap-utils.c
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2011-01-10 23:39:12 -0600
committerDan Williams <dcbw@redhat.com>2011-01-10 23:39:12 -0600
commit215306f5a1e4dc38ec02a484c31470bb048d668b (patch)
treea4a62c495dd81427bfbe18119446914085e5f299 /src/tests/test-wifi-ap-utils.c
parentbf98469b8d7b9efe0dfd6e8117e1bcff30ef2c16 (diff)
core: add AddAndActivate D-Bus method
Given connection details, complete the connection as well as possible using the given specific object and device, add it to system settings, and activate it all in one method.
Diffstat (limited to 'src/tests/test-wifi-ap-utils.c')
-rw-r--r--src/tests/test-wifi-ap-utils.c973
1 files changed, 973 insertions, 0 deletions
diff --git a/src/tests/test-wifi-ap-utils.c b/src/tests/test-wifi-ap-utils.c
new file mode 100644
index 0000000000..b2cd234ece
--- /dev/null
+++ b/src/tests/test-wifi-ap-utils.c
@@ -0,0 +1,973 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ */
+
+#include <glib.h>
+#include <string.h>
+
+#include "nm-wifi-ap-utils.h"
+
+#include "nm-setting-connection.h"
+#include "nm-setting-wireless.h"
+#include "nm-setting-wireless-security.h"
+#include "nm-setting-8021x.h"
+
+#define DEBUG 1
+
+/*******************************************/
+
+#define COMPARE(src, expected, success, error, edomain, ecode) \
+{ \
+ if (expected) { \
+ if (!success) { \
+ g_assert (error != NULL); \
+ g_warning ("Failed to complete connection: (%d) %s", error->code, error->message); \
+ } \
+ g_assert (success == TRUE); \
+ g_assert (error == NULL); \
+\
+ success = nm_connection_compare (src, expected, NM_SETTING_COMPARE_FLAG_EXACT); \
+ if (success == FALSE && DEBUG) { \
+ g_message ("\n- COMPLETED ---------------------------------\n"); \
+ nm_connection_dump (src); \
+ g_message ("+ EXPECTED ++++++++++++++++++++++++++++++++++++\n"); \
+ nm_connection_dump (expected); \
+ g_message ("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); \
+ } \
+ g_assert (success == TRUE); \
+ } else { \
+ if (success) { \
+ g_message ("\n- COMPLETED ---------------------------------\n"); \
+ nm_connection_dump (src); \
+ } \
+ g_assert (success == FALSE); \
+ g_assert_error (error, edomain, ecode); \
+ } \
+ \
+ g_clear_error (&error); \
+}
+
+static gboolean
+complete_connection (const char *ssid,
+ const guint8 bssid[ETH_ALEN],
+ NM80211Mode mode,
+ guint32 flags,
+ guint32 wpa_flags,
+ guint32 rsn_flags,
+ gboolean lock_bssid,
+ NMConnection *src,
+ GError **error)
+{
+ GByteArray *tmp;
+ gboolean success;
+
+ tmp = g_byte_array_sized_new (strlen (ssid));
+ g_byte_array_append (tmp, (const guint8 *) ssid, strlen (ssid));
+
+ success = nm_ap_utils_complete_connection (tmp,
+ bssid,
+ mode,
+ flags,
+ wpa_flags,
+ rsn_flags,
+ src,
+ lock_bssid,
+ error);
+ g_byte_array_free (tmp, TRUE);
+ return success;
+}
+
+static NMConnection *
+create_expected (const char *ssid,
+ const guint8 *bssid,
+ NM80211Mode mode,
+ gboolean add_security,
+ gboolean add_8021x,
+ const char *key_mgmt,
+ const char *auth_alg,
+ NMSettingWireless **out_s_wifi,
+ NMSettingWirelessSecurity **out_s_wsec,
+ NMSetting8021x **out_s_8021x)
+{
+ NMConnection *connection;
+ NMSettingWireless *s_wifi = NULL;
+ NMSettingWirelessSecurity *s_wsec = NULL;
+ NMSetting8021x *s_8021x = NULL;
+ GByteArray *tmp;
+
+ connection = nm_connection_new ();
+
+ s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_wifi));
+
+ /* SSID */
+ tmp = g_byte_array_sized_new (strlen (ssid));
+ g_byte_array_append (tmp, (const guint8 *) ssid, strlen (ssid));
+ g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_SSID, tmp, NULL);
+ g_byte_array_free (tmp, TRUE);
+
+ /* BSSID */
+ if (bssid) {
+ tmp = g_byte_array_sized_new (ETH_ALEN);
+ g_byte_array_append (tmp, bssid, ETH_ALEN);
+ g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_BSSID, tmp, NULL);
+ g_byte_array_free (tmp, TRUE);
+ }
+
+ if (mode == NM_802_11_MODE_INFRA)
+ g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_MODE, "infrastructure", NULL);
+ else if (mode == NM_802_11_MODE_ADHOC)
+ g_object_set (G_OBJECT (s_wifi), NM_SETTING_WIRELESS_MODE, "adhoc", NULL);
+ else
+ g_assert_not_reached ();
+
+ if (add_security) {
+ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_wsec));
+
+ g_object_set (G_OBJECT (s_wifi),
+ NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
+ NULL);
+ if (key_mgmt)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, key_mgmt, NULL);
+ if (auth_alg)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, auth_alg, NULL);
+
+ if (add_8021x) {
+ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_8021x));
+ }
+ }
+
+ if (out_s_wifi)
+ *out_s_wifi = s_wifi;
+ if (out_s_wsec)
+ *out_s_wsec = s_wsec;
+ if (out_s_8021x)
+ *out_s_8021x = s_8021x;
+ return connection;
+}
+
+static NMSettingWireless *
+get_wifi_setting (NMConnection *connection, gboolean add_if_absent)
+{
+ NMSettingWireless *s_wifi;
+
+ s_wifi = (NMSettingWireless *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS);
+ if (add_if_absent) {
+ if (!s_wifi) {
+ s_wifi = (NMSettingWireless *) nm_setting_wireless_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_wifi));
+ }
+ g_object_set (G_OBJECT (s_wifi),
+ NM_SETTING_WIRELESS_SEC, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
+ NULL);
+ }
+ return s_wifi;
+}
+
+static void
+fill_wep (NMConnection *connection,
+ const char *key0,
+ guint32 tx_keyidx,
+ const char *auth_alg,
+ gboolean set_s_wifi)
+{
+ NMSettingWireless *s_wifi;
+ NMSettingWirelessSecurity *s_wsec;
+
+ s_wifi = get_wifi_setting (connection, set_s_wifi);
+
+ s_wsec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY);
+ if (!s_wsec) {
+ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_wsec));
+ }
+
+ if (key0) {
+ g_object_set (G_OBJECT (s_wsec),
+ NM_SETTING_WIRELESS_SECURITY_WEP_KEY0, key0,
+ NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, tx_keyidx,
+ NULL);
+ }
+
+ if (auth_alg)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, auth_alg, NULL);
+}
+
+static void
+fill_leap (NMConnection *connection,
+ const char *leap_username,
+ gboolean set_auth_alg,
+ gboolean set_key_mgmt,
+ gboolean set_s_wifi)
+{
+ NMSettingWireless *s_wifi;
+ NMSettingWirelessSecurity *s_wsec;
+
+ s_wifi = get_wifi_setting (connection, set_s_wifi);
+
+ s_wsec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY);
+ if (!s_wsec) {
+ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_wsec));
+ }
+
+ if (leap_username)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, leap_username, NULL);
+
+ if (set_auth_alg)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap", NULL);
+
+ if (set_key_mgmt)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL);
+}
+
+static void
+fill_wpa_psk (NMConnection *connection,
+ const char *key_mgmt,
+ const char *psk,
+ const char *auth_alg,
+ gboolean set_s_wifi)
+{
+ NMSettingWireless *s_wifi;
+ NMSettingWirelessSecurity *s_wsec;
+
+ s_wifi = get_wifi_setting (connection, set_s_wifi);
+
+ s_wsec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY);
+ if (!s_wsec) {
+ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_wsec));
+ }
+
+ if (key_mgmt)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, key_mgmt, NULL);
+ if (psk)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_PSK, psk, NULL);
+ if (auth_alg)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, auth_alg, NULL);
+}
+
+static void
+fill_8021x (NMConnection *connection,
+ NMSetting8021x *s_8021x,
+ const char *key_mgmt,
+ const char *auth_alg,
+ gboolean set_s_wifi)
+{
+ NMSettingWireless *s_wifi;
+ NMSettingWirelessSecurity *s_wsec;
+
+ s_wifi = get_wifi_setting (connection, set_s_wifi);
+
+ s_wsec = (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY);
+ if (!s_wsec) {
+ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_wsec));
+ }
+
+ if (key_mgmt)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, key_mgmt, NULL);
+ if (auth_alg)
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, auth_alg, NULL);
+
+ nm_connection_add_setting (connection, NM_SETTING (s_8021x));
+}
+
+/*******************************************/
+
+static void
+test_lock_bssid (void)
+{
+ NMConnection *src, *expected;
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ const char *ssid = "blahblah";
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ success = complete_connection (ssid, bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_NONE,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ TRUE,
+ src, &error);
+
+ expected = create_expected (ssid, bssid, NM_802_11_MODE_INFRA, FALSE, FALSE, NULL, NULL, NULL, NULL, NULL);
+ COMPARE (src, expected, success, error, 0, 0);
+
+ g_object_unref (src);
+ g_object_unref (expected);
+}
+
+/*******************************************/
+
+static void
+test_open_ap_empty_connection (void)
+{
+ NMConnection *src, *expected;
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ const char *ssid = "blahblah";
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ success = complete_connection (ssid, bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_NONE,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ FALSE,
+ src, &error);
+
+ expected = create_expected (ssid, NULL, NM_802_11_MODE_INFRA, FALSE, FALSE, NULL, NULL, NULL, NULL, NULL);
+ COMPARE (src, expected, success, error, 0, 0);
+
+ g_object_unref (src);
+ g_object_unref (expected);
+}
+
+/*******************************************/
+
+static void
+test_open_ap_leap_connection_1 (gboolean fill_wifi)
+{
+ NMConnection *src;
+ NMSettingWireless *s_wifi;
+ NMSettingWirelessSecurity *s_wsec;
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ s_wifi = get_wifi_setting (src, fill_wifi);
+ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, "Bill Smith", NULL);
+ nm_connection_add_setting (src, NM_SETTING (s_wsec));
+
+ success = complete_connection ("blahblah", bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_NONE,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ FALSE,
+ src, &error);
+ /* We expect failure */
+ COMPARE (src, NULL, success, error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY);
+
+ g_object_unref (src);
+}
+
+/*******************************************/
+
+static void
+test_open_ap_leap_connection_2 (void)
+{
+ NMConnection *src;
+ NMSettingWireless *s_wifi;
+ NMSettingWirelessSecurity *s_wsec;
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ s_wifi = get_wifi_setting (src, TRUE);
+ s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new ();
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL);
+ nm_connection_add_setting (src, NM_SETTING (s_wsec));
+
+ success = complete_connection ("blahblah", bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_NONE,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ FALSE,
+ src, &error);
+ /* We expect failure */
+ COMPARE (src, NULL, success, error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY);
+
+ g_object_unref (src);
+}
+
+/*******************************************/
+
+static void
+test_open_ap_wep_connection (gboolean fill_wifi)
+{
+ NMConnection *src;
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ fill_wep (src, "11111111111111111111111111", 0, "open", fill_wifi);
+ success = complete_connection ("blahblah", bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_NONE,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ FALSE,
+ src, &error);
+ /* We expect failure */
+ COMPARE (src, NULL, success, error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY);
+
+ g_object_unref (src);
+}
+
+/*******************************************/
+
+static void
+test_ap_wpa_psk_connection_base (const char *key_mgmt,
+ const char *auth_alg,
+ guint32 flags,
+ guint32 wpa_flags,
+ guint32 rsn_flags,
+ gboolean fill_wifi)
+{
+ NMConnection *src;
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ fill_wpa_psk (src, key_mgmt, "asdfasdfasdfasdfasdfafs", auth_alg, fill_wifi);
+ success = complete_connection ("blahblah", bssid, NM_802_11_MODE_INFRA,
+ flags, wpa_flags, rsn_flags,
+ FALSE, src, &error);
+ /* We expect failure */
+ COMPARE (src, NULL, success, error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY);
+
+ g_object_unref (src);
+}
+
+static void
+test_open_ap_wpa_psk_connection_1 (void)
+{
+ test_ap_wpa_psk_connection_base (NULL, NULL,
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE);
+}
+
+static void
+test_open_ap_wpa_psk_connection_2 (void)
+{
+ test_ap_wpa_psk_connection_base (NULL, NULL,
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE);
+}
+
+static void
+test_open_ap_wpa_psk_connection_3 (void)
+{
+ test_ap_wpa_psk_connection_base (NULL, "open",
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE);
+}
+
+static void
+test_open_ap_wpa_psk_connection_4 (void)
+{
+ test_ap_wpa_psk_connection_base (NULL, "shared",
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE);
+}
+
+static void
+test_open_ap_wpa_psk_connection_5 (void)
+{
+ test_ap_wpa_psk_connection_base ("wpa-psk", "open",
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE);
+}
+
+/*******************************************/
+
+static void
+test_ap_wpa_eap_connection_base (const char *key_mgmt,
+ const char *auth_alg,
+ guint32 flags,
+ guint32 wpa_flags,
+ guint32 rsn_flags,
+ gboolean fill_wifi,
+ guint error_domain,
+ guint error_code)
+{
+ NMConnection *src;
+ NMSetting8021x *s_8021x;
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ gboolean success;
+ GError *error = NULL;
+ const char *ssid = "blahblah";
+
+ src = nm_connection_new ();
+ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
+ fill_8021x (src, s_8021x, key_mgmt, auth_alg, fill_wifi);
+ success = complete_connection (ssid, bssid, NM_802_11_MODE_INFRA,
+ flags, wpa_flags, rsn_flags,
+ FALSE, src, &error);
+ if (!wpa_flags && !rsn_flags) {
+ if (!flags) {
+ /* Failure expected */
+ COMPARE (src, NULL, success, error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY);
+ } else if (flags & NM_802_11_AP_FLAGS_PRIVACY) {
+ COMPARE (src, NULL, success, error, error_domain, error_code);
+ }
+ } else
+ g_assert_not_reached ();
+
+ g_object_unref (src);
+}
+
+static void
+test_open_ap_wpa_eap_connection_1 (void)
+{
+ test_ap_wpa_eap_connection_base (NULL, NULL,
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE, 0, 0);
+}
+
+static void
+test_open_ap_wpa_eap_connection_2 (void)
+{
+ test_ap_wpa_eap_connection_base (NULL, NULL,
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ TRUE, 0, 0);
+}
+
+static void
+test_open_ap_wpa_eap_connection_3 (void)
+{
+ test_ap_wpa_eap_connection_base (NULL, "open",
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE, 0, 0);
+}
+
+static void
+test_open_ap_wpa_eap_connection_4 (void)
+{
+ test_ap_wpa_eap_connection_base (NULL, "shared",
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE, 0, 0);
+}
+
+static void
+test_open_ap_wpa_eap_connection_5 (void)
+{
+ test_ap_wpa_eap_connection_base ("wpa-eap", "open",
+ NM_802_11_AP_FLAGS_NONE,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE, 0, 0);
+}
+
+/*******************************************/
+
+static void
+test_priv_ap_empty_connection (void)
+{
+ NMConnection *src, *expected;
+ NMSettingWirelessSecurity *s_wsec;
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ const char *ssid = "blahblah";
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ success = complete_connection (ssid, bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ FALSE,
+ src, &error);
+
+ /* Static WEP connection expected */
+ expected = create_expected (ssid, NULL, NM_802_11_MODE_INFRA, TRUE, FALSE, "none", NULL, NULL, &s_wsec, NULL);
+ COMPARE (src, expected, success, error, 0, 0);
+
+ g_object_unref (src);
+ g_object_unref (expected);
+}
+
+/*******************************************/
+
+static void
+test_priv_ap_leap_connection_1 (gboolean fill_wifi)
+{
+ NMConnection *src, *expected;
+ NMSettingWirelessSecurity *s_wsec;
+ const char *ssid = "blahblah";
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ const char *leap_username = "Bill Smith";
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ fill_leap (src, leap_username, TRUE, FALSE, TRUE);
+ success = complete_connection (ssid, bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ FALSE,
+ src, &error);
+ /* We expect success here; since LEAP APs just set the 'privacy' flag
+ * there's no way to determine from the AP's beacon whether it's static WEP,
+ * dynamic WEP, or LEAP.
+ */
+ s_wsec = NULL;
+ expected = create_expected (ssid, NULL, NM_802_11_MODE_INFRA, TRUE, FALSE, "ieee8021x", "leap", NULL, &s_wsec, NULL);
+ g_assert (s_wsec);
+ g_object_set (G_OBJECT (s_wsec), NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, leap_username, NULL);
+ COMPARE (src, expected, success, error, 0, 0);
+
+ g_object_unref (src);
+}
+
+/*******************************************/
+
+static void
+test_priv_ap_leap_connection_2 (void)
+{
+ NMConnection *src;
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ fill_leap (src, NULL, TRUE, TRUE, TRUE);
+ success = complete_connection ("blahblah", bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ FALSE,
+ src, &error);
+ /* We expect failure here, we need a LEAP username */
+ COMPARE (src, NULL, success, error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_LEAP_REQUIRES_USERNAME);
+
+ g_object_unref (src);
+}
+
+/*******************************************/
+
+static void
+test_priv_ap_dynamic_wep_1 (void)
+{
+ NMConnection *src, *expected;
+ const char *ssid = "blahblah";
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ NMSettingWirelessSecurity *s_wsec;
+ NMSetting8021x *s_8021x;
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
+ nm_setting_802_1x_add_eap_method (s_8021x, "peap");
+ g_object_set (G_OBJECT (s_8021x),
+ NM_SETTING_802_1X_IDENTITY, "Bill Smith",
+ NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2",
+ NULL);
+ fill_8021x (src, s_8021x, "ieee8021x", "open", TRUE);
+ success = complete_connection (ssid, bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ FALSE,
+ src, &error);
+
+ /* We expect a completed Dynamic WEP connection */
+ s_8021x = NULL;
+ expected = create_expected (ssid, NULL, NM_802_11_MODE_INFRA, TRUE, TRUE, "ieee8021x", "open", NULL, &s_wsec, &s_8021x);
+ nm_setting_wireless_security_add_pairwise (s_wsec, "wep40");
+ nm_setting_wireless_security_add_pairwise (s_wsec, "wep104");
+ nm_setting_wireless_security_add_group (s_wsec, "wep40");
+ nm_setting_wireless_security_add_group (s_wsec, "wep104");
+ nm_setting_802_1x_add_eap_method (s_8021x, "peap");
+ g_object_set (G_OBJECT (s_8021x),
+ NM_SETTING_802_1X_IDENTITY, "Bill Smith",
+ NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2",
+ NULL);
+
+ COMPARE (src, expected, success, error, 0, 0);
+
+ g_object_unref (src);
+}
+
+/*******************************************/
+
+static void
+test_priv_ap_dynamic_wep_2 (void)
+{
+ NMConnection *src, *expected;
+ const char *ssid = "blahblah";
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ NMSettingWirelessSecurity *s_wsec;
+ NMSetting8021x *s_8021x;
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
+ nm_setting_802_1x_add_eap_method (s_8021x, "peap");
+ g_object_set (G_OBJECT (s_8021x),
+ NM_SETTING_802_1X_IDENTITY, "Bill Smith",
+ NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2",
+ NULL);
+ fill_8021x (src, s_8021x, NULL, "open", TRUE);
+ success = complete_connection (ssid, bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ FALSE,
+ src, &error);
+
+ /* We expect a completed Dynamic WEP connection */
+ s_8021x = NULL;
+ expected = create_expected (ssid, NULL, NM_802_11_MODE_INFRA, TRUE, TRUE, "ieee8021x", "open", NULL, &s_wsec, &s_8021x);
+ nm_setting_wireless_security_add_pairwise (s_wsec, "wep40");
+ nm_setting_wireless_security_add_pairwise (s_wsec, "wep104");
+ nm_setting_wireless_security_add_group (s_wsec, "wep40");
+ nm_setting_wireless_security_add_group (s_wsec, "wep104");
+ nm_setting_802_1x_add_eap_method (s_8021x, "peap");
+ g_object_set (G_OBJECT (s_8021x),
+ NM_SETTING_802_1X_IDENTITY, "Bill Smith",
+ NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2",
+ NULL);
+
+ COMPARE (src, expected, success, error, 0, 0);
+
+ g_object_unref (src);
+}
+
+/*******************************************/
+
+static void
+test_priv_ap_dynamic_wep_3 (void)
+{
+ NMConnection *src;
+ const guint8 bssid[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ NMSetting8021x *s_8021x;
+ gboolean success;
+ GError *error = NULL;
+
+ src = nm_connection_new ();
+ s_8021x = (NMSetting8021x *) nm_setting_802_1x_new ();
+ nm_setting_802_1x_add_eap_method (s_8021x, "peap");
+ g_object_set (G_OBJECT (s_8021x),
+ NM_SETTING_802_1X_IDENTITY, "Bill Smith",
+ NM_SETTING_802_1X_PHASE2_AUTH, "mschapv2",
+ NULL);
+ fill_8021x (src, s_8021x, "ieee8021x", "shared", TRUE);
+ success = complete_connection ("blahblah", bssid,
+ NM_802_11_MODE_INFRA, NM_802_11_AP_FLAGS_PRIVACY,
+ NM_WIFI_DEVICE_CAP_NONE, NM_WIFI_DEVICE_CAP_NONE,
+ FALSE,
+ src, &error);
+ /* Expect failure; shared is not compatible with dynamic WEP */
+ COMPARE (src, NULL, success, error, NM_SETTING_WIRELESS_SECURITY_ERROR, NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY);
+
+ g_object_unref (src);
+}
+
+/*******************************************/
+
+static void
+test_priv_ap_wpa_psk_connection_1 (void)
+{
+ test_ap_wpa_psk_connection_base (NULL, NULL,
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE);
+}
+
+static void
+test_priv_ap_wpa_psk_connection_2 (void)
+{
+ test_ap_wpa_psk_connection_base (NULL, NULL,
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ TRUE);
+}
+
+static void
+test_priv_ap_wpa_psk_connection_3 (void)
+{
+ test_ap_wpa_psk_connection_base (NULL, "open",
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE);
+}
+
+static void
+test_priv_ap_wpa_psk_connection_4 (void)
+{
+ test_ap_wpa_psk_connection_base (NULL, "shared",
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE);
+}
+
+static void
+test_priv_ap_wpa_psk_connection_5 (void)
+{
+ test_ap_wpa_psk_connection_base ("wpa-psk", "open",
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE);
+}
+
+/*******************************************/
+
+static void
+test_priv_ap_wpa_eap_connection_1 (void)
+{
+ test_ap_wpa_eap_connection_base (NULL, NULL,
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE,
+ NM_SETTING_802_1X_ERROR,
+ NM_SETTING_802_1X_ERROR_MISSING_PROPERTY);
+}
+
+static void
+test_priv_ap_wpa_eap_connection_2 (void)
+{
+ test_ap_wpa_eap_connection_base (NULL, NULL,
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ TRUE,
+ NM_SETTING_802_1X_ERROR,
+ NM_SETTING_802_1X_ERROR_MISSING_PROPERTY);
+}
+
+static void
+test_priv_ap_wpa_eap_connection_3 (void)
+{
+ test_ap_wpa_eap_connection_base (NULL, "open",
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE,
+ NM_SETTING_802_1X_ERROR,
+ NM_SETTING_802_1X_ERROR_MISSING_PROPERTY);
+}
+
+static void
+test_priv_ap_wpa_eap_connection_4 (void)
+{
+ test_ap_wpa_eap_connection_base (NULL, "shared",
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE,
+ NM_SETTING_WIRELESS_SECURITY_ERROR,
+ NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY);
+}
+
+static void
+test_priv_ap_wpa_eap_connection_5 (void)
+{
+ test_ap_wpa_eap_connection_base ("wpa-eap", "open",
+ NM_802_11_AP_FLAGS_PRIVACY,
+ NM_802_11_AP_SEC_NONE,
+ NM_802_11_AP_SEC_NONE,
+ FALSE,
+ NM_SETTING_WIRELESS_SECURITY_ERROR,
+ NM_SETTING_WIRELESS_SECURITY_ERROR_INVALID_PROPERTY);
+}
+
+/*******************************************/
+
+#if GLIB_CHECK_VERSION(2,25,12)
+typedef GTestFixtureFunc TCFunc;
+#else
+typedef void (*TCFunc)(void);
+#endif
+
+#define TESTCASE(t, d) g_test_create_case (#t, 0, (gconstpointer) d, NULL, (TCFunc) t, NULL)
+
+int main (int argc, char **argv)
+{
+ GTestSuite *suite;
+
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ suite = g_test_get_root ();
+
+ g_test_suite_add (suite, TESTCASE (test_lock_bssid, NULL));
+
+ /* Open AP tests; make sure that connections to be completed that have
+ * various security-related settings already set cause the completion
+ * to fail.
+ */
+ g_test_suite_add (suite, TESTCASE (test_open_ap_empty_connection, NULL));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_leap_connection_1, TRUE));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_leap_connection_1, FALSE));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_leap_connection_2, NULL));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wep_connection, TRUE));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wep_connection, FALSE));
+
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wpa_psk_connection_1, NULL));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wpa_psk_connection_2, NULL));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wpa_psk_connection_3, NULL));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wpa_psk_connection_4, NULL));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wpa_psk_connection_5, NULL));
+
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wpa_eap_connection_1, NULL));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wpa_eap_connection_2, NULL));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wpa_eap_connection_3, NULL));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wpa_eap_connection_4, NULL));
+ g_test_suite_add (suite, TESTCASE (test_open_ap_wpa_eap_connection_5, NULL));
+
+ /* WEP AP tests */
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_empty_connection, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_leap_connection_1, FALSE));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_leap_connection_2, FALSE));
+
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_dynamic_wep_1, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_dynamic_wep_2, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_dynamic_wep_3, NULL));
+
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_wpa_psk_connection_1, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_wpa_psk_connection_2, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_wpa_psk_connection_3, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_wpa_psk_connection_4, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_wpa_psk_connection_5, NULL));
+
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_wpa_eap_connection_1, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_wpa_eap_connection_2, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_wpa_eap_connection_3, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_wpa_eap_connection_4, NULL));
+ g_test_suite_add (suite, TESTCASE (test_priv_ap_wpa_eap_connection_5, NULL));
+
+ return g_test_run ();
+}
+