Added test case 555, a variation of 547 but using multi interface instead of
authorDaniel Stenberg <daniel@haxx.se>
Wed, 16 Apr 2008 21:11:46 +0000 (21:11 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 16 Apr 2008 21:11:46 +0000 (21:11 +0000)
easy. This was reported not working by Penugonda Chenna Reddy in
http://curl.haxx.se/mail/lib-2008-04/0046.html but I fail to repeat that
problem.

tests/data/Makefile.am
tests/data/test555 [new file with mode: 0644]
tests/libtest/Makefile.am
tests/libtest/lib555.c [new file with mode: 0644]

index ad2e63a..b3fe735 100644 (file)
@@ -50,7 +50,7 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46           \
  test551 test552 test1016 test1017 test1018 test1019 test1020 test553      \
  test1021 test1022 test1023 test309 test616 test617 test618 test619        \
  test620 test621 test622 test623 test624 test625 test626 test627 test554   \
- test1024 test1025
+ test1024 test1025 test555
 
 filecheck:
        @mkdir test-place; \
diff --git a/tests/data/test555 b/tests/data/test555
new file mode 100644 (file)
index 0000000..148a01a
--- /dev/null
@@ -0,0 +1,135 @@
+# NOTE: this test case is a duplicate of 547 but the tool is built to use the
+# multi interface instead of easy, but that shouldn't be noticable at all in
+# this file!
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP POST
+POST callback
+HTTP proxy NTLM auth
+multi interface
+</keywords>
+</info>
+# Server-side
+<reply>
+
+<data>
+HTTP/1.1 407 Authorization Required swsclose\r
+Server: Apache/1.3.27 (Darwin) PHP/4.1.2\r
+Proxy-Authenticate: Blackmagic realm="gimme all yer s3cr3ts"\r
+Proxy-Authenticate: Basic realm="gimme all yer s3cr3ts"\r
+Proxy-Authenticate: NTLM\r
+Content-Type: text/html; charset=iso-8859-1\r
+Connection: close\r
+\r
+This is not the real page
+</data>
+
+# this is returned first since we get no proxy-auth
+<data1001>
+HTTP/1.1 407 Authorization Required to proxy me my dear\r
+Proxy-Authenticate: NTLM TlRMTVNTUAACAAAAAgACADAAAAAGgoEAc51AYVDgyNcAAAAAAAAAAG4AbgAyAAAAQ0MCAAQAQwBDAAEAEgBFAEwASQBTAEEAQgBFAFQASAAEABgAYwBjAC4AaQBjAGUAZABlAHYALgBuAHUAAwAsAGUAbABpAHMAYQBiAGUAdABoAC4AYwBjAC4AaQBjAGUAZABlAHYALgBuAHUAAAAAAA==\r
+Content-Length: 34\r
+\r
+Hey you, authenticate or go away!
+</data1001>
+
+# This is supposed to be returned when the server gets the second
+# Authorization: NTLM line passed-in from the client
+<data1002>
+HTTP/1.1 200 Things are fine in proxy land swsclose\r
+Server: Microsoft-IIS/5.0\r
+Content-Type: text/html; charset=iso-8859-1\r
+Content-Length: 42\r
+\r
+Contents of that page you requested, sir.
+</data1002>
+
+<datacheck>
+HTTP/1.1 407 Authorization Required swsclose\r
+Server: Apache/1.3.27 (Darwin) PHP/4.1.2\r
+Proxy-Authenticate: Blackmagic realm="gimme all yer s3cr3ts"\r
+Proxy-Authenticate: Basic realm="gimme all yer s3cr3ts"\r
+Proxy-Authenticate: NTLM\r
+Content-Type: text/html; charset=iso-8859-1\r
+Connection: close\r
+\r
+HTTP/1.1 407 Authorization Required to proxy me my dear\r
+Proxy-Authenticate: NTLM TlRMTVNTUAACAAAAAgACADAAAAAGgoEAc51AYVDgyNcAAAAAAAAAAG4AbgAyAAAAQ0MCAAQAQwBDAAEAEgBFAEwASQBTAEEAQgBFAFQASAAEABgAYwBjAC4AaQBjAGUAZABlAHYALgBuAHUAAwAsAGUAbABpAHMAYQBiAGUAdABoAC4AYwBjAC4AaQBjAGUAZABlAHYALgBuAHUAAAAAAA==\r
+Content-Length: 34\r
+\r
+HTTP/1.1 200 Things are fine in proxy land swsclose\r
+Server: Microsoft-IIS/5.0\r
+Content-Type: text/html; charset=iso-8859-1\r
+Content-Length: 42\r
+\r
+Contents of that page you requested, sir.
+</datacheck>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+# tool to use
+<tool>
+lib555
+</tool>
+<features>
+NTLM
+</features>
+ <name>
+HTTP proxy auth NTLM with POST data from read callback multi-if
+ </name>
+ <command>
+http://test.remote.server.com/path/555 http://%HOSTIP:%HTTPPORT s1lly:pers0n
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent: curl/.*
+</strip>
+# We strip off a large chunk of the type-2 NTLM message since it depends on
+# the local host name and thus differs on different machines!
+<strippart>
+s/^(Proxy-Authorization: NTLM TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAAAAABwAAAABQAFAHAAAAA).*/$1/
+</strippart>
+<protocol>
+POST http://test.remote.server.com/path/555 HTTP/1.1\r
+User-Agent: curl/7.13.2-CVS (i686-pc-linux-gnu) libcurl/7.13.2-CVS OpenSSL/0.9.7e zlib/1.2.2 libidn/0.5.13\r
+Host: test.remote.server.com\r
+Pragma: no-cache\r
+Accept: */*\r
+Proxy-Connection: Keep-Alive\r
+Content-Length: 36\r
+Content-Type: application/x-www-form-urlencoded\r
+\r
+this is the blurb we want to upload
+POST http://test.remote.server.com/path/555 HTTP/1.1\r
+Proxy-Authorization: NTLM TlRMTVNTUAABAAAABoIIAAAAAAAAAAAAAAAAAAAAAAA=\r
+User-Agent: curl/7.13.2-CVS (i686-pc-linux-gnu) libcurl/7.13.2-CVS OpenSSL/0.9.7e zlib/1.2.2 libidn/0.5.13\r
+Host: test.remote.server.com\r
+Pragma: no-cache\r
+Accept: */*\r
+Proxy-Connection: Keep-Alive\r
+Content-Length: 0\r
+Content-Type: application/x-www-form-urlencoded\r
+\r
+POST http://test.remote.server.com/path/555 HTTP/1.1\r
+Proxy-Authorization: NTLM TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAAAAABwAAAABQAFAHAAAAA
+User-Agent: curl/7.13.2-CVS (i686-pc-linux-gnu) libcurl/7.13.2-CVS OpenSSL/0.9.7e zlib/1.2.2 libidn/0.5.13\r
+Host: test.remote.server.com\r
+Pragma: no-cache\r
+Accept: */*\r
+Proxy-Connection: Keep-Alive\r
+Content-Length: 36\r
+Content-Type: application/x-www-form-urlencoded\r
+\r
+this is the blurb we want to upload
+</protocol>
+</verify>
+</testcase>
index c6e6910..47864eb 100644 (file)
@@ -48,7 +48,7 @@ noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505 lib506    \
   lib507 lib508 lib510 lib511 lib512 lib513 lib514 lib515 lib516       \
   lib517 lib518 lib519 lib520 lib521 lib523 lib524 lib525 lib526 lib527        \
   lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542 lib543 \
-  lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554
+  lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555
 
 # Dependencies (may need to be overriden)
 LDADD = $(LIBDIR)/libcurl.la
@@ -144,6 +144,8 @@ lib548_CFLAGS = -DLIB548
 
 lib549_SOURCES = lib549.c $(SUPPORTFILES)
 
+lib555_SOURCES = lib555.c $(SUPPORTFILES) $(TESTUTIL)
+
 lib552_SOURCES = lib552.c $(SUPPORTFILES)
 
 lib553_SOURCES = lib553.c $(SUPPORTFILES)
diff --git a/tests/libtest/lib555.c b/tests/libtest/lib555.c
new file mode 100644 (file)
index 0000000..bfc29fc
--- /dev/null
@@ -0,0 +1,147 @@
+/*****************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ *
+ * This test case is supposed to be identical to 547 except that this uses the
+ * multi interface and 547 is easy interface.
+ *
+ * argv1 = URL
+ * argv2 = proxy
+ * argv3 = proxyuser:password
+ */
+
+#include "test.h"
+#include "testutil.h"
+
+#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+
+#define UPLOADTHIS "this is the blurb we want to upload\n"
+
+static size_t readcallback(void  *ptr,
+                           size_t size,
+                           size_t nmemb,
+                           void *clientp)
+{
+  int *counter = (int *)clientp;
+
+  if(*counter) {
+    /* only do this once and then require a clearing of this */
+    fprintf(stderr, "READ ALREADY DONE!\n");
+    return 0;
+  }
+  (*counter)++; /* bump */
+
+  if(size * nmemb > strlen(UPLOADTHIS)) {
+    fprintf(stderr, "READ!\n");
+    strcpy(ptr, UPLOADTHIS);
+    return strlen(UPLOADTHIS);
+  }
+  fprintf(stderr, "READ NOT FINE!\n");
+  return 0;
+}
+static curlioerr ioctlcallback(CURL *handle,
+                               int cmd,
+                               void *clientp)
+{
+  int *counter = (int *)clientp;
+  (void)handle; /* unused */
+  if(cmd == CURLIOCMD_RESTARTREAD) {
+    fprintf(stderr, "REWIND!\n");
+    *counter = 0; /* clear counter to make the read callback restart */
+  }
+  return CURLIOE_OK;
+}
+
+
+int test(char *URL)
+{
+  CURLcode res;
+  CURL *curl;
+  int counter=0;
+  CURLM *m;
+  int running=1;
+  struct timeval mp_start;
+  char mp_timedout = FALSE;
+
+  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+    fprintf(stderr, "curl_global_init() failed\n");
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  if ((curl = curl_easy_init()) == NULL) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  curl_easy_setopt(curl, CURLOPT_URL, URL);
+  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+  curl_easy_setopt(curl, CURLOPT_HEADER, TRUE);
+
+  /* read the POST data from a callback */
+  curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
+  curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
+  curl_easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
+  curl_easy_setopt(curl, CURLOPT_READDATA, &counter);
+  /* We CANNOT do the POST fine without setting the size (or choose chunked)! */
+  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
+
+  curl_easy_setopt(curl, CURLOPT_POST, 1);
+  curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
+  curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
+  curl_easy_setopt(curl, CURLOPT_PROXYAUTH,
+                   CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC );
+
+  if ((m = curl_multi_init()) == NULL) {
+    fprintf(stderr, "curl_multi_init() failed\n");
+    curl_easy_cleanup(curl);
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) {
+    fprintf(stderr, "curl_multi_add_handle() failed, "
+            "with code %d\n", res);
+    curl_multi_cleanup(m);
+    curl_easy_cleanup(curl);
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  mp_timedout = FALSE;
+  mp_start = tutil_tvnow();
+
+  while (running) {
+    res = (int)curl_multi_perform(m, &running);
+    if (tutil_tvdiff(tutil_tvnow(), mp_start) >
+        MULTI_PERFORM_HANG_TIMEOUT) {
+      mp_timedout = TRUE;
+      break;
+    }
+    if (running <= 0) {
+      fprintf(stderr, "nothing left running.\n");
+      break;
+    }
+  }
+
+  if (mp_timedout) {
+    if (mp_timedout) fprintf(stderr, "mp_timedout\n");
+    fprintf(stderr, "ABORTING TEST, since it seems "
+            "that it would have run forever.\n");
+    res = TEST_ERR_RUNS_FOREVER;
+  }
+
+  curl_multi_remove_handle(m, curl);
+  curl_easy_cleanup(curl);
+  curl_multi_cleanup(m);
+
+  curl_global_cleanup();
+
+  return (int)res;
+}
+