From a219cd3c45aa2545a7a641acb277acb5e8be87f9 Mon Sep 17 00:00:00 2001 From: Sam Varshavchik Date: Sat, 5 Mar 2022 23:32:10 -0500 Subject: Add additional tests. --- imap/.gitignore | 1 + imap/Makefile.am | 19 ++++++-- imap/pop3dserver.c | 22 +++++++-- imap/pop3testsuite | 130 +++++++++++++++++++++++++++++++++++++++++++++++++ imap/pop3testsuite.txt | 115 +++++++++++++++++++++++++++++++++++++++++++ imap/testpop3dserver.c | 6 +++ 6 files changed, 285 insertions(+), 8 deletions(-) create mode 100644 imap/pop3testsuite create mode 100644 imap/pop3testsuite.txt create mode 100644 imap/testpop3dserver.c diff --git a/imap/.gitignore b/imap/.gitignore index 663429e..6b4c6f5 100644 --- a/imap/.gitignore +++ b/imap/.gitignore @@ -49,5 +49,6 @@ /pop3d.dist /pop3d.dist.in /pop3d.pam +/pop3d.testmock /pop3login /testsuitefix.pl diff --git a/imap/Makefile.am b/imap/Makefile.am index 5aade68..5f91b41 100644 --- a/imap/Makefile.am +++ b/imap/Makefile.am @@ -23,10 +23,12 @@ EXTRA_DIST=testsuite testsuite.txt smaptestsuite smaptestsuite.txt \ mkpop3dcert.html.in mkpop3dcert.8.in \ courierpop3d.html.in courierpop3d.8.in \ README.proxy README.proxy.html \ - imapd.cnf.gnutls pop3d.cnf.gnutls + imapd.cnf.gnutls pop3d.cnf.gnutls \ + pop3testsuite pop3testsuite.txt noinst_SCRIPTS=mkimapdcert mkpop3dcert mkdhparams -noinst_PROGRAMS=imaplogin imapd imapd.testmockpurge pop3login pop3d +noinst_PROGRAMS=imaplogin imapd imapd.testmockpurge pop3login pop3d \ + pop3d.testmock noinst_DATA=imapd.8 imapd.html imapd.cnf pop3d.cnf \ makeimapaccess.html makeimapaccess.8 \ @@ -99,6 +101,10 @@ pop3d_SOURCES=pop3dserver.c pop3dcapa.c pop3d_DEPENDENCIES=libpop3d.la pop3d_LDADD=libpop3d.la @LDAUTH@ -lcourierauth -lcourier-unicode +pop3d_testmock_SOURCES=testpop3dserver.c pop3dcapa.c +pop3d_testmock_DEPENDENCIES=libpop3d.la +pop3d_testmock_LDADD=libpop3d.la @LDAUTH@ -lcourierauth -lcourier-unicode + HTML2TXT=links -dump -no-numbering README: README.html @@ -231,9 +237,13 @@ check-am: rm -f confmdmemleak; \ IMAPINVOKE='@SHELL@ $(srcdir)/testsuitevalgrind ./imapd'; export IMAPINVOKE; \ export PERL=@PERL@; @SHELL@ -x $(srcdir)/smaptestsuite 2>&1 | tee confmderror.txt; test -f confmdmemleak || exit 0; exit 1 - rm -f confmderror.txt rm -rf confmdtest + @SHELL@ $(srcdir)/pop3testsuite | sed 's/^--=_.*/--mimeboundary/;s/ENOMEM.*/ENOMEM/;s/boundary=.*/boundary=/' | cmp -s - $(srcdir)/pop3testsuite.txt + rm -f confmdmemleak; \ + POP3INVOKE='@SHELL@ $(srcdir)/testsuitevalgrind ./pop3d.testmock' \ + @SHELL@ -x $(srcdir)/pop3testsuite; \ + test -f confmdmemleak || exit 0; exit 1 testsuite-imap: @chmod +x testsuitefix.pl @@ -242,3 +252,6 @@ testsuite-imap: testsuite-smap: @chmod +x testsuitefix.pl @LC_ALL=C; export LC_ALL; test "@smap@" = "yes" || exit 0; export PERL=@PERL@; @SHELL@ $(srcdir)/smaptestsuite | ./testsuitefix.pl | sort + +testsuite-pop3: + @LC_ALL=C @SHELL@ pop3testsuite | sed 's/^--=_.*/--mimeboundary/;s/ENOMEM.*/ENOMEM/;s/boundary=.*/boundary=/' diff --git a/imap/pop3dserver.c b/imap/pop3dserver.c index 5e938ad..82a1ec0 100644 --- a/imap/pop3dserver.c +++ b/imap/pop3dserver.c @@ -60,6 +60,14 @@ #define POP3DLIST "courierpop3dsizelist" #define LISTVERSION 3 +#ifndef RUNTIME_START +#define RUNTIME_START time(NULL) +#endif + +#ifndef RUNTIME_CUR +#define RUNTIME_CUR time(NULL) +#endif + extern void pop3dcapa(); extern void pop3dlang(const char *); @@ -190,7 +198,7 @@ static struct msglist **readpop3dlist(unsigned long *uid) int vernum=0; unsigned long size; - uidv=time(NULL); + uidv=RUNTIME_CUR; if (fp == NULL || fgets(linebuf, sizeof(linebuf)-1, fp) == NULL || @@ -299,6 +307,9 @@ static int savepop3dlist(struct msglist **a, size_t cnt, struct maildir_tmpcreate_info createInfo; +#ifdef SAVEHOOK + SAVEHOOK(); +#endif maildir_tmpcreate_init(&createInfo); createInfo.uniq="pop3"; @@ -488,7 +499,9 @@ static void sortmsgs() } if (prev_list[n]) + { savesizes=1; + } for (i=0; prev_list[i]; i++) { @@ -728,7 +741,7 @@ static void do_retr(unsigned i, unsigned *lptr) if (msglist_a[i]->isutf8 && !utf8_enabled) { - sprintf(boundary, "=_%d-%d", (int)getpid(), (int)time(NULL)); + sprintf(boundary, "=_%d-%d", (int)getpid(), (int)RUNTIME_CUR); sprintf(wrapheader, MIMEWRAPTXT, boundary, boundary, boundary, mime_message_type); @@ -910,7 +923,7 @@ static void acctout(const char *disc) libmail_str_size_t(top_count, num1); libmail_str_size_t(retr_count, num2); - libmail_str_time_t(time(NULL)-start_time, num3); + libmail_str_time_t(RUNTIME_CUR-start_time, num3); libmail_str_size_t(bytes_received_count, numAR); libmail_str_size_t(bytes_sent_count, numAS); @@ -1121,11 +1134,10 @@ char *n; int main(int argc, char **argv) { char *p; - #ifdef HAVE_SETVBUF_IOLBF setvbuf(stderr, NULL, _IOLBF, BUFSIZ); #endif - time(&start_time); + start_time=RUNTIME_START; if ((authaddr=getenv("AUTHADDR")) == NULL || *authaddr == 0) diff --git a/imap/pop3testsuite b/imap/pop3testsuite new file mode 100644 index 0000000..6ce6c1e --- /dev/null +++ b/imap/pop3testsuite @@ -0,0 +1,130 @@ +#!/bin/sh + +# Maintainer's sanity check + +OPTIONS="" +export OPTIONS +TZ=EST5EDT +export TZ + +echo '****************************' >&2 +echo '* Sanity check in progress *' >&2 +echo '****************************' >&2 +#test ! -d confmdtest || find confmdtest -exec chmod u+rwx {} \; +#test ! -d confmdtest2 || find confmdtest2 -exec chmod u+rwx {} \; +test ! -d confmdtest || chmod -R u+rwx confmdtest +rm -rf confmdtest +../maildir/maildirmake confmdtest || exit 1 + +if test "$POP3INVOKE" = "" +then + POP3INVOKE="./pop3d.testmock" +fi + +cat >confmdtest/new/msg1 <confmdtest/new/msg2 <confmdtest/new/msg3 <confmdtest/new/msg4 <confmdtest/new/msg5 <confmdtest/new/msg6 <confmdtest/new/msg7 < +Subject: Cannot display Unicode content +Mime-Version: 1.0 +Content-Type: multipart/mixed; boundary= + + + +--mimeboundary +Content-Type: text/plain + +This E-mail message was determined to be Unicode-formatted +but your E-mail reader does not support Unicode E-mail. + +Please use an E-mail reader that supports POP3 with UTF-8 +(see https://tools.ietf.org/html/rfc6856.html). + +This can also happen when the sender's E-mail program does not +correctly format the sent message. + +The original message is included as a separate attachment +so that it can be downloaded manually. + +--mimeboundary +Content-Type: message/global + +Subject: test 6 Привет +From: nobody@example.com + +Line 1 +Line 2 +Line 3 + +--mimeboundary +. ++OK UTF8 enabled ++OK octets follow. +Subject: test 6 Привет +From: nobody@example.com + +Line 1 +Line 2 +Line 3 +. diff --git a/imap/testpop3dserver.c b/imap/testpop3dserver.c new file mode 100644 index 0000000..5164854 --- /dev/null +++ b/imap/testpop3dserver.c @@ -0,0 +1,6 @@ +#define RUNTIME_START 100 +#define RUNTIME_CUR 200 + +#define SAVEHOOK() do { if (getenv("POP3DEBUGNOSAVE")) return -1; } while (0) + +#include "pop3dserver.c" -- cgit v1.2.3