summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Monnerat <Patrick.Monnerat@datasphere.ch>2007-10-25 19:40:05 +0000
committerPatrick Monnerat <Patrick.Monnerat@datasphere.ch>2007-10-25 19:40:05 +0000
commit0678a51d3b8be8b24e475929fae11b95d2258da4 (patch)
treece61134dcc831ab685b27300e2d675f1f9c2344c
parentb7dd186d3608ae82de103f4e25982047abb816be (diff)
downloadgnurl-0678a51d3b8be8b24e475929fae11b95d2258da4.tar.gz
gnurl-0678a51d3b8be8b24e475929fae11b95d2258da4.tar.bz2
gnurl-0678a51d3b8be8b24e475929fae11b95d2258da4.zip
Allow test server to handle binary POSTs.
Tests 35, 544 545 added: binary data POSTs.
-rw-r--r--CHANGES5
-rw-r--r--tests/data/Makefile.am3
-rw-r--r--tests/data/test35bin0 -> 743 bytes
-rw-r--r--tests/data/test54449
-rw-r--r--tests/data/test545bin0 -> 748 bytes
-rw-r--r--tests/libtest/Makefile.am8
-rw-r--r--tests/libtest/lib544.c57
-rw-r--r--tests/server/sws.c12
8 files changed, 125 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index 79f347084..586a1ecdb 100644
--- 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.
diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index 14a511bf3..f802b1ac9 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -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
index 000000000..0f322f9e3
--- /dev/null
+++ b/tests/data/test35
Binary files differ
diff --git a/tests/data/test544 b/tests/data/test544
new file mode 100644
index 000000000..2fa4edb1b
--- /dev/null
+++ b/tests/data/test544
@@ -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
+Host: %HOSTIP:%HTTPPORT
+Accept: */*
+Content-Length: 4
+Content-Type: application/x-www-form-urlencoded
+
+This
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/data/test545 b/tests/data/test545
new file mode 100644
index 000000000..66ebb6119
--- /dev/null
+++ b/tests/data/test545
Binary files differ
diff --git a/tests/libtest/Makefile.am b/tests/libtest/Makefile.am
index f0fb24ed0..3137e9e06 100644
--- a/tests/libtest/Makefile.am
+++ b/tests/libtest/Makefile.am
@@ -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
index 000000000..bde630d6b
--- /dev/null
+++ b/tests/libtest/lib544.c
@@ -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;
+}
diff --git a/tests/server/sws.c b/tests/server/sws.c
index e9f5f9384..55c05b199 100644
--- a/tests/server/sws.c
+++ b/tests/server/sws.c
@@ -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 */
}