diff options
author | Tobias Brunner <tobias@strongswan.org> | 2014-05-09 18:44:17 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2014-05-19 14:28:45 +0200 |
commit | 350c1dead93d2db0d439bdfdb30a89e599d55660 (patch) | |
tree | 2253794ffe0de1e5dd1cb2ff175cbdcf3d827f1c /src | |
parent | 703a0b4c3e11ceee936c795efdb630fbc45faa75 (diff) | |
download | strongswan-350c1dead93d2db0d439bdfdb30a89e599d55660.tar.bz2 strongswan-350c1dead93d2db0d439bdfdb30a89e599d55660.tar.xz |
unit-tests: Allow some HTTP write operations to fail
Because CURLOPT_FAILONERROR is enabled in the curl plugin an error code
will often (not always) cause the client to close the TCP connection
before the server has written the complete response.
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/tests/suites/test_fetch_http.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/libstrongswan/tests/suites/test_fetch_http.c b/src/libstrongswan/tests/suites/test_fetch_http.c index eeef3587c..42743c787 100644 --- a/src/libstrongswan/tests/suites/test_fetch_http.c +++ b/src/libstrongswan/tests/suites/test_fetch_http.c @@ -159,25 +159,30 @@ static bool servicing(void *data, stream_t *stream) /* response headers */ snprintf(buf, sizeof(buf), "HTTP/1.%u %u OK\r\n", test->minor, test->code); ck_assert(stream->write_all(stream, buf, strlen(buf))); + + /* if the response code indicates an error the following write operations + * might fail because the client already terminated the TCP connection */ +#define may_fail(test, op) ck_assert(op || !HTTP_SUCCESS(test->code)) + t = time(NULL); gmtime_r(&t, &tm); strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z", &tm); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "Server: strongSwan unit test\r\n"); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); /* rest of response headers */ snprintf(buf, sizeof(buf), "Content-Type: text/plain\r\n"); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "Content-Length: %u\r\n", test->res_len); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "Connection: close\r\n"); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); snprintf(buf, sizeof(buf), "\r\n"); - ck_assert(stream->write_all(stream, buf, strlen(buf))); + may_fail(test, stream->write_all(stream, buf, strlen(buf))); /* response body */ - ck_assert(stream->write_all(stream, test->res, test->res_len)); + may_fail(test, stream->write_all(stream, test->res, test->res_len)); return FALSE; } |