Allow test server to handle binary POSTs.
authorPatrick Monnerat <Patrick.Monnerat@datasphere.ch>
Thu, 25 Oct 2007 19:40:05 +0000 (19:40 +0000)
committerPatrick Monnerat <Patrick.Monnerat@datasphere.ch>
Thu, 25 Oct 2007 19:40:05 +0000 (19:40 +0000)
Tests 35, 544 545 added: binary data POSTs.

CHANGES
tests/data/Makefile.am
tests/data/test35 [new file with mode: 0644]
tests/data/test544 [new file with mode: 0644]
tests/data/test545 [new file with mode: 0644]
tests/libtest/Makefile.am
tests/libtest/lib544.c [new file with mode: 0644]
tests/server/sws.c

diff --git a/CHANGES b/CHANGES
index 79f3470..586a1ec 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,11 @@
 
                                   Changelog
 
+Patrick M (25 October 2007)
+- Fixed test server to allow null bytes in binary posts.
+_ Added tests 35, 544 & 545 to check binary data posts, both static (in place)
+  and dynamic (copied).
+
 Daniel S (25 October 2007)
 - Michal Marek fixed the test script to be able to use valgrind even when the
   lib is built shared with libtool.
index 14a511b..f802b1a 100644 (file)
@@ -45,7 +45,8 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46           \
  test706 test707 test350 test351 test352 test353 test289 test540 test354   \
  test231 test1000 test1001 test1002 test1003 test1004 test1005 test1006    \
  test615 test1007 test541 test1010 test1011 test1012 test542 test543       \
- test536 test1008 test1009 test2000 test2001 test2002 test2003
+ test536 test1008 test1009 test2000 test2001 test2002 test2003 test35      \
+ test544 test545
 
 filecheck:
        @mkdir test-place; \
diff --git a/tests/data/test35 b/tests/data/test35
new file mode 100644 (file)
index 0000000..0f322f9
Binary files /dev/null and b/tests/data/test35 differ
diff --git a/tests/data/test544 b/tests/data/test544
new file mode 100644 (file)
index 0000000..2fa4edb
--- /dev/null
@@ -0,0 +1,49 @@
+<testcase>
+#
+# Server-side
+<reply>
+<data mode="text">
+HTTP/1.1 200 OK swsclose
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Server: test-server/fake
+Content-Length: 3
+
+OK
+</data>
+</reply>
+
+# Client-side
+<client>
+<server>
+http
+</server>
+# tool is what to use instead of 'curl'
+<tool>
+lib544
+</tool>
+
+ <name>
+HTTP POST text data using CURLOPT_COPYPOSTFIELDS
+ </name>
+ <command>
+http://%HOSTIP:%HTTPPORT/544
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<strip>
+^User-Agent:.*
+</strip>
+<protocol nonewline="yes">
+POST /544 HTTP/1.1\r
+Host: %HOSTIP:%HTTPPORT\r
+Accept: */*\r
+Content-Length: 4\r
+Content-Type: application/x-www-form-urlencoded\r
+\r
+This
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/data/test545 b/tests/data/test545
new file mode 100644 (file)
index 0000000..66ebb61
Binary files /dev/null and b/tests/data/test545 differ
index f0fb24e..3137e9e 100644 (file)
@@ -47,7 +47,8 @@ SUPPORTFILES = first.c test.h
 noinst_PROGRAMS = lib500 lib501 lib502 lib503 lib504 lib505 lib506     \
   lib507 lib508 lib509 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
+  lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542 lib543 \
+  lib544 lib545
 
 # Dependencies (may need to be overriden)
 LDADD = $(LIBDIR)/libcurl.la
@@ -132,3 +133,8 @@ lib541_SOURCES = lib541.c $(SUPPORTFILES)
 lib542_SOURCES = lib542.c $(SUPPORTFILES)
 
 lib543_SOURCES = lib543.c $(SUPPORTFILES)
+
+lib544_SOURCES = lib544.c $(SUPPORTFILES)
+
+lib545_SOURCES = lib544.c $(SUPPORTFILES)
+lib545_CFLAGS = -DLIB545
diff --git a/tests/libtest/lib544.c b/tests/libtest/lib544.c
new file mode 100644 (file)
index 0000000..bde630d
--- /dev/null
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * $Id$
+ */
+
+#include "test.h"
+
+
+static char teststring[] =
+  "This\0 is test binary data with an embedded NUL byte\n";
+
+
+int test(char *URL)
+{
+  CURL *curl;
+  CURLcode res=CURLE_OK;
+
+  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;
+  }
+
+  /* First set the URL that is about to receive our POST. */
+  curl_easy_setopt(curl, CURLOPT_URL, URL);
+
+#ifdef LIB545
+  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, sizeof teststring - 1);
+#endif
+
+  curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, teststring);
+
+  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); /* show verbose for debug */
+  curl_easy_setopt(curl, CURLOPT_HEADER, 1); /* include header */
+
+  /* Update the original data to detect non-copy. */
+  strcpy(teststring, "FAIL");
+
+  /* Now, this is a POST request with binary 0 embedded in POST data. */
+  res = curl_easy_perform(curl);
+
+  /* always cleanup */
+  curl_easy_cleanup(curl);
+  curl_global_cleanup();
+
+  return (int)res;
+}
index e9f5f93..55c05b1 100644 (file)
@@ -110,7 +110,7 @@ struct httprequest {
 };
 
 int ProcessRequest(struct httprequest *req);
-void storerequest(char *reqbuf);
+void storerequest(char *reqbuf, ssize_t totalsize);
 
 #define DEFAULT_PORT 8999
 
@@ -446,7 +446,7 @@ int ProcessRequest(struct httprequest *req)
     return 1;
 
   if(req->cl) {
-    if(req->cl <= strlen(end+strlen(END_OF_HEADERS)))
+    if(req->cl <= req->offset - (end - req->reqbuf) - strlen(END_OF_HEADERS))
       return 1; /* done */
     else
       return 0; /* not complete yet */
@@ -456,18 +456,16 @@ int ProcessRequest(struct httprequest *req)
 }
 
 /* store the entire request in a file */
-void storerequest(char *reqbuf)
+void storerequest(char *reqbuf, ssize_t totalsize)
 {
   int error;
   ssize_t written;
   ssize_t writeleft;
-  ssize_t totalsize;
   FILE *dump;
 
   if (reqbuf == NULL)
     return;
 
-  totalsize = (ssize_t)strlen(reqbuf);
   if (totalsize == 0)
     return;
 
@@ -531,7 +529,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
       reqbuf[req->offset]=0;
 
       /* dump the request receivied so far to the external file */
-      storerequest(reqbuf);
+      storerequest(reqbuf, req->offset);
       return DOCNUMBER_INTERNAL;
     }
 
@@ -560,7 +558,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
     reqbuf[req->offset]=0;
 
   /* dump the request to an external file */
-  storerequest(reqbuf);
+  storerequest(reqbuf, req->offset);
 
   return fail; /* success */
 }