AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib \
- -I$(top_srcdir)/src/lib-master
+ -I$(top_srcdir)/src/lib-master \
+ -I$(top_srcdir)/src/lib-test
libauth_la_SOURCES = \
auth-client.c \
pkginc_libdir=$(pkgincludedir)
pkginc_lib_HEADERS = $(headers)
+
+test_programs = \
+ test-auth-master
+
+noinst_PROGRAMS = $(test_programs)
+
+test_libs = \
+ $(noinst_LTLIBRARIES) \
+ ../lib-test/libtest.la \
+ ../lib/liblib.la \
+ $(MODULE_LIBS)
+
+test_deps = \
+ $(noinst_LTLIBRARIES) \
+ ../lib-test/libtest.la \
+ ../lib/liblib.la
+
+test_auth_master_SOURCES = test-auth-master.c
+test_auth_master_LDADD = $(test_libs)
+test_auth_master_DEPENDENCIES = $(test_deps)
+
+check-local:
+ for bin in $(test_programs); do \
+ if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \
+ done
--- /dev/null
+/* Copyright (c) 2019 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "auth-master.h"
+#include "net.h"
+#include "test-common.h"
+#include "str.h"
+
+static void test_auth_user_info_export(void)
+{
+ string_t *str;
+ struct auth_user_info info;
+
+ i_zero(&info);
+
+ test_begin("auth_user_info_export()");
+
+ /* Setup info for auth_user_info_export call where the
+ * resulting auth request string should contain all
+ * real_ variables. */
+ net_addr2ip("192.168.1.1", &info.local_ip);
+ net_addr2ip("192.23.42.9", &info.real_local_ip);
+ net_addr2ip("10.42.3.223", &info.remote_ip);
+ net_addr2ip("192.168.1.2", &info.real_remote_ip);
+ info.local_port = 57035;
+ info.remote_port = 53075;
+ info.real_remote_port = 64385;
+ info.real_local_port = 57391;
+
+ str = t_str_new(128);
+ auth_user_info_export(str, &info);
+
+ test_assert(strstr(str_c(str), "real_rip=192.168.1.2") != NULL);
+ test_assert(strstr(str_c(str), "real_lip=192.23.42.9") != NULL);
+ test_assert(strstr(str_c(str), "rip=10.42.3.223") != NULL);
+ test_assert(strstr(str_c(str), "lip=192.168.1.1") != NULL);
+ test_assert(strstr(str_c(str), "real_rport=64385") != NULL);
+ test_assert(strstr(str_c(str), "rport=53075") != NULL);
+ test_assert(strstr(str_c(str), "real_lport=57391") != NULL);
+ test_assert(strstr(str_c(str), "lport=57035") != NULL);
+
+ /* Setup info for auth_user_info_export call where the
+ * resulting auth request string should not contain any
+ * real_ variables. */
+ net_addr2ip("10.42.3.223", &info.real_remote_ip);
+ net_addr2ip("192.168.1.1", &info.real_local_ip);
+ info.real_remote_port = 53075;
+ info.real_local_port = 57035;
+
+ str_truncate(str, 0);
+ auth_user_info_export(str, &info);
+
+ test_assert(strstr(str_c(str), "rip=10.42.3.223") != NULL);
+ test_assert(strstr(str_c(str), "lip=192.168.1.1") != NULL);
+ test_assert(strstr(str_c(str), "lport=57035") != NULL);
+ test_assert(strstr(str_c(str), "rport=53075") != NULL);
+ /* The following fields should not be part of the string as
+ * they are matching with their non-real counterparts */
+ test_assert(strstr(str_c(str), "real_lport") == NULL);
+ test_assert(strstr(str_c(str), "real_rport") == NULL);
+ test_assert(strstr(str_c(str), "real_rip") == NULL);
+ test_assert(strstr(str_c(str), "real_lip") == NULL);
+
+ test_end();
+}
+
+int main(void)
+{
+ static void (*const test_functions[])(void) = {
+ test_auth_user_info_export,
+ NULL
+ };
+ return test_run(test_functions);
+}