Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Step:FrontRunner
dovecot23.17734
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 dovecot23.17734
From ae7c2082d6b07d61e251b1dfad9db0a0661d7435 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 | 99 +++++++++++++++++++++++++++++++++++ 4 files changed, 124 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 0e4c2ad1f0..0a45fd3926 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 \ @@ -86,7 +87,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 = \ @@ -110,3 +114,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 809c811d67..ccd2837814 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 mail_user *user = client->user; struct stat peer_st; diff --git a/src/imap/imap-client.h b/src/imap/imap-client.h index f2ffe0d7c9..150ad5d1b8 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -343,6 +343,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 0000000000..ee4a0f008c --- /dev/null +++ b/src/imap/test-imap-client-hibernate.c @@ -0,0 +1,99 @@ +/* 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, + .conn = { + .local_ip = t_new(struct ip_addr, 1), + .remote_ip = t_new(struct ip_addr, 1), + }, + .username = EVILSTR"testuser", + .session_id = EVILSTR"session", + .session_create_time = 1234567, + .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), + .command_queue = &queue, + }; + test_begin("imap client hibernate"); + test_assert(net_addr2ip("127.0.0.1", mail_user.conn.local_ip) == 0); + test_assert(net_addr2ip("127.0.0.2", mail_user.conn.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