Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Alexander_Naumov:SLE-12:Update
dovecot22
0002-imap-Add-unit-test-for-imap-client-hiberna...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0002-imap-Add-unit-test-for-imap-client-hibernate.patch of Package dovecot22
From 0383075a83547e0321f1477115134f131f6b2463 Mon Sep 17 00:00:00 2001 From: Timo Sirainen <timo.sirainen@open-xchange.com> Date: Mon, 24 Aug 2020 19:12:21 +0300 Subject: [PATCH 2/2] imap: Add unit test for imap-client-hibernate --- src/imap/Makefile.am | 22 +++++++- src/imap/imap-client-hibernate.c | 4 +- src/imap/imap-client.h | 3 ++ src/imap/test-imap-client-hibernate.c | 97 +++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 src/imap/test-imap-client-hibernate.c diff --git a/src/imap/Makefile.am b/src/imap/Makefile.am index 94294896e..a6897a8e6 100644 --- a/src/imap/Makefile.am +++ b/src/imap/Makefile.am @@ -4,6 +4,7 @@ pkglibexec_PROGRAMS = imap AM_CPPFLAGS = \ -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-test \ -I$(top_srcdir)/src/lib-settings \ -I$(top_srcdir)/src/lib-dict \ -I$(top_srcdir)/src/lib-master \ @@ -67,7 +68,7 @@ cmds = \ cmd-x-cancel.c \ cmd-x-state.c -imap_SOURCES = \ +common_sources = \ $(cmds) \ imap-client.c \ imap-client-hibernate.c \ @@ -85,7 +86,10 @@ imap_SOURCES = \ imap-status.c \ imap-state.c \ imap-sync.c \ - mail-storage-callbacks.c \ + mail-storage-callbacks.c + +imap_SOURCES = \ + $(common_sources) \ main.c headers = \ @@ -108,3 +112,17 @@ headers = \ pkginc_libdir=$(pkgincludedir) pkginc_lib_HEADERS = $(headers) + +test_programs = \ + test-imap-client-hibernate +noinst_PROGRAMS = $(test_programs) + +test_imap_client_hibernate_SOURCES = \ + test-imap-client-hibernate.c $(common_sources) +test_imap_client_hibernate_LDADD = $(imap_LDADD) +test_imap_client_hibernate_DEPENDENCIES = $(imap_DEPENDENCIES) + +check-local: + for bin in $(test_programs); do \ + if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \ + done diff --git a/src/imap/imap-client-hibernate.c b/src/imap/imap-client-hibernate.c index 7aefedd55..672c34e83 100644 --- a/src/imap/imap-client-hibernate.c +++ b/src/imap/imap-client-hibernate.c @@ -40,8 +40,8 @@ static int imap_hibernate_handshake(int fd, const char *path) return -1; } -static void imap_hibernate_write_cmd(struct client *client, string_t *cmd, - const buffer_t *state, int fd_notify) +void imap_hibernate_write_cmd(struct client *client, string_t *cmd, + const buffer_t *state, int fd_notify) { struct stat peer_st; const char *tag; diff --git a/src/imap/imap-client.h b/src/imap/imap-client.h index 229d1d52d..aca28d8c2 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -320,6 +320,9 @@ void client_continue_pending_input(struct client *client); void client_add_missing_io(struct client *client); const char *client_stats(struct client *client); +void imap_hibernate_write_cmd(struct client *client, string_t *cmd, + const buffer_t *state, int fd_notify); + void client_input(struct client *client); bool client_handle_input(struct client *client); int client_output(struct client *client); diff --git a/src/imap/test-imap-client-hibernate.c b/src/imap/test-imap-client-hibernate.c new file mode 100644 index 000000000..10944f362 --- /dev/null +++ b/src/imap/test-imap-client-hibernate.c @@ -0,0 +1,97 @@ +/* Copyright (c) 2020 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "test-common.h" +#include "istream.h" +#include "ostream.h" +#include "str.h" +#include "strescape.h" +#include "mail-storage-private.h" +#include "imap-common.h" +#include "imap-client.h" + +#define EVILSTR "\t\r\n\001" +#define EVILSTR_ESCAPED "\001t\001r\001n\0011" + +imap_client_created_func_t *hook_client_created = NULL; +bool imap_debug = FALSE; + +void imap_refresh_proctitle(void) { } +int client_create_from_input(const struct mail_storage_service_input *input ATTR_UNUSED, + int fd_in ATTR_UNUSED, int fd_out ATTR_UNUSED, + struct client **client_r ATTR_UNUSED, + const char **error_r ATTR_UNUSED) { return -1; } + +static void test_imap_client_hibernate(void) +{ + buffer_t *state = buffer_create_dynamic(pool_datastack_create(), 0); + struct mail_user_settings mail_set = { + .mail_log_prefix = EVILSTR"%u", + }; + struct mail_user mail_user = { + .set = &mail_set, + .username = EVILSTR"testuser", + .session_create_time = 1234567, + .local_ip = t_new(struct ip_addr, 1), + .remote_ip = t_new(struct ip_addr, 1), + .pool = pool_datastack_create(), + .uid = 4000, + .gid = 4001, + }; + struct imap_settings imap_set = { + .imap_idle_notify_interval = 120, + .imap_logout_format = "", + }; + struct client_command_context queue = { + .tag = EVILSTR"tag", + .name = "IDLE", + }; + struct client client = { + .user = &mail_user, + .set = &imap_set, + .fd_in = dev_null_fd, + .input = i_stream_create_from_data("", 0), + .output = o_stream_create_buffer(state), + .session_id = EVILSTR"session", + .command_queue = &queue, + }; + test_begin("imap client hibernate"); + test_assert(net_addr2ip("127.0.0.1", mail_user.local_ip) == 0); + test_assert(net_addr2ip("127.0.0.2", mail_user.remote_ip) == 0); + + string_t *cmd = t_str_new(256); + imap_hibernate_write_cmd(&client, cmd, state, -1); + + const char *const *args = t_strsplit(str_c(cmd), "\t"); + unsigned int i = 0; + test_assert_strcmp(args[i++], EVILSTR_ESCAPED"testuser"); + test_assert_strcmp(args[i++], EVILSTR_ESCAPED"%u"); + test_assert_strcmp(args[i++], "idle_notify_interval=120"); + test_assert(strncmp(args[i++], "peer_dev_major=", 15) == 0); + test_assert(strncmp(args[i++], "peer_dev_minor=", 15) == 0); + test_assert(strncmp(args[i++], "peer_ino=", 9) == 0); + test_assert_strcmp(args[i++], "session="EVILSTR_ESCAPED"session"); + test_assert_strcmp(args[i++], "session_created=1234567"); + test_assert_strcmp(args[i++], "lip=127.0.0.1"); + test_assert_strcmp(args[i++], "rip=127.0.0.2"); + test_assert_strcmp(args[i++], "uid=4000"); + test_assert_strcmp(args[i++], "gid=4001"); + test_assert_strcmp(args[i++], "tag="EVILSTR_ESCAPED"tag"); + test_assert(strncmp(args[i++], "stats=", 6) == 0); + test_assert_strcmp(args[i++], "idle-cmd"); + test_assert(strncmp(args[i++], "state=", 6) == 0); + test_assert(args[i] == NULL); + + i_stream_destroy(&client.input); + o_stream_destroy(&client.output); + test_end(); +} + +int main(void) +{ + static void (*test_functions[])(void) = { + test_imap_client_hibernate, + NULL + }; + return test_run(test_functions); +} -- 2.11.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor