/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
#include "test-auth.h"
#include "str.h"
#include "auth.h"
#include "passdb.h"
#include "userdb.h"
#include "auth-request.h"
.id = 40
};
.id = 41
};
.passdb = &test_passdb
};
.userdb = &test_userdb
};
.user = "-user@+domain1@+domain2",
.service = "-service",
.client_pid = 54321,
.mech_password = "-password",
.mech_name = "-mech",
.local_port = 21,
.remote_port = 210,
.requested_login_user = "-loginuser@+logindomain1@+logindomain2",
.session_id = "-session",
.real_local_port = 200,
.real_remote_port = 201,
.master_user = "-masteruser@-masterdomain1@-masterdomain2",
.session_pid = 5000,
.original_username = "-origuser@-origdomain1@-origdomain2",
.passdb = &test_auth_passdb,
};
static const char *
{
char *dest;
unsigned int i;
for (i = 0; dest[i] != '\0'; i++) {
if (dest[i] == '-')
dest[i] = '+';
}
return dest;
}
{
const char *error;
str_truncate(str, 0);
}
static void test_auth_request_var_expand_shortlong(void)
{
static const char *test_input_short =
"%u\n%n\n%d\n%s\n%h\n%l\n%r\n%p\n%w\n%m\n%c\n%a\n%b\n%k\n";
static const char *test_input_long =
"%{user}\n%{username}\n%{domain}\n%{service}\n%{home}\n"
"%{lip}\n%{rip}\n%{pid}\n%{password}\n%{mech}\n%{secured}\n"
"%{lport}\n%{rport}\n%{cert}\n";
static const char *test_output =
/* %{home} is intentionally always expanding to empty */
"+user@+domain1@+domain2\n+user\n+domain1@+domain2\n+service\n\n"
"7.91.205.21\n73.150.2.210\n54321\n+password\n+mech\nsecured\n"
"21\n210\nvalid\n";
const char *error;
test_begin("auth request var expand short and long");
str_truncate(str, 0);
/* test with empty input that it won't crash */
test_end();
}
static void test_auth_request_var_expand_flags(void)
{
const char *error;
test_begin("auth request var expand flags");
&error) == 1);
str_truncate(str, 0);
&error) == 1);
test_end();
}
static void test_auth_request_var_expand_long(void)
{
static const char *test_input =
"%{login_user}\n%{login_username}\n%{login_domain}\n%{session}\n"
"%{real_lip}\n%{real_rip}\n%{real_lport}\n%{real_rport}\n"
"%{master_user}\n%{session_pid}\n"
"%{orig_user}\n%{orig_username}\n%{orig_domain}\n";
static const char *test_output =
"+loginuser@+logindomain1@+logindomain2\n+loginuser\n+logindomain1@+logindomain2\n+session\n"
"13.81.174.20\n13.81.174.21\n200\n201\n"
"+masteruser@+masterdomain1@+masterdomain2\n5000\n"
"+origuser@+origdomain1@+origdomain2\n+origuser\n+origdomain1@+origdomain2\n";
const char *error;
test_begin("auth request var expand long-only");
&error) == 1);
test_end();
}
static void test_auth_request_var_expand_usernames(void)
{
static const struct {
} tests[] = {
{ "-foo", "+foo\n\n\n\n+foo" },
{ "-foo@-domain", "+foo\n+domain\n+domain\n+domain\n+foo@+domain" },
{ "-foo@-domain1@-domain2", "+foo\n+domain1@+domain2\n+domain1\n+domain2\n+foo@+domain1@+domain2" }
};
static const char *test_input =
"%{username}\n%{domain}\n%{domain_first}\n%{domain_last}\n%{user}";
const char *error;
unsigned int i;
test_begin("auth request var expand usernames");
for (i = 0; i < N_ELEMENTS(tests); i++) {
str_truncate(str, 0);
&error) == 1);
}
test_end();
}
static void test_auth_request_var_expand_funcs(void)
{
test_begin("auth request var expand funcs");
"%{passdb:pkey1}\n%{passdb:pkey1:default1}\n"
"%{passdb:pkey2}\n%{passdb:pkey2:default2}\n"
"%{passdb:pkey3}\n%{passdb:pkey3:default3}\n"
"%{passdb:ukey1}\n%{passdb:ukey1:default4}\n",
"%{userdb:ukey1}\n%{userdb:ukey1:default1}\n"
"%{userdb:ukey2}\n%{userdb:ukey2:default2}\n"
"%{userdb:ukey3}\n%{userdb:ukey3:default3}\n"
"%{userdb:pkey1}\n%{userdb:pkey1:default4}\n",
pool_unref(&pool);
test_end();
}
void test_auth_request_var_expand(void)
{
}