mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-14 14:18:07 +02:00
2005-12-29 Dan Williams <dcbw@redhat.com>
* test/test-common.c test/test-common.h test/Makefile.am - Move to a test-common subdirectory * test/libnm-util/test-ciphers.c - Move test data to test-inputs.h - Test WPA ciphers too * test/libnm-util/test-dbus-helpers.c - Test serialization/deserialization of ciphers git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@1240 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
b16fe688d2
commit
4783f65521
10 changed files with 603 additions and 88 deletions
14
ChangeLog
14
ChangeLog
|
|
@ -1,3 +1,17 @@
|
|||
2005-12-29 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* test/test-common.c
|
||||
test/test-common.h
|
||||
test/Makefile.am
|
||||
- Move to a test-common subdirectory
|
||||
|
||||
* test/libnm-util/test-ciphers.c
|
||||
- Move test data to test-inputs.h
|
||||
- Test WPA ciphers too
|
||||
|
||||
* test/libnm-util/test-dbus-helpers.c
|
||||
- Test serialization/deserialization of ciphers
|
||||
|
||||
2005-12-29 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* gnome/applet/applet-dbus-devices.c
|
||||
|
|
|
|||
|
|
@ -300,6 +300,7 @@ gnome/libnm_glib/libnm_glib.pc
|
|||
gnome/libnm_glib/Makefile
|
||||
gnome/vpn-properties/Makefile
|
||||
test/Makefile
|
||||
test/test-common/Makefile
|
||||
test/libnm-util/Makefile
|
||||
initscript/Makefile
|
||||
initscript/RedHat/Makefile
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS=libnm-util
|
||||
SUBDIRS=test-common libnm-util
|
||||
|
||||
INCLUDES = -I${top_srcdir} \
|
||||
-I${top_srcdir}/gnome/libnm_glib \
|
||||
|
|
@ -15,8 +15,6 @@ AM_CPPFLAGS = \
|
|||
|
||||
noinst_PROGRAMS = nm-tool nminfotest nmtestdevices libnm_glib_test
|
||||
|
||||
noinst_LTLIBRARIES=libtest-common.la
|
||||
|
||||
nm_tool_SOURCES = nm-tool.c
|
||||
nm_tool_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) $(HAL_LIBS) \
|
||||
$(top_builddir)/utils/libnmutils.la
|
||||
|
|
@ -35,14 +33,3 @@ libnm_glib_test_LDADD = $(DBUS_LIBS) $(GTHREAD_LIBS) \
|
|||
$(top_builddir)/utils/libnmutils.la \
|
||||
../gnome/libnm_glib/libnm_glib.la
|
||||
|
||||
|
||||
libtest_common_la_SOURCES= \
|
||||
test-common.c \
|
||||
test-common.h
|
||||
|
||||
libtest_common_la_CPPFLAGS = \
|
||||
$(GLIB_CFLAGS) \
|
||||
-DG_DISABLE_DEPRECATED
|
||||
|
||||
libtest_common_la_LIBADD = $(GLIB_LIBS)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
INCLUDES = -I${top_srcdir} \
|
||||
-I${top_srcdir}/utils \
|
||||
-I${top_srcdir}/include \
|
||||
-I${top_srcdir}/libnm-util \
|
||||
-I${top_srcdir}/test
|
||||
-I${top_srcdir}/libnm-util \
|
||||
-I${top_srcdir}/test \
|
||||
-I${top_srcdir}/test/test-common
|
||||
|
||||
noinst_PROGRAMS = test-ciphers
|
||||
noinst_PROGRAMS = test-ciphers test-dbus-helpers
|
||||
|
||||
test_ciphers_SOURCES = test-ciphers.c
|
||||
test_ciphers_SOURCES = test-ciphers.c test-inputs.h
|
||||
|
||||
test_ciphers_CPPFLAGS = \
|
||||
$(DBUS_CFLAGS) \
|
||||
|
|
@ -19,4 +20,19 @@ test_ciphers_LDADD = \
|
|||
$(DBUS_LIBS) \
|
||||
$(GLIB_LIBS) \
|
||||
$(top_builddir)/libnm-util/libnm-util.la \
|
||||
$(top_builddir)/test/libtest-common.la
|
||||
$(top_builddir)/test/test-common/libtest-common.la
|
||||
|
||||
test_dbus_helpers_SOURCES = test-dbus-helpers.c test-inputs.h
|
||||
|
||||
test_dbus_helpers_CPPFLAGS = \
|
||||
$(DBUS_CFLAGS) \
|
||||
$(GLIB_CFLAGS) \
|
||||
-DDBUS_API_SUBJECT_TO_CHANGE \
|
||||
-DBINDIR=\"$(bindir)\" \
|
||||
-DDATADIR=\"$(datadir)\"
|
||||
|
||||
test_dbus_helpers_LDADD = \
|
||||
$(DBUS_LIBS) \
|
||||
$(GLIB_LIBS) \
|
||||
$(top_builddir)/libnm-util/libnm-util.la \
|
||||
$(top_builddir)/test/test-common/libtest-common.la
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@
|
|||
#include "cipher-wep-ascii.h"
|
||||
#include "cipher-wep-hex.h"
|
||||
#include "cipher-wep-passphrase.h"
|
||||
#include "cipher-wpa-psk-hex.h"
|
||||
#include "cipher-wpa-psk-passphrase.h"
|
||||
#include "test-inputs.h"
|
||||
#include "test-common.h"
|
||||
|
||||
static char *progname = NULL;
|
||||
|
|
@ -53,77 +56,9 @@ static void test_refcounts (IEEE_802_11_Cipher *cipher, const char *test)
|
|||
}
|
||||
|
||||
|
||||
struct Inputs
|
||||
{
|
||||
char * underrun;
|
||||
char * overrun;
|
||||
char * incorrect_input;
|
||||
char * correct_input;
|
||||
char * correct_output;
|
||||
};
|
||||
|
||||
#define WEP128_ASCII_SELECTOR 0
|
||||
#define WEP64_ASCII_SELECTOR 1
|
||||
#define WEP128_HEX_SELECTOR 2
|
||||
#define WEP64_HEX_SELECTOR 3
|
||||
#define WEP128_PASSPHRASE_SELECTOR 4
|
||||
#define WEP64_PASSPHRASE_SELECTOR 5
|
||||
|
||||
struct Inputs test_input[6] =
|
||||
{
|
||||
{
|
||||
/* WEP128 ASCII */
|
||||
"ph34rm3",
|
||||
"herecomessantaclaus",
|
||||
NULL,
|
||||
"1234567891234",
|
||||
"31323334353637383931323334"
|
||||
},
|
||||
{
|
||||
/* WEP64 ASCII */
|
||||
"1234",
|
||||
"herecomessantaclaus",
|
||||
NULL,
|
||||
"12345",
|
||||
"3132333435"
|
||||
},
|
||||
{
|
||||
/* WEP128 Hex */
|
||||
"3dff2f1f93a87ad",
|
||||
"3235ab39b9b2e32fda8a919b9a021458",
|
||||
"qwertyuiopjxccjvjpapadfjcd",
|
||||
"4ec5de9938b606e9d40dff721e",
|
||||
"4ec5de9938b606e9d40dff721e"
|
||||
},
|
||||
{
|
||||
/* WEP64 Hex */
|
||||
"3dff2f1f",
|
||||
"3235ab39b9b2e",
|
||||
"qwertyuiop",
|
||||
"4ec5de9938",
|
||||
"4ec5de9938"
|
||||
},
|
||||
{
|
||||
/* WEP128 Passphrse */
|
||||
"",
|
||||
"3235ab39b9b2e32fda8a919b9a0214583235ab39b9b2e32fda8a919b9a0214583acb",
|
||||
NULL,
|
||||
"You don't remember me but I remember you.",
|
||||
"06a9c70715fe06129c625a248d"
|
||||
},
|
||||
{
|
||||
/* WEP64 Passphrse */
|
||||
"",
|
||||
"3235ab39b9b2e32fda8a919b9a0214583235ab39b9b2e32fda8a919b9a0214583acb",
|
||||
NULL,
|
||||
"Have you forgotten all I know?",
|
||||
"18074f3178"
|
||||
}
|
||||
};
|
||||
|
||||
static void test_inputs (IEEE_802_11_Cipher *cipher, const char *test, int selector)
|
||||
{
|
||||
#define ESSID "foobar"
|
||||
#define ESSID "ThisIsASSID"
|
||||
struct Inputs * input = &test_input[selector];
|
||||
char *output;
|
||||
char *correct_output;
|
||||
|
|
@ -162,6 +97,8 @@ static void test_wep_ascii (void)
|
|||
{
|
||||
IEEE_802_11_Cipher *cipher;
|
||||
|
||||
fprintf (stderr, "\n\n---- START: WEP ASCII ---------------------------------------------\n");
|
||||
|
||||
/* Test basic object creation */
|
||||
if (!(cipher = cipher_wep128_ascii_new ()))
|
||||
test_result (progname, "new_wep128_ascii", TEST_FAIL, "Could not create WEP104 ASCII cipher.\n");
|
||||
|
|
@ -192,6 +129,8 @@ static void test_wep_hex (void)
|
|||
{
|
||||
IEEE_802_11_Cipher *cipher;
|
||||
|
||||
fprintf (stderr, "\n\n---- START: WEP Hex ---------------------------------------------\n");
|
||||
|
||||
/* Test basic object creation */
|
||||
if (!(cipher = cipher_wep128_hex_new ()))
|
||||
test_result (progname, "new_wep128_hex", TEST_FAIL, "Could not create WEP104 Hex cipher.\n");
|
||||
|
|
@ -222,6 +161,8 @@ static void test_wep_passphrase (void)
|
|||
{
|
||||
IEEE_802_11_Cipher *cipher;
|
||||
|
||||
fprintf (stderr, "\n\n---- START: WEP Passphrase ---------------------------------------------\n");
|
||||
|
||||
/* Test basic object creation */
|
||||
if (!(cipher = cipher_wep128_passphrase_new ()))
|
||||
test_result (progname, "new_wep128_passphrase", TEST_FAIL, "Could not create WEP104 Passphrase cipher.\n");
|
||||
|
|
@ -248,6 +189,47 @@ static void test_wep_passphrase (void)
|
|||
ieee_802_11_cipher_unref (cipher);
|
||||
}
|
||||
|
||||
static void test_wpa_psk_hex (void)
|
||||
{
|
||||
IEEE_802_11_Cipher *cipher;
|
||||
|
||||
fprintf (stderr, "\n\n---- START: WPA-PSK Hex ---------------------------------------------\n");
|
||||
|
||||
/* Test basic object creation */
|
||||
if (!(cipher = cipher_wpa_psk_hex_new ()))
|
||||
test_result (progname, "new_wpa_psk_hex", TEST_FAIL, "Could not create WPA-PSK Hex cipher.\n");
|
||||
test_result (progname, "new_wpa_psk_hex", TEST_SUCCEED, NULL);
|
||||
/* Test object refcounting */
|
||||
test_refcounts (cipher, "wpa_psk_hex_refcounts");
|
||||
|
||||
/* Test inputs */
|
||||
if (!(cipher = cipher_wpa_psk_hex_new ()))
|
||||
test_result (progname, "new_wpa_psk_hex", TEST_FAIL, "Could not create WPA-PSK Hex cipher.\n");
|
||||
test_inputs (cipher, "inputs_wpa_psk_hex", WPA_PSK_HEX_SELECTOR);
|
||||
ieee_802_11_cipher_unref (cipher);
|
||||
}
|
||||
|
||||
static void test_wpa_psk_passphrase (void)
|
||||
{
|
||||
IEEE_802_11_Cipher *cipher;
|
||||
|
||||
fprintf (stderr, "\n\n---- START: WPA-PSK Passphrase ---------------------------------------------\n");
|
||||
|
||||
/* Test basic object creation */
|
||||
if (!(cipher = cipher_wpa_psk_passphrase_new ()))
|
||||
test_result (progname, "new_wpa_psk_passphrase", TEST_FAIL, "Could not create WPA-PSK Passphrase cipher.\n");
|
||||
test_result (progname, "new_wpa_psk_passphrase", TEST_SUCCEED, NULL);
|
||||
/* Test object refcounting */
|
||||
test_refcounts (cipher, "wpa_psk_passphrase_refcounts");
|
||||
|
||||
/* Test inputs */
|
||||
if (!(cipher = cipher_wpa_psk_passphrase_new ()))
|
||||
test_result (progname, "new_wpa_psk_passphrase", TEST_FAIL, "Could not create WPA-PSK Passphrase cipher.\n");
|
||||
test_inputs (cipher, "inputs_wpa_psk_passphrase", WPA_PSK_PASSPHRASE_SELECTOR);
|
||||
ieee_802_11_cipher_unref (cipher);
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
progname = argv[0];
|
||||
|
|
@ -255,6 +237,10 @@ int main (int argc, char **argv)
|
|||
test_wep_ascii ();
|
||||
test_wep_hex ();
|
||||
test_wep_passphrase ();
|
||||
test_wpa_psk_hex ();
|
||||
test_wpa_psk_passphrase ();
|
||||
|
||||
fprintf (stderr, "\n\n------ DONE\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
266
test/libnm-util/test-dbus-helpers.c
Normal file
266
test/libnm-util/test-dbus-helpers.c
Normal file
|
|
@ -0,0 +1,266 @@
|
|||
/* NetworkManager -- Forget about your network
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* 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 of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dbus/dbus.h>
|
||||
#include <iwlib.h>
|
||||
|
||||
#include "cipher.h"
|
||||
#include "cipher-wep-ascii.h"
|
||||
#include "cipher-wep-hex.h"
|
||||
#include "cipher-wep-passphrase.h"
|
||||
#include "cipher-wpa-psk-hex.h"
|
||||
#include "cipher-wpa-psk-passphrase.h"
|
||||
#include "test-inputs.h"
|
||||
#include "test-common.h"
|
||||
#include "dbus-helpers.h"
|
||||
|
||||
static char *progname = NULL;
|
||||
#define ESSID "ThisIsASSID"
|
||||
|
||||
static void
|
||||
test_serialize_wep (const char * test,
|
||||
IEEE_802_11_Cipher *cipher,
|
||||
int selector,
|
||||
int auth_alg)
|
||||
{
|
||||
DBusMessage * message;
|
||||
const char * signature;
|
||||
DBusMessageIter iter;
|
||||
dbus_int32_t int_arg;
|
||||
char * str_arg;
|
||||
char * hashed;
|
||||
|
||||
message = dbus_message_new_method_call ("org.foobar", "/org/foobar", "org.foobar", "foobar");
|
||||
if (!message)
|
||||
test_result (progname, test, TEST_FAIL, "Couldn't create test dbus message.\n");
|
||||
|
||||
if (!nmu_security_serialize_wep_with_cipher (message,
|
||||
cipher,
|
||||
ESSID,
|
||||
test_input[selector].correct_input,
|
||||
auth_alg))
|
||||
{
|
||||
test_result (progname, test, TEST_FAIL, "Couldn't serialize cipher into dbus message.\n");
|
||||
}
|
||||
|
||||
if (!(signature = dbus_message_get_signature (message)))
|
||||
test_result (progname, test, TEST_FAIL, "Couldn't retrieve test dbus message's signature.\n");
|
||||
|
||||
/* Verify message signature */
|
||||
#define CORRECT_SIGNATURE "isi"
|
||||
if (strcmp (signature, CORRECT_SIGNATURE) != 0)
|
||||
{
|
||||
test_result (progname, test, TEST_FAIL, "Signature of serialized cipher (%s)"
|
||||
" didn't match expected (%s).\n", signature, CORRECT_SIGNATURE);
|
||||
}
|
||||
|
||||
/* Verify message arguments */
|
||||
dbus_message_iter_init (message, &iter);
|
||||
|
||||
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32)
|
||||
test_result (progname, test, TEST_FAIL, "Message's we_cipher element expected but not found.\n");
|
||||
|
||||
dbus_message_iter_get_basic (&iter, &int_arg);
|
||||
if (int_arg != ieee_802_11_cipher_get_we_cipher (cipher))
|
||||
{
|
||||
test_result (progname, test, TEST_FAIL, "Message's we_cipher element (%d)"
|
||||
" did not match expected value (%d).\n", int_arg, ieee_802_11_cipher_get_we_cipher (cipher));
|
||||
}
|
||||
|
||||
if (!dbus_message_iter_has_next (&iter))
|
||||
test_result (progname, test, TEST_FAIL, "Message's key element expected but not found.\n");
|
||||
dbus_message_iter_next (&iter);
|
||||
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING)
|
||||
test_result (progname, test, TEST_FAIL, "Message's key element expected but not found after next.\n");
|
||||
|
||||
dbus_message_iter_get_basic (&iter, &str_arg);
|
||||
if (!(hashed = ieee_802_11_cipher_hash (cipher, ESSID, test_input[selector].correct_input)))
|
||||
test_result (progname, test, TEST_FAIL, "Couldn't hash encryption key input.\n");
|
||||
if (!str_arg || (strcmp (hashed, str_arg) != 0))
|
||||
{
|
||||
test_result (progname, test, TEST_FAIL, "Message's key element (%s) did not match expected value (%s).\n",
|
||||
str_arg, hashed);
|
||||
g_free (hashed);
|
||||
}
|
||||
g_free (hashed);
|
||||
|
||||
if (!dbus_message_iter_has_next (&iter))
|
||||
test_result (progname, test, TEST_FAIL, "Message's auth_algorithm element expected but not found.\n");
|
||||
dbus_message_iter_next (&iter);
|
||||
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INT32)
|
||||
test_result (progname, test, TEST_FAIL, "Message's auth_algorithm element expected but not found after next.\n");
|
||||
|
||||
dbus_message_iter_get_basic (&iter, &int_arg);
|
||||
if (int_arg != auth_alg)
|
||||
{
|
||||
test_result (progname, test, TEST_FAIL, "Message's auth_algoritm element (%s) did not match expected value (%s).\n",
|
||||
int_arg, auth_alg);
|
||||
}
|
||||
|
||||
dbus_message_unref (message);
|
||||
test_result (progname, test, TEST_SUCCEED, NULL);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
test_deserialize_wep (const char *test,
|
||||
int selector,
|
||||
int auth_alg)
|
||||
{
|
||||
DBusMessage * message;
|
||||
DBusMessageIter iter;
|
||||
char * msg_key = NULL;
|
||||
int msg_key_len;
|
||||
int msg_auth_alg;
|
||||
int real_key_len;
|
||||
|
||||
message = dbus_message_new_method_call ("org.foobar", "/org/foobar", "org.foobar", "foobar");
|
||||
if (!message)
|
||||
test_result (progname, test, TEST_FAIL, "Couldn't create test dbus message.\n");
|
||||
|
||||
/* Build up test message */
|
||||
dbus_message_iter_init_append (message, &iter);
|
||||
dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &test_input[selector].we_cipher);
|
||||
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &test_input[selector].correct_output);
|
||||
dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &auth_alg);
|
||||
|
||||
dbus_message_iter_init (message, &iter);
|
||||
/* Skip we_cipher element */
|
||||
dbus_message_iter_next (&iter);
|
||||
if (!nmu_security_deserialize_wep (&iter, &msg_key, &msg_key_len, &msg_auth_alg))
|
||||
test_result (progname, test, TEST_FAIL, "Error deserializing from dbus message.\n");
|
||||
|
||||
if (strcmp (msg_key, test_input[selector].correct_output) != 0)
|
||||
{
|
||||
test_result (progname, test, TEST_FAIL, "Message's key element (%s) did not match expected value (%s).\n",
|
||||
msg_key, test_input[selector].correct_output);
|
||||
}
|
||||
|
||||
real_key_len = strlen (test_input[selector].correct_output);
|
||||
if (msg_key_len != real_key_len)
|
||||
{
|
||||
test_result (progname, test, TEST_FAIL, "Message's key element length (%d) did not match expected value (%d).\n",
|
||||
msg_key_len, real_key_len);
|
||||
}
|
||||
|
||||
if (msg_auth_alg != auth_alg)
|
||||
{
|
||||
test_result (progname, test, TEST_FAIL, "Message's auth_algorithm (%d) did not match expected value (%d).\n",
|
||||
msg_auth_alg, auth_alg);
|
||||
}
|
||||
|
||||
dbus_message_unref (message);
|
||||
test_result (progname, test, TEST_SUCCEED, NULL);
|
||||
}
|
||||
|
||||
|
||||
static void test_wep_ascii (void)
|
||||
{
|
||||
IEEE_802_11_Cipher *cipher;
|
||||
|
||||
fprintf (stdout, "\n\n---- START: WEP ASCII ---------------------------------------------\n");
|
||||
|
||||
if (!(cipher = cipher_wep128_ascii_new ()))
|
||||
test_result (progname, "new_wep128_ascii", TEST_FAIL, "Could not create WEP104 ASCII cipher.\n");
|
||||
test_serialize_wep ("serialize_wep128_ascii_os", cipher, WEP128_ASCII_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_serialize_wep ("serialize_wep128_ascii_sk", cipher, WEP128_ASCII_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
ieee_802_11_cipher_unref (cipher);
|
||||
|
||||
test_deserialize_wep ("deserialize_wep128_ascii_os", WEP128_ASCII_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_deserialize_wep ("deserialize_wep128_ascii_sk", WEP128_ASCII_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
|
||||
if (!(cipher = cipher_wep64_ascii_new ()))
|
||||
test_result (progname, "new_wep64_ascii", TEST_FAIL, "Could not create WEP40 ASCII cipher.\n");
|
||||
test_serialize_wep ("serialize_wep64_ascii_os", cipher, WEP64_ASCII_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_serialize_wep ("serialize_wep64_ascii_sk", cipher, WEP64_ASCII_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
ieee_802_11_cipher_unref (cipher);
|
||||
|
||||
test_deserialize_wep ("deserialize_wep64_ascii_os", WEP64_ASCII_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_deserialize_wep ("deserialize_wep64_ascii_sk", WEP64_ASCII_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
}
|
||||
|
||||
static void test_wep_hex (void)
|
||||
{
|
||||
IEEE_802_11_Cipher *cipher;
|
||||
|
||||
fprintf (stdout, "\n\n---- START: WEP Hex ---------------------------------------------\n");
|
||||
|
||||
if (!(cipher = cipher_wep128_hex_new ()))
|
||||
test_result (progname, "new_wep128_hex", TEST_FAIL, "Could not create WEP104 Hex cipher.\n");
|
||||
test_serialize_wep ("serialize_wep128_hex_os", cipher, WEP128_HEX_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_serialize_wep ("serialize_wep128_hex_sk", cipher, WEP128_HEX_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
ieee_802_11_cipher_unref (cipher);
|
||||
|
||||
test_deserialize_wep ("deserialize_wep128_hex_os", WEP128_HEX_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_deserialize_wep ("deserialize_wep128_hex_sk", WEP128_HEX_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
|
||||
if (!(cipher = cipher_wep64_hex_new ()))
|
||||
test_result (progname, "new_wep64_hex", TEST_FAIL, "Could not create WEP40 Hex cipher.\n");
|
||||
test_serialize_wep ("serialize_wep64_hex_os", cipher, WEP64_HEX_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_serialize_wep ("serialize_wep64_hex_sk", cipher, WEP64_HEX_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
ieee_802_11_cipher_unref (cipher);
|
||||
|
||||
test_deserialize_wep ("deserialize_wep64_hex_os", WEP64_HEX_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_deserialize_wep ("deserialize_wep64_hex_sk", WEP64_HEX_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
}
|
||||
|
||||
|
||||
static void test_wep_passphrase (void)
|
||||
{
|
||||
IEEE_802_11_Cipher *cipher;
|
||||
|
||||
fprintf (stdout, "\n\n---- START: WEP Passphrase ---------------------------------------------\n");
|
||||
|
||||
if (!(cipher = cipher_wep128_passphrase_new ()))
|
||||
test_result (progname, "new_wep128_passphrase", TEST_FAIL, "Could not create WEP104 Passphrase cipher.\n");
|
||||
test_serialize_wep ("serialize_wep128_passphrase_os", cipher, WEP128_PASSPHRASE_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_serialize_wep ("serialize_wep128_passphrase_sk", cipher, WEP128_PASSPHRASE_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
ieee_802_11_cipher_unref (cipher);
|
||||
|
||||
test_deserialize_wep ("deserialize_wep128_passphrase_os", WEP128_PASSPHRASE_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_deserialize_wep ("deserialize_wep128_passphrase_sk", WEP128_PASSPHRASE_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
|
||||
if (!(cipher = cipher_wep64_passphrase_new ()))
|
||||
test_result (progname, "new_wep64_passphrase", TEST_FAIL, "Could not create WEP40 Passphrase cipher.\n");
|
||||
test_serialize_wep ("serialize_wep64_passphrase_os", cipher, WEP64_PASSPHRASE_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_serialize_wep ("serialize_wep64_passphrase_sk", cipher, WEP64_PASSPHRASE_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
ieee_802_11_cipher_unref (cipher);
|
||||
|
||||
test_deserialize_wep ("deserialize_wep64_passphrase_os", WEP64_PASSPHRASE_SELECTOR, IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
test_deserialize_wep ("deserialize_wep64_passphrase_sk", WEP64_PASSPHRASE_SELECTOR, IW_AUTH_ALG_SHARED_KEY);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
progname = argv[0];
|
||||
|
||||
test_wep_ascii ();
|
||||
test_wep_hex ();
|
||||
test_wep_passphrase ();
|
||||
|
||||
fprintf (stderr, "\n\n------ DONE\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
122
test/libnm-util/test-inputs.h
Normal file
122
test/libnm-util/test-inputs.h
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* 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 of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef TEST_INPUTS_H
|
||||
#define TEST_INPUTS_H
|
||||
|
||||
#include <iwlib.h>
|
||||
|
||||
struct Inputs
|
||||
{
|
||||
int we_cipher;
|
||||
char * underrun;
|
||||
char * overrun;
|
||||
char * incorrect_input;
|
||||
char * correct_input;
|
||||
char * correct_output;
|
||||
};
|
||||
|
||||
#define WEP128_ASCII_SELECTOR 0
|
||||
#define WEP64_ASCII_SELECTOR 1
|
||||
#define WEP128_HEX_SELECTOR 2
|
||||
#define WEP64_HEX_SELECTOR 3
|
||||
#define WEP128_PASSPHRASE_SELECTOR 4
|
||||
#define WEP64_PASSPHRASE_SELECTOR 5
|
||||
#define WPA_PSK_HEX_SELECTOR 6
|
||||
#define WPA_PSK_PASSPHRASE_SELECTOR 7
|
||||
|
||||
struct Inputs test_input[8] =
|
||||
{
|
||||
{
|
||||
/* WEP128 ASCII */
|
||||
IW_AUTH_CIPHER_WEP104,
|
||||
"ph34rm3",
|
||||
"herecomessantaclaus",
|
||||
NULL,
|
||||
"1234567891234",
|
||||
"31323334353637383931323334"
|
||||
},
|
||||
{
|
||||
/* WEP64 ASCII */
|
||||
IW_AUTH_CIPHER_WEP40,
|
||||
"1234",
|
||||
"herecomessantaclaus",
|
||||
NULL,
|
||||
"12345",
|
||||
"3132333435"
|
||||
},
|
||||
{
|
||||
/* WEP128 Hex */
|
||||
IW_AUTH_CIPHER_WEP104,
|
||||
"3dff2f1f93a87ad",
|
||||
"3235ab39b9b2e32fda8a919b9a021458",
|
||||
"qwertyuiopjxccjvjpapadfjcd",
|
||||
"4ec5de9938b606e9d40dff721e",
|
||||
"4ec5de9938b606e9d40dff721e"
|
||||
},
|
||||
{
|
||||
/* WEP64 Hex */
|
||||
IW_AUTH_CIPHER_WEP40,
|
||||
"3dff2f1f",
|
||||
"3235ab39b9b2e",
|
||||
"qwertyuiop",
|
||||
"4ec5de9938",
|
||||
"4ec5de9938"
|
||||
},
|
||||
{
|
||||
/* WEP128 Passphrse */
|
||||
IW_AUTH_CIPHER_WEP104,
|
||||
"",
|
||||
"3235ab39b9b2e32fda8a919b9a0214583235ab39b9b2e32fda8a919b9a0214583acb",
|
||||
NULL,
|
||||
"You don't remember me but I remember you.",
|
||||
"06a9c70715fe06129c625a248d"
|
||||
},
|
||||
{
|
||||
/* WEP64 Passphrse */
|
||||
IW_AUTH_CIPHER_WEP40,
|
||||
"",
|
||||
"3235ab39b9b2e32fda8a919b9a0214583235ab39b9b2e32fda8a919b9a0214583acb",
|
||||
NULL,
|
||||
"Have you forgotten all I know?",
|
||||
"18074f3178"
|
||||
},
|
||||
{
|
||||
/* WPA PSK Hex */
|
||||
IW_AUTH_CIPHER_TKIP,
|
||||
"3220a0adbad22310",
|
||||
"3235ab39b9b2e32f5a5b5c5a8e8c8b8a09129abfbe293959fa9023b20bacb09320214583acb",
|
||||
"waetueuasdghadsg83282af",
|
||||
"22ad0a0c0dea0b0a09a6a54aeb5dc42838d7f128a6f6b6e6d77c7c7aa3d4b4ae",
|
||||
"22ad0a0c0dea0b0a09a6a54aeb5dc42838d7f128a6f6b6e6d77c7c7aa3d4b4ae"
|
||||
},
|
||||
{
|
||||
/* WPA PSK Passphrase */
|
||||
IW_AUTH_CIPHER_TKIP,
|
||||
"",
|
||||
"This is a really long passphrase since it's supposed to be a test of overflow.",
|
||||
NULL,
|
||||
"ThisIsAPassword",
|
||||
"0dc0d6eb90555ed6419756b9a15ec3e3209b63df707dd508d14581f8982721af"
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* TEST_INPUTS_H */
|
||||
19
test/test-common/Makefile.am
Normal file
19
test/test-common/Makefile.am
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
INCLUDES = -I${top_srcdir} \
|
||||
-I${top_srcdir}/utils \
|
||||
-I${top_srcdir}/include \
|
||||
-I${top_srcdir}/libnm-util \
|
||||
-I${top_srcdir}/test
|
||||
|
||||
noinst_LTLIBRARIES=libtest-common.la
|
||||
|
||||
|
||||
libtest_common_la_SOURCES= \
|
||||
test-common.c \
|
||||
test-common.h
|
||||
|
||||
libtest_common_la_CPPFLAGS = \
|
||||
$(GLIB_CFLAGS) \
|
||||
-DG_DISABLE_DEPRECATED
|
||||
|
||||
libtest_common_la_LIBADD = $(GLIB_LIBS)
|
||||
|
||||
63
test/test-common/test-common.c
Normal file
63
test/test-common/test-common.c
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/* NetworkManager -- Forget about your network
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* 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 of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "test-common.h"
|
||||
|
||||
|
||||
void
|
||||
test_result (const char *progname,
|
||||
const char *test,
|
||||
TestResult result,
|
||||
const char *format,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
char * errmsg = NULL;
|
||||
char * full_msg = NULL;
|
||||
char * result_string = NULL;
|
||||
|
||||
if (format)
|
||||
{
|
||||
errmsg = g_malloc0 (257);
|
||||
va_start (args, format);
|
||||
vsnprintf (errmsg, 256, format, args);
|
||||
va_end (args);
|
||||
}
|
||||
|
||||
if (result == TEST_FAIL)
|
||||
result_string = "FAIL";
|
||||
else
|
||||
result_string = "SUCCEED";
|
||||
|
||||
full_msg = g_strdup_printf ("%s: (%s) %s %s\n", progname, test, result_string, errmsg ? errmsg : "");
|
||||
fprintf (stderr, full_msg);
|
||||
g_free (full_msg);
|
||||
g_free (errmsg);
|
||||
|
||||
if (result == TEST_FAIL)
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
41
test/test-common/test-common.h
Normal file
41
test/test-common/test-common.h
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* NetworkManager -- Forget about your network
|
||||
*
|
||||
* Dan Williams <dcbw@redhat.com>
|
||||
*
|
||||
* 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 of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* (C) Copyright 2005 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef TEST_COMMON_H
|
||||
#define TEST_COMMON_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef enum TestResult
|
||||
{
|
||||
TEST_FAIL = 0,
|
||||
TEST_SUCCEED
|
||||
} TestResult;
|
||||
|
||||
void test_result (const char *progname,
|
||||
const char *test,
|
||||
TestResult result,
|
||||
const char *format,
|
||||
...);
|
||||
|
||||
#endif /* TEST_COMMON_H */
|
||||
Loading…
Add table
Reference in a new issue