]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: test - make sure memory gets free'd
authorAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 17 Apr 2018 09:11:05 +0000 (12:11 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 28 May 2018 07:07:18 +0000 (10:07 +0300)
src/auth/test-auth.h
src/auth/test-lua.c
src/auth/test-main.c
src/auth/test-mock.c

index f4565c2a02fe12175a1339eab2d7674f940735db..ef596e96bfae6662cf52dd5d736226cd6a6aa1e3 100644 (file)
@@ -13,6 +13,8 @@ void test_db_dict_parse_cache_key(void);
 void test_username_filter(void);
 void test_db_lua(void);
 struct auth_passdb *passdb_mock(void);
+void passdb_mock_mod_init(void);
+void passdb_mock_mod_deinit(void);
 
 #endif
 
index ab5b4f032bbe41cbea9859559a24ca93b25c5388..79ab9eb7ad12d1e014b24c3d64b6c3e39cce104a 100644 (file)
@@ -13,7 +13,6 @@ static void test_db_lua_auth_verify(void)
         struct auth_settings set;
         i_zero(&set);
         global_auth_settings = &set;
-        passdbs_init();
 
         struct auth_request *req = auth_request_new_dummy();
         req->passdb = passdb_mock();
@@ -52,7 +51,6 @@ static void test_db_lua_auth_lookup(void)
        struct auth_settings set;
        i_zero(&set);
        global_auth_settings = &set;
-       passdbs_init();
 
        struct auth_request *req = auth_request_new_dummy();
        req->passdb = passdb_mock();
index 2275d19764c5fc699f190cf0635d30dd0fed7cc7..70025c1ccbf21fc470c260fa9a038513b35ea89c 100644 (file)
@@ -4,10 +4,12 @@
 #include "test-common.h"
 #include "test-auth.h"
 #include "password-scheme.h"
+#include "passdb.h"
 
 int main(int argc, const char *argv[])
 {
        const char *match = "";
+       int ret;
        static const struct named_test test_functions[] = {
                TEST_NAMED(test_auth_request_var_expand)
                TEST_NAMED(test_db_dict_parse_cache_key)
@@ -19,9 +21,17 @@ int main(int argc, const char *argv[])
        };
 
        password_schemes_init();
+       passdbs_init();
+       passdb_mock_mod_init();
 
        if (argc > 2 && strcasecmp(argv[1], "--match") == 0)
                match = argv[2];
 
-       return test_run_named(test_functions, match);
+       ret = test_run_named(test_functions, match);
+
+       passdb_mock_mod_deinit();
+       password_schemes_deinit();
+       passdbs_deinit();
+
+       return ret;
 }
index 8834f7221cd4fcde027a7877c8fe0194a1509480..16807d72a32b20b7c8069c254fcb43e8676e0932 100644 (file)
@@ -8,6 +8,7 @@ struct auth_penalty *auth_penalty;
 time_t process_start_time;
 bool worker, worker_restart_request;
 static struct passdb_module *mock_passdb_mod = NULL;
+static pool_t mock_pool;
 
 void auth_module_load(const char *names ATTR_UNUSED)
 {
@@ -52,11 +53,13 @@ static struct auth_passdb_settings set = {
        .auth_verbose = "default"
 };
 
-static void passdb_mock_mod_init(void)
+void passdb_mock_mod_init(void)
 {
        if (mock_passdb_mod != NULL)
                return;
 
+       mock_pool = pool_allocfree_create("auth mock");
+
        passdb_register_module(&mock_interface);
 
        struct auth_passdb_settings set = {
@@ -78,12 +81,19 @@ static void passdb_mock_mod_init(void)
                .master = FALSE,
                .auth_verbose = "default"
        };
-       mock_passdb_mod = passdb_preinit(default_pool, &set);
+       mock_passdb_mod = passdb_preinit(mock_pool, &set);
+       passdb_init(mock_passdb_mod);
+}
+
+void passdb_mock_mod_deinit(void)
+{
+       passdb_deinit(mock_passdb_mod);
+       passdb_unregister_module(&mock_interface);
+       pool_unref(&mock_pool);
 }
 
 struct auth_passdb *passdb_mock(void)
 {
-       passdb_mock_mod_init();
        struct auth_passdb *ret = i_new(struct auth_passdb, 1);
        ret->set = &set;
        ret->passdb = mock_passdb_mod;