From 27f7a523b46c12756a40b8693747a3e67695301c Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Mon, 8 Apr 2019 11:15:21 -0700 Subject: [PATCH] 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. --- Makefile.am | 8 ++--- unit/{test-ssid-to-utf8.c => test-util.c} | 40 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) rename unit/{test-ssid-to-utf8.c => test-util.c} (74%) diff --git a/Makefile.am b/Makefile.am index dbed35dc..f92808d3 100644 --- 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-util.c similarity index 74% rename from unit/test-ssid-to-utf8.c rename to unit/test-util.c index 5595745c..562a262f 100644 --- a/unit/test-ssid-to-utf8.c +++ b/unit/test-util.c @@ -77,11 +77,51 @@ static void ssid_to_utf8(const void *data) } +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(); }