]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
auth: Add test for lua password verify
authorAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 17 Apr 2018 07:55:53 +0000 (10:55 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 28 May 2018 07:07:18 +0000 (10:07 +0300)
src/auth/test-lua.c
src/auth/test-main.c

index 0b8fc85fbb9edc72e213face89801e0eca32ed93..ab5b4f032bbe41cbea9859559a24ca93b25c5388 100644 (file)
@@ -8,7 +8,45 @@
 #include "auth-request.h"
 #include "db-lua.h"
 
-void test_db_lua(void)
+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();
+        req->debug = TRUE;
+        req->user = "testuser";
+
+        static const char *luascript =
+"function auth_password_verify(req, pass)\n"
+"  req:log_debug(\"user \" .. req.user)\n"
+"  if req:password_verify(\"{SHA256-CRYPT}$5$XtUywQCSjW0zAJgE$YjuPKQnsLuH4iE9kranZyy1lbil5IrRUfs7X6EyJyG1\", pass) then\n"
+"      return dovecot.auth.PASSDB_RESULT_OK, {}\n"
+"  end\n"
+"end\n";
+        const char *error = NULL;
+        struct dlua_script *script = NULL;
+
+        test_begin("auth db lua passdb_verify");
+
+        test_assert(dlua_script_create_string(luascript, &script, &error) == 0);
+        test_assert(auth_lua_script_init(script, &error) == 0);
+        if (script != NULL) {
+               test_assert(auth_lua_call_password_verify(script, req, "password", &error) == 1);
+               if (error != NULL)
+                       i_debug("error = %s", error);
+        }
+        dlua_script_unref(&script);
+        i_free(req->passdb);
+        auth_request_unref(&req);
+
+        test_end();
+}
+
+static void test_db_lua_auth_lookup(void)
 {
        const char *scheme,*pass;
        struct auth_settings set;
@@ -29,7 +67,7 @@ void test_db_lua(void)
        const char *error = NULL;
        struct dlua_script *script = NULL;
 
-       test_begin("auth db lua");
+       test_begin("auth db lua passdb_lookup");
 
        test_assert(dlua_script_create_string(luascript, &script, &error) == 0);
        test_assert(auth_lua_script_init(script, &error) == 0);
@@ -42,4 +80,10 @@ void test_db_lua(void)
 
        test_end();
 }
+
+void test_db_lua(void) {
+       test_db_lua_auth_lookup();
+       test_db_lua_auth_verify();
+}
+
 #endif
index 72700d4d6ae3f398f57daf6a8fd9e9050dd908bd..2275d19764c5fc699f190cf0635d30dd0fed7cc7 100644 (file)
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "test-common.h"
 #include "test-auth.h"
+#include "password-scheme.h"
 
 int main(int argc, const char *argv[])
 {
@@ -17,6 +18,8 @@ int main(int argc, const char *argv[])
                { NULL, NULL }
        };
 
+       password_schemes_init();
+
        if (argc > 2 && strcasecmp(argv[1], "--match") == 0)
                match = argv[2];