From: Timo Sirainen Date: Mon, 3 Aug 2020 13:43:56 +0000 (+0300) Subject: auth: test-lua - Deduplicate code into test_db_lua_auth_request_new() X-Git-Tag: 2.3.13~329 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8841d1b2a8a67ac1687f6280a13050ed0152c847;p=thirdparty%2Fdovecot%2Fcore.git auth: test-lua - Deduplicate code into test_db_lua_auth_request_new() --- diff --git a/src/auth/test-lua.c b/src/auth/test-lua.c index 6b708912ce..2d67380256 100644 --- a/src/auth/test-lua.c +++ b/src/auth/test-lua.c @@ -8,18 +8,23 @@ #include "auth-request.h" #include "db-lua.h" -static void test_db_lua_auth_verify(void) +static struct auth_request *test_db_lua_auth_request_new(void) { - struct auth_settings set; - i_zero(&set); - global_auth_settings = &set; - struct auth_request *req = auth_request_new_dummy(); - struct event *event = event_create(req->event); array_push_back(&req->authdb_event, &event); req->passdb = passdb_mock(); req->fields.user = "testuser"; + return req; +} + +static void test_db_lua_auth_verify(void) +{ + struct auth_settings set; + i_zero(&set); + global_auth_settings = &set; + + struct auth_request *req = test_db_lua_auth_request_new(); static const char *luascript = "function auth_password_verify(req, pass)\n" @@ -44,8 +49,7 @@ static void test_db_lua_auth_verify(void) } i_free(req->passdb); - event_unref(&event); - array_pop_back(&req->authdb_event); + auth_request_passdb_lookup_end(req, PASSDB_RESULT_OK); auth_request_unref(&req); test_end(); @@ -58,12 +62,7 @@ static void test_db_lua_auth_lookup_numberish_value(void) i_zero(&set); global_auth_settings = &set; - struct auth_request *req = auth_request_new_dummy(); - - struct event *event = event_create(req->event); - array_push_back(&req->authdb_event, &event); - req->passdb = passdb_mock(); - req->fields.user = "testuser"; + struct auth_request *req = test_db_lua_auth_request_new(); static const char *luascript = "function auth_passdb_lookup(req)\n" @@ -87,8 +86,7 @@ static void test_db_lua_auth_lookup_numberish_value(void) i_error("Test failed: %s", error); } i_free(req->passdb); - event_unref(&event); - array_pop_back(&req->authdb_event); + auth_request_passdb_lookup_end(req, PASSDB_RESULT_OK); auth_request_unref(&req); test_end(); @@ -101,12 +99,7 @@ static void test_db_lua_auth_lookup(void) i_zero(&set); global_auth_settings = &set; - struct auth_request *req = auth_request_new_dummy(); - - struct event *event = event_create(req->event); - array_push_back(&req->authdb_event, &event); - req->passdb = passdb_mock(); - req->fields.user = "testuser"; + struct auth_request *req = test_db_lua_auth_request_new(); static const char *luascript = "function auth_passdb_lookup(req)\n" @@ -128,8 +121,7 @@ static void test_db_lua_auth_lookup(void) i_error("Test failed: %s", error); } i_free(req->passdb); - event_unref(&event); - array_pop_back(&req->authdb_event); + auth_request_passdb_lookup_end(req, PASSDB_RESULT_OK); auth_request_unref(&req); test_end();