Allow test server to handle binary POSTs.

Tests 35, 544 545 added: binary data POSTs.
This commit is contained in:
Patrick Monnerat 2007-10-25 19:40:05 +00:00
Родитель b7dd186d36
Коммит 0678a51d3b
8 изменённых файлов: 125 добавлений и 9 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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; \

Двоичные данные
tests/data/test35 Normal file

Двоичный файл не отображается.

49
tests/data/test544 Normal file
Просмотреть файл

@ -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>

Двоичные данные
tests/data/test545 Normal 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

57
tests/libtest/lib544.c Normal file
Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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 */
}