From a5ab72d5edd72eba3485c790b42006d407e6f162 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 18 Jun 2021 23:49:25 +0200 Subject: [PATCH] test677: IMAP CONNECT_ONLY, custom command and then exit Adjusted ftpserver.pl to add support for the IMAP IDLE command Adjusted test 660 to sync with the fix --- tests/data/Makefile.inc | 2 +- tests/data/test660 | 1 - tests/data/test677 | 43 ++++++++++++++ tests/ftpserver.pl | 8 +++ tests/libtest/Makefile.inc | 6 +- tests/libtest/lib677.c | 117 +++++++++++++++++++++++++++++++++++++ 6 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 tests/data/test677 create mode 100644 tests/libtest/lib677.c diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 271e5348c..163696962 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -90,7 +90,7 @@ test635 test636 test637 test638 test639 test640 test641 test642 \ test643 test645 test646 test647 test648 test649 test650 test651 \ test652 test653 test654 test655 test656 test658 test659 test660 test661 \ test662 test663 test664 test665 test666 test667 test668 test669 \ -test670 test671 test672 test673 test674 test675 test676 test678 \ +test670 test671 test672 test673 test674 test675 test676 test677 test678 \ \ test700 test701 test702 test703 test704 test705 test706 test707 test708 \ test709 test710 test711 test712 test713 test714 test715 test716 test717 \ diff --git a/tests/data/test660 b/tests/data/test660 index 3b1964b90..b53d47bce 100644 --- a/tests/data/test660 +++ b/tests/data/test660 @@ -29,7 +29,6 @@ imap://%HOSTIP:%IMAPPORT/%TESTNUMBER A001 CAPABILITY -A002 LOGOUT diff --git a/tests/data/test677 b/tests/data/test677 new file mode 100644 index 000000000..e3d9041fd --- /dev/null +++ b/tests/data/test677 @@ -0,0 +1,43 @@ + + + +IMAP +CONNECT_ONLY + + + +# +# Server-side + + + + + +# +# Client-side + + +imap + + +IMAP with CONNECT_ONLY, custom command then exit + + +lib%TESTNUMBER + + + +imap://%HOSTIP:%IMAPPORT/677 + + + + +# +# Verify data after the test has been "shot" + + +A001 CAPABILITY +A1 IDLE + + + diff --git a/tests/ftpserver.pl b/tests/ftpserver.pl index 9040478ec..a3819508a 100755 --- a/tests/ftpserver.pl +++ b/tests/ftpserver.pl @@ -643,6 +643,7 @@ sub protocolsetup { 'STATUS' => \&STATUS_imap, 'STORE' => \&STORE_imap, 'UID' => \&UID_imap, + 'IDLE' => \&IDLE_imap, ); %displaytext = ( 'welcome' => join("", @@ -1587,6 +1588,13 @@ sub COPY_imap { return 0; } +sub IDLE_imap { + logmsg "IDLE received\n"; + + sendcontrol "+ entering idle mode\r\n"; + return 0; +} + sub UID_imap { my ($args) = @_; my ($command) = split(/ /, $args, 1); diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 60cd65320..c2d0a6e8e 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -48,7 +48,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \ lib599 \ lib643 lib645 lib650 lib651 lib652 lib653 lib654 lib655 lib658 \ lib659 lib661 lib666 lib667 lib668 \ - lib670 lib671 lib672 lib673 lib674 lib676 lib678 \ + lib670 lib671 lib672 lib673 lib674 lib676 lib677 lib678 \ lib1156 \ lib1500 lib1501 lib1502 lib1503 lib1504 lib1505 lib1506 lib1507 lib1508 \ lib1509 lib1510 lib1511 lib1512 lib1513 lib1514 lib1515 lib1517 \ @@ -406,6 +406,10 @@ lib676_SOURCES = lib676.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) lib676_LDADD = $(TESTUTIL_LIBS) lib676_CPPFLAGS = $(AM_CPPFLAGS) +lib677_SOURCES = lib677.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) $(MULTIBYTE) +lib677_LDADD = $(TESTUTIL_LIBS) +lib677_CPPFLAGS = $(AM_CPPFLAGS) + lib678_SOURCES = lib678.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) $(MULTIBYTE) lib678_LDADD = $(TESTUTIL_LIBS) lib678_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/tests/libtest/lib677.c b/tests/libtest/lib677.c new file mode 100644 index 000000000..48d5919fe --- /dev/null +++ b/tests/libtest/lib677.c @@ -0,0 +1,117 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2021, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#include "test.h" + +#include "testutil.h" +#include "warnless.h" +#include "memdebug.h" + +static const char cmd[] = "A1 IDLE\r\n"; +static char buf[1024]; + +int test(char *URL) +{ + CURLM *mcurl; + CURL *curl; + int mrun; + curl_socket_t sock = CURL_SOCKET_BAD; + time_t start = time(NULL); + int state = 0; + ssize_t pos = 0; + + curl_global_init(CURL_GLOBAL_DEFAULT); + mcurl = curl_multi_init(); + if(!mcurl) + return 1; + curl = curl_easy_init(); + if(!curl) + goto fail; + + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(curl, CURLOPT_URL, URL); + curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); + curl_multi_add_handle(mcurl, curl); + + while(time(NULL) - start < 5) { + struct curl_waitfd waitfd; + + curl_multi_perform(mcurl, &mrun); + for(;;) { + int i; + struct CURLMsg *m = curl_multi_info_read(mcurl, &i); + + if(!m) + break; + if(m->msg == CURLMSG_DONE && m->easy_handle == curl) { + curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sock); + if(sock == CURL_SOCKET_BAD) + return 3; + printf("Connected fine, extracted socket. Moving on\n"); + } + } + + if(sock != CURL_SOCKET_BAD) { + waitfd.events = state ? CURL_WAIT_POLLIN : CURL_WAIT_POLLOUT; + waitfd.revents = 0; + curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sock); + waitfd.fd = sock; + } + curl_multi_wait(mcurl, &waitfd, sock == CURL_SOCKET_BAD ? 0 : 1, 500, + &mrun); + if((sock != CURL_SOCKET_BAD) && (waitfd.revents & waitfd.events)) { + size_t len = 0; + + if(!state) { + curl_easy_send(curl, cmd + pos, sizeof(cmd) - 1 - pos, &len); + if(len > 0) + pos += len; + else + pos = 0; + if(pos == sizeof(cmd) - 1) { + state++; + pos = 0; + } + } + else if(pos < (ssize_t)sizeof(buf)) { + curl_easy_recv(curl, buf + pos, sizeof(buf) - pos, &len); + if(len > 0) + pos += len; + } + if(len <= 0) + sock = CURL_SOCKET_BAD; + } + } + + if(state) { + fwrite(buf, pos, 1, stdout); + putchar('\n'); + } + + curl_multi_remove_handle(mcurl, curl); + fail: + curl_easy_cleanup(curl); + curl_multi_cleanup(mcurl); + + curl_global_cleanup(); + return 0; +} +