diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 09:51:24 +0000 |
commit | f7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch) | |
tree | a3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/auth/test-auth-cache.c | |
parent | Initial commit. (diff) | |
download | dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip |
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/auth/test-auth-cache.c')
-rw-r--r-- | src/auth/test-auth-cache.c | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/auth/test-auth-cache.c b/src/auth/test-auth-cache.c new file mode 100644 index 0000000..ea71b1b --- /dev/null +++ b/src/auth/test-auth-cache.c @@ -0,0 +1,82 @@ +/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "str.h" +#include "auth-request.h" +#include "auth-cache.h" +#include "test-common.h" + +const struct var_expand_table +auth_request_var_expand_static_tab[AUTH_REQUEST_VAR_TAB_COUNT + 1] = { + /* these 3 must be in this order */ + { 'u', NULL, "user" }, + { 'n', NULL, "username" }, + { 'd', NULL, "domain" }, + + { 'a', NULL, NULL }, + { '\0', NULL, "longb" }, + { 'c', NULL, "longc" }, + { '\0', NULL, NULL } +}; + +struct var_expand_table * +auth_request_get_var_expand_table_full(const struct auth_request *auth_request ATTR_UNUSED, + const char *username ATTR_UNUSED, + auth_request_escape_func_t *escape_func ATTR_UNUSED, + unsigned int *count ATTR_UNUSED) +{ + i_unreached(); +} + +int auth_request_var_expand_with_table(string_t *dest, const char *str, + const struct auth_request *auth_request ATTR_UNUSED, + const struct var_expand_table *table ATTR_UNUSED, + auth_request_escape_func_t *escape_func ATTR_UNUSED, + const char **error_r ATTR_UNUSED) +{ + return var_expand(dest, str, auth_request_var_expand_static_tab, error_r); +} + +static void test_auth_cache_parse_key(void) +{ + static const struct { + const char *in, *out; + } tests[] = { + { "%n@%d", "%u" }, + { "%{username}@%{domain}", "%u" }, + { "%n%d%u", "%u" }, + { "%n", "%n" }, + { "%d", "%d" }, + { "%a%b%u", "%u\t%a\t%b" }, + + { "foo%5.5Mabar", "%a" }, + { "foo%5.5M{longb}bar", "%{longb}" }, + { "foo%5.5Mcbar", "%c" }, + { "foo%5.5M{longc}bar", "%c" }, + { "%a%b", "%a\t%b" }, + { "%a%{longb}%a", "%a\t%{longb}" }, + { "%{longc}%c", "%c" }, + { "%c%a%{longc}%c", "%a\t%c" }, + { "%a%{env:foo}%{env:foo}%a", "%a\t%{env:foo}\t%{env:foo}" } + }; + const char *cache_key; + unsigned int i; + + test_begin("auth cache parse key"); + + for (i = 0; i < N_ELEMENTS(tests); i++) { + cache_key = auth_cache_parse_key(pool_datastack_create(), + tests[i].in); + test_assert(strcmp(cache_key, tests[i].out) == 0); + } + test_end(); +} + +int main(void) +{ + static void (*const test_functions[])(void) = { + test_auth_cache_parse_key, + NULL + }; + return test_run(test_functions); +} |