commit 27f7a523b46c12756a40b8693747a3e67695301c
parent 1e337259ceb9de011f188e4376f1171a4c9cc43c
Author: James Prestwood <james.prestwood@linux.intel.com>
Date: Mon, 8 Apr 2019 11:15:21 -0700
unit: add tests for util_get_{domain,username}
test-ssid-to-utf8 was hijacked and renamed to test-util, and
two tests were added for the new utility functions.
Diffstat:
3 files changed, 131 insertions(+), 91 deletions(-)
diff --git a/Makefile.am b/Makefile.am
@@ -312,7 +312,7 @@ unit_tests = unit/test-cmac-aes \
unit/test-hmac-md5 unit/test-hmac-sha1 unit/test-hmac-sha256 \
unit/test-prf-sha1 unit/test-kdf-sha256 \
unit/test-crypto unit/test-eapol unit/test-mpdu \
- unit/test-ie unit/test-ssid-to-utf8 unit/test-ssid-security \
+ unit/test-ie unit/test-util unit/test-ssid-security \
unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \
unit/test-eap-sim unit/test-sae
@@ -399,9 +399,9 @@ unit_test_eapol_SOURCES = unit/test-eapol.c \
unit_test_eapol_LDADD = $(ell_ldadd)
unit_test_eapol_DEPENDENCIES = ell/unit/test_data
-unit_test_ssid_to_utf8_SOURCES = src/util.h src/util.c \
- unit/test-ssid-to-utf8.c
-unit_test_ssid_to_utf8_LDADD = $(ell_ldadd)
+unit_test_util_SOURCES = src/util.h src/util.c \
+ unit/test-util.c
+unit_test_util_LDADD = $(ell_ldadd)
unit_test_ssid_security_SOURCES = unit/test-ssid-security.c src/ie.h src/ie.c \
src/common.h src/common.c
diff --git a/unit/test-ssid-to-utf8.c b/unit/test-ssid-to-utf8.c
@@ -1,87 +0,0 @@
-/*
- *
- * Wireless daemon for Linux
- *
- * Copyright (C) 2014 Intel Corporation. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-#include <ell/ell.h>
-
-#include "src/util.h"
-
-struct ssid_test_data {
- size_t len;
- uint8_t ssid[32];
- const char *string;
- bool result;
-};
-
-const struct ssid_test_data ssid_samples[] = {
- { 0, { }, "", true },
- { 1, { }, "", true },
- { 32, { }, "", true },
- { 33, { }, "", true },
- { 33, { 'a', 'b', 'c', }, "", true },
- { 42, { }, "", true },
- { 3, { 'f', 'o', 'o', }, "foo", true },
- { 3, { }, "", true },
- { 3, { 'f', 'o', 'o', }, "bar", false },
- { 3, { 'f', 'o', 'o', 0xff, }, "foo", true },
- { 5, { 'f', 'o', 'o', 'b', 'a', 'r' }, "fooba", true },
- { 5, { 'f', 'o', 'o', 'b', 'a', 'r' }, "foobar", false },
- { 5, { 'f', 'o', 'o', 'b', 'a', 'r' }, "oobar", false },
- { 4, { 'x', 'y', 'z', 0xff }, "xyz�", true },
- { 6, { 'x', 'y', 'z', 0xff, '1', '2' }, "xyz�12", true },
- { 7, { 0xf0, 0xf3, '3', '4', '5', '6', '7', }, "��34567", true },
- { 6, { 0xc3, 0x96, '3', '4', '5', '6' }, "Ö3456", true },
- { 6, { '1', 0xc3, 0x96, '4', '5', '6' }, "1Ö456", true },
- { 6, { '1', '2', '3', '4', 0xc3, 0x96 }, "1234Ö", true },
-};
-
-static void ssid_to_utf8(const void *data)
-{
- const struct ssid_test_data *ssid = data;
- int i = 0, samples = L_ARRAY_SIZE(ssid_samples);
-
- while (i < samples) {
- const char *result = util_ssid_to_utf8(ssid[i].len,
- ssid[i].ssid);
-
- assert(!memcmp(ssid[i].string, result,
- strlen(ssid[i].string)) == ssid[i].result);
-
- i++;
- }
-
-}
-
-int main(int argc, char *argv[])
-{
- l_test_init(&argc, &argv);
-
- l_test_add("/util/ssid_to_utf8/", ssid_to_utf8, ssid_samples);
-
- return l_test_run();
-}
diff --git a/unit/test-util.c b/unit/test-util.c
@@ -0,0 +1,127 @@
+/*
+ *
+ * Wireless daemon for Linux
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+#include <ell/ell.h>
+
+#include "src/util.h"
+
+struct ssid_test_data {
+ size_t len;
+ uint8_t ssid[32];
+ const char *string;
+ bool result;
+};
+
+const struct ssid_test_data ssid_samples[] = {
+ { 0, { }, "", true },
+ { 1, { }, "", true },
+ { 32, { }, "", true },
+ { 33, { }, "", true },
+ { 33, { 'a', 'b', 'c', }, "", true },
+ { 42, { }, "", true },
+ { 3, { 'f', 'o', 'o', }, "foo", true },
+ { 3, { }, "", true },
+ { 3, { 'f', 'o', 'o', }, "bar", false },
+ { 3, { 'f', 'o', 'o', 0xff, }, "foo", true },
+ { 5, { 'f', 'o', 'o', 'b', 'a', 'r' }, "fooba", true },
+ { 5, { 'f', 'o', 'o', 'b', 'a', 'r' }, "foobar", false },
+ { 5, { 'f', 'o', 'o', 'b', 'a', 'r' }, "oobar", false },
+ { 4, { 'x', 'y', 'z', 0xff }, "xyz�", true },
+ { 6, { 'x', 'y', 'z', 0xff, '1', '2' }, "xyz�12", true },
+ { 7, { 0xf0, 0xf3, '3', '4', '5', '6', '7', }, "��34567", true },
+ { 6, { 0xc3, 0x96, '3', '4', '5', '6' }, "Ö3456", true },
+ { 6, { '1', 0xc3, 0x96, '4', '5', '6' }, "1Ö456", true },
+ { 6, { '1', '2', '3', '4', 0xc3, 0x96 }, "1234Ö", true },
+};
+
+static void ssid_to_utf8(const void *data)
+{
+ const struct ssid_test_data *ssid = data;
+ int i = 0, samples = L_ARRAY_SIZE(ssid_samples);
+
+ while (i < samples) {
+ const char *result = util_ssid_to_utf8(ssid[i].len,
+ ssid[i].ssid);
+
+ assert(!memcmp(ssid[i].string, result,
+ strlen(ssid[i].string)) == ssid[i].result);
+
+ i++;
+ }
+
+}
+
+static const char ms_id[] = "domain\\user";
+static const char id[] = "user@domain";
+static const char no_separator[] = "username";
+
+static void get_domain_test(const void *data)
+{
+ const char *test;
+
+ test = util_get_domain(ms_id);
+
+ assert(strcmp(test, "domain") == 0);
+
+ test = util_get_domain(id);
+
+ assert(strcmp(test, "domain") == 0);
+
+ test = util_get_domain(no_separator);
+
+ assert(strcmp(test, "username") == 0);
+}
+
+static void get_username_test(const void *data)
+{
+ const char *test;
+
+ test = util_get_username(ms_id);
+
+ assert(strcmp(test, "user") == 0);
+
+ test = util_get_username(id);
+
+ assert(strcmp(test, "user") == 0);
+
+ test = util_get_username(no_separator);
+
+ assert(strcmp(test, "username") == 0);
+}
+
+int main(int argc, char *argv[])
+{
+ l_test_init(&argc, &argv);
+
+ l_test_add("/util/ssid_to_utf8/", ssid_to_utf8, ssid_samples);
+ l_test_add("/util/get_domain/", get_domain_test, NULL);
+ l_test_add("/util/get_username/", get_username_test, NULL);
+
+ return l_test_run();
+}