From: Aki Tuomi Date: Fri, 28 Apr 2017 11:42:31 +0000 (+0300) Subject: auth: Organize code into two unit tests X-Git-Tag: 2.3.0.rc1~1676 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=332e3fd09754ad85800a736292a0ef8dfdca4c9e;p=thirdparty%2Fdovecot%2Fcore.git auth: Organize code into two unit tests auth-cache needs special setup --- diff --git a/src/auth/Makefile.am b/src/auth/Makefile.am index 2ad9ac089d..3dfd7a7044 100644 --- a/src/auth/Makefile.am +++ b/src/auth/Makefile.am @@ -224,15 +224,14 @@ libstats_auth_la_SOURCES = auth-stats.c test_programs = \ test-auth-cache \ - test-auth-request-var-expand \ - test-username-filter \ - test-db-dict + test-auth noinst_PROGRAMS = $(test_programs) +noinst_HEADERS = test-auth.h + test_libs = \ - ../lib-test/libtest.la \ - ../lib/liblib.la + ../lib-dovecot/libdovecot.la test_auth_cache_SOURCES = auth-cache.c test-auth-cache.c test_auth_cache_LDADD = $(test_libs) @@ -240,17 +239,14 @@ test_auth_cache_DEPENDENCIES = $(pkglibexec_PROGRAMS) $(test_libs) # this is needed to force auth-cache.c recompilation test_auth_cache_CPPFLAGS = $(AM_CPPFLAGS) -test_auth_request_var_expand_SOURCES = test-auth-request-var-expand.c -test_auth_request_var_expand_LDADD = $(test_libs) libauth.la -test_auth_request_var_expand_DEPENDENCIES = $(pkglibexec_PROGRAMS) $(test_libs) - -test_username_filter_SOURCES = test-username-filter.c -test_username_filter_LDADD = $(test_libs) $(auth_libs) $(AUTH_LIBS) $(LIBDOVECOT) -test_username_filter_DEPENDENCIES = $(pkglibexec_PROGRAMS) $(test_libs) $(LIBDOVECOT_DEPS) - -test_db_dict_SOURCES = test-db-dict.c -test_db_dict_LDADD = $(test_libs) libauth.la -test_db_dict_DEPENDENCIES = $(pkglibexec_PROGRAMS) $(test_libs) +test_auth_SOURCES = \ + test-auth-request-var-expand.c \ + test-username-filter.c \ + test-db-dict.c \ + test-mock.c \ + test-main.c +test_auth_LDADD = $(test_libs) $(auth_libs) $(AUTH_LIBS) +test_auth_DEPENDENCIES = $(pkglibexec_PROGRAMS) $(test_libs) check: check-am check-test check-test: all-am diff --git a/src/auth/test-auth-request-var-expand.c b/src/auth/test-auth-request-var-expand.c index 9b1ab2a416..adf3bce68d 100644 --- a/src/auth/test-auth-request-var-expand.c +++ b/src/auth/test-auth-request-var-expand.c @@ -1,12 +1,11 @@ /* Copyright (c) 2015-2017 Dovecot authors, see the included COPYING file */ -#include "lib.h" +#include "test-auth.h" #include "str.h" #include "auth.h" #include "passdb.h" #include "userdb.h" #include "auth-request.h" -#include "test-common.h" static struct passdb_module test_passdb = { .id = 40 @@ -235,22 +234,18 @@ static void test_auth_request_var_expand_funcs(void) test_end(); } -int main(void) +void test_auth_request_var_expand(void) { - static void (*const test_functions[])(void) = { - test_auth_request_var_expand_shortlong, - test_auth_request_var_expand_flags, - test_auth_request_var_expand_long, - test_auth_request_var_expand_usernames, - test_auth_request_var_expand_funcs, - NULL - }; - default_test_request.local_ip.u.ip4.s_addr = htonl(123456789); default_test_request.remote_ip.u.ip4.s_addr = htonl(1234567890); default_test_request.real_local_ip.u.ip4.s_addr = htonl(223456788); default_test_request.real_remote_ip.u.ip4.s_addr = htonl(223456789); test_request = default_test_request; - return test_run(test_functions); + + test_auth_request_var_expand_shortlong(); + test_auth_request_var_expand_flags(); + test_auth_request_var_expand_long(); + test_auth_request_var_expand_usernames(); + test_auth_request_var_expand_funcs(); } diff --git a/src/auth/test-auth.h b/src/auth/test-auth.h new file mode 100644 index 0000000000..ae059da216 --- /dev/null +++ b/src/auth/test-auth.h @@ -0,0 +1,14 @@ +/* Copyright (c) 2017 Dovecot authors, see the included COPYING file */ + +#ifndef TEST_AUTH_H +#define TEST_AUTH_H 1 + +#include "lib.h" +#include "test-common.h" + +void test_auth_request_var_expand(void); +void test_db_dict_parse_cache_key(void); +void test_username_filter(void); + +#endif + diff --git a/src/auth/test-db-dict.c b/src/auth/test-db-dict.c index ad10235793..e1523434fc 100644 --- a/src/auth/test-db-dict.c +++ b/src/auth/test-db-dict.c @@ -1,11 +1,10 @@ /* Copyright (c) 2013-2017 Dovecot authors, see the included COPYING file */ -#include "lib.h" +#include "test-auth.h" #include "array.h" #include "db-dict.h" -#include "test-common.h" -static void test_db_dict_parse_cache_key(void) +void test_db_dict_parse_cache_key(void) { struct db_dict_key keys[] = { { "key0", "%d and %n", NULL, NULL, 0 }, @@ -40,12 +39,3 @@ static void test_db_dict_parse_cache_key(void) "\t%d and %n\t%l\t%{foo}%r%{bar}\t%{test1}/path\t%{extra}\tpath2/%{test2}\t%{plop}") == 0); test_end(); } - -int main(void) -{ - static void (*const test_functions[])(void) = { - test_db_dict_parse_cache_key, - NULL - }; - return test_run(test_functions); -} diff --git a/src/auth/test-main.c b/src/auth/test-main.c new file mode 100644 index 0000000000..0d7de23ae5 --- /dev/null +++ b/src/auth/test-main.c @@ -0,0 +1,19 @@ +#include "lib.h" +#include "test-common.h" +#include "test-auth.h" + +int main(int argc, const char *argv[]) +{ + const char *match = ""; + static const struct named_test test_functions[] = { + TEST_NAMED(test_auth_request_var_expand) + TEST_NAMED(test_db_dict_parse_cache_key) + TEST_NAMED(test_username_filter) + { NULL, NULL } + }; + + if (argc > 2 && strcasecmp(argv[1], "--match") == 0) + match = argv[2]; + + return test_run_named(test_functions, match); +} diff --git a/src/auth/test-mock.c b/src/auth/test-mock.c new file mode 100644 index 0000000000..b523391323 --- /dev/null +++ b/src/auth/test-mock.c @@ -0,0 +1,11 @@ +#include "lib.h" +#include "auth-common.h" + +struct auth_penalty *auth_penalty; +time_t process_start_time; +bool worker, worker_restart_request; +void auth_module_load(const char *names ATTR_UNUSED) +{ +} +void auth_refresh_proctitle(void) { +} diff --git a/src/auth/test-username-filter.c b/src/auth/test-username-filter.c index ed9e65edb1..c0f64d5e61 100644 --- a/src/auth/test-username-filter.c +++ b/src/auth/test-username-filter.c @@ -1,19 +1,9 @@ /* Copyright (c) 2017 Dovecot authors, see the included COPYING file */ -#include "lib.h" -#include "test-common.h" -#include "auth-common.h" +#include "test-auth.h" #include "auth-request.h" -struct auth_penalty *auth_penalty; -time_t process_start_time; -bool worker, worker_restart_request; -void auth_module_load(const char *names ATTR_UNUSED) -{ -} -void auth_refresh_proctitle(void) { -} -static void test_username_filter(void) +void test_username_filter(void) { const struct { const char *filter; @@ -56,13 +46,3 @@ static void test_username_filter(void) test_end(); } - -int main(void) -{ - static void (*const test_functions[])(void) = { - test_username_filter, - NULL - }; - - return test_run(test_functions); -}