mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +02:00
Use standard HARNESS_FORK*() macros to fork test servers.
These forks were done in a custom way (not sure why) and lack the capability of the standard macros for the parent to wait for child exit. This mean that the server would continue to run after the tests were complete and that multiple servers could run at once. This caused subtle timing and connection issues that required larger timeouts to resolve. Don't change the timeouts here since they need to be adjusted in future commits anyway.
This commit is contained in:
parent
42246401b8
commit
71ce637557
@ -3,9 +3,11 @@ Test Http
|
||||
***********************************************************************************************************************************/
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common/harnessTls.h"
|
||||
#include "common/time.h"
|
||||
|
||||
#include "common/harnessFork.h"
|
||||
#include "common/harnessTls.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Test server
|
||||
***********************************************************************************************************************************/
|
||||
@ -14,311 +16,303 @@ testHttpServer(void)
|
||||
{
|
||||
FUNCTION_HARNESS_VOID();
|
||||
|
||||
if (fork() == 0)
|
||||
{
|
||||
// Change log process id to aid in debugging
|
||||
hrnLogProcessIdSet(1);
|
||||
harnessTlsServerInitDefault();
|
||||
|
||||
harnessTlsServerInitDefault();
|
||||
// Test no output from server
|
||||
harnessTlsServerAccept();
|
||||
|
||||
// Test no output from server
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
sleepMSec(600);
|
||||
harnessTlsServerClose();
|
||||
|
||||
sleepMSec(600);
|
||||
harnessTlsServerClose();
|
||||
// Test invalid http version
|
||||
harnessTlsServerAccept();
|
||||
|
||||
// Test invalid http version
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.0 200 OK\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.0 200 OK\r\n");
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerClose();
|
||||
// Test no space in status
|
||||
harnessTlsServerAccept();
|
||||
|
||||
// Test no space in status
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200OK\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200OK\r\n");
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerClose();
|
||||
// Test unexpected end of headers
|
||||
harnessTlsServerAccept();
|
||||
|
||||
// Test unexpected end of headers
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n");
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerClose();
|
||||
// Test missing colon in header
|
||||
harnessTlsServerAccept();
|
||||
|
||||
// Test missing colon in header
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"header-value\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"header-value\r\n");
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerClose();
|
||||
// Test invalid transfer encoding
|
||||
harnessTlsServerAccept();
|
||||
|
||||
// Test invalid transfer encoding
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"transfer-encoding:bogus\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"transfer-encoding:bogus\r\n");
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerClose();
|
||||
// Test content length and transfer encoding both set
|
||||
harnessTlsServerAccept();
|
||||
|
||||
// Test content length and transfer encoding both set
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"transfer-encoding:chunked\r\n"
|
||||
"content-length:777\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"transfer-encoding:chunked\r\n"
|
||||
"content-length:777\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerClose();
|
||||
// Test 5xx error with no retry
|
||||
harnessTlsServerAccept();
|
||||
|
||||
// Test 5xx error with no retry
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 503 Slow Down\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 503 Slow Down\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerClose();
|
||||
// Request with no content (with an internal error)
|
||||
harnessTlsServerAccept();
|
||||
|
||||
// Request with no content (with an internal error)
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET /?name=%2Fpath%2FA%20Z.txt&type=test HTTP/1.1\r\n"
|
||||
"host:myhost.com\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET /?name=%2Fpath%2FA%20Z.txt&type=test HTTP/1.1\r\n"
|
||||
"host:myhost.com\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 500 Internal Error\r\n"
|
||||
"Connection:close\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 500 Internal Error\r\n"
|
||||
"Connection:close\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerClose();
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET /?name=%2Fpath%2FA%20Z.txt&type=test HTTP/1.1\r\n"
|
||||
"host:myhost.com\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET /?name=%2Fpath%2FA%20Z.txt&type=test HTTP/1.1\r\n"
|
||||
"host:myhost.com\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"key1:0\r\n"
|
||||
" key2 : value2\r\n"
|
||||
"Connection:ack\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"key1:0\r\n"
|
||||
" key2 : value2\r\n"
|
||||
"Connection:ack\r\n"
|
||||
"\r\n");
|
||||
// Head request with content-length but no content
|
||||
harnessTlsServerExpect(
|
||||
"HEAD / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
// Head request with content-length but no content
|
||||
harnessTlsServerExpect(
|
||||
"HEAD / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"content-length:380\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"content-length:380\r\n"
|
||||
"\r\n");
|
||||
// Head request with transfer encoding but no content
|
||||
harnessTlsServerExpect(
|
||||
"HEAD / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
// Head request with transfer encoding but no content
|
||||
harnessTlsServerExpect(
|
||||
"HEAD / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Transfer-Encoding: chunked\r\n"
|
||||
"\r\n");
|
||||
// Head request with connection close but no content
|
||||
harnessTlsServerExpect(
|
||||
"HEAD / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
// Head request with connection close but no content
|
||||
harnessTlsServerExpect(
|
||||
"HEAD / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Connection:close\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Connection:close\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerClose();
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerAccept();
|
||||
// Error with content (with a few slow down errors)
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
// Error with content (with a few slow down errors)
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 503 Slow Down\r\n"
|
||||
"content-length:3\r\n"
|
||||
"Connection:close\r\n"
|
||||
"\r\n"
|
||||
"123");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 503 Slow Down\r\n"
|
||||
"content-length:3\r\n"
|
||||
"Connection:close\r\n"
|
||||
"\r\n"
|
||||
"123");
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerClose();
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 503 Slow Down\r\n"
|
||||
"Transfer-Encoding:chunked\r\n"
|
||||
"Connection:close\r\n"
|
||||
"\r\n"
|
||||
"0\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 404 Not Found\r\n"
|
||||
"content-length:0\r\n"
|
||||
"\r\n");
|
||||
|
||||
// Error with content
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 403 Auth Error\r\n"
|
||||
"content-length:7\r\n"
|
||||
"\r\n"
|
||||
"CONTENT");
|
||||
|
||||
// Request with content
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET /path/file%201.txt HTTP/1.1\r\n"
|
||||
"content-length:30\r\n"
|
||||
"\r\n"
|
||||
"012345678901234567890123456789");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Connection:close\r\n"
|
||||
"\r\n"
|
||||
"01234567890123456789012345678901");
|
||||
|
||||
harnessTlsServerClose();
|
||||
|
||||
// Request with eof before content complete with retry
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET /path/file%201.txt HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"content-length:32\r\n"
|
||||
"\r\n"
|
||||
"0123456789012345678901234567890");
|
||||
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 503 Slow Down\r\n"
|
||||
"Transfer-Encoding:chunked\r\n"
|
||||
"Connection:close\r\n"
|
||||
"\r\n"
|
||||
"0\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerClose();
|
||||
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 404 Not Found\r\n"
|
||||
"content-length:0\r\n"
|
||||
"\r\n");
|
||||
|
||||
// Error with content
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 403 Auth Error\r\n"
|
||||
"content-length:7\r\n"
|
||||
"\r\n"
|
||||
"CONTENT");
|
||||
|
||||
// Request with content
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET /path/file%201.txt HTTP/1.1\r\n"
|
||||
"content-length:30\r\n"
|
||||
"\r\n"
|
||||
"012345678901234567890123456789");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Connection:close\r\n"
|
||||
"\r\n"
|
||||
"01234567890123456789012345678901");
|
||||
|
||||
harnessTlsServerClose();
|
||||
|
||||
// Request with eof before content complete with retry
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET /path/file%201.txt HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"content-length:32\r\n"
|
||||
"\r\n"
|
||||
"0123456789012345678901234567890");
|
||||
|
||||
harnessTlsServerClose();
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET /path/file%201.txt HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"content-length:32\r\n"
|
||||
"\r\n"
|
||||
"01234567890123456789012345678901");
|
||||
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET /path/file%201.txt HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"content-length:32\r\n"
|
||||
"\r\n"
|
||||
"01234567890123456789012345678901");
|
||||
// Request with eof before content complete
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET /path/file%201.txt HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"content-length:32\r\n"
|
||||
"\r\n"
|
||||
"0123456789012345678901234567890");
|
||||
|
||||
// Request with eof before content complete
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET /path/file%201.txt HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"content-length:32\r\n"
|
||||
"\r\n"
|
||||
"0123456789012345678901234567890");
|
||||
|
||||
harnessTlsServerClose();
|
||||
|
||||
// Request with chunked content
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Transfer-Encoding:chunked\r\n"
|
||||
"\r\n"
|
||||
"20\r\n"
|
||||
"01234567890123456789012345678901\r\n"
|
||||
"10\r\n"
|
||||
"0123456789012345\r\n"
|
||||
"0\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerClose();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
harnessTlsServerClose();
|
||||
|
||||
// Request with chunked content
|
||||
harnessTlsServerAccept();
|
||||
|
||||
harnessTlsServerExpect(
|
||||
"GET / HTTP/1.1\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerReply(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Transfer-Encoding:chunked\r\n"
|
||||
"\r\n"
|
||||
"20\r\n"
|
||||
"01234567890123456789012345678901\r\n"
|
||||
"10\r\n"
|
||||
"0123456789012345\r\n"
|
||||
"0\r\n"
|
||||
"\r\n");
|
||||
|
||||
harnessTlsServerClose();
|
||||
|
||||
FUNCTION_HARNESS_RESULT_VOID();
|
||||
}
|
||||
@ -446,176 +440,198 @@ testRun(void)
|
||||
|
||||
// Reset statistics
|
||||
httpClientStatLocal = (HttpClientStat){0};
|
||||
|
||||
TEST_RESULT_PTR(httpClientStatStr(), NULL, "no stats yet");
|
||||
|
||||
TEST_ASSIGN(
|
||||
client, httpClientNew(strNew("localhost"), harnessTlsTestPort(), 500, testContainer(), NULL, NULL), "new client");
|
||||
client, httpClientNew(strNew("localhost"), harnessTlsTestPort(), 500, testContainer(), NULL, NULL),
|
||||
"new client");
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), HostConnectError,
|
||||
"unable to connect to 'localhost:%u': [111] Connection refused", harnessTlsTestPort());
|
||||
|
||||
// Start http test server
|
||||
TEST_RESULT_VOID(testHttpServer(), "http server begin");
|
||||
HARNESS_FORK_BEGIN()
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, false)
|
||||
{
|
||||
// Start http test server
|
||||
TEST_RESULT_VOID(testHttpServer(), "http server begin");
|
||||
}
|
||||
HARNESS_FORK_CHILD_END();
|
||||
|
||||
// Test no output from server
|
||||
TEST_ASSIGN(
|
||||
client, httpClientNew(harnessTlsTestHost(), harnessTlsTestPort(), 500, testContainer(), NULL, NULL), "new client");
|
||||
client->timeout = 0;
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
// Test no output from server
|
||||
TEST_ASSIGN(
|
||||
client, httpClientNew(harnessTlsTestHost(), harnessTlsTestPort(), 500, testContainer(), NULL, NULL),
|
||||
"new client");
|
||||
client->timeout = 0;
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FileReadError,
|
||||
"timeout after 500ms waiting for read from '%s:%u'", strPtr(harnessTlsTestHost()), harnessTlsTestPort());
|
||||
TEST_ERROR_FMT(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FileReadError,
|
||||
"timeout after 500ms waiting for read from '%s:%u'", strPtr(harnessTlsTestHost()), harnessTlsTestPort());
|
||||
|
||||
// Test invalid http version
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FormatError,
|
||||
"http version of response 'HTTP/1.0 200 OK' must be HTTP/1.1");
|
||||
// Test invalid http version
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FormatError,
|
||||
"http version of response 'HTTP/1.0 200 OK' must be HTTP/1.1");
|
||||
|
||||
// Test no space in status
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FormatError,
|
||||
"response status '200OK' must have a space");
|
||||
// Test no space in status
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FormatError,
|
||||
"response status '200OK' must have a space");
|
||||
|
||||
// Test unexpected end of headers
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FileReadError,
|
||||
"unexpected eof while reading line");
|
||||
// Test unexpected end of headers
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FileReadError,
|
||||
"unexpected eof while reading line");
|
||||
|
||||
// Test missing colon in header
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FormatError,
|
||||
"header 'header-value' missing colon");
|
||||
// Test missing colon in header
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FormatError,
|
||||
"header 'header-value' missing colon");
|
||||
|
||||
// Test invalid transfer encoding
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FormatError,
|
||||
"only 'chunked' is supported for 'transfer-encoding' header");
|
||||
// Test invalid transfer encoding
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FormatError,
|
||||
"only 'chunked' is supported for 'transfer-encoding' header");
|
||||
|
||||
// Test content length and transfer encoding both set
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FormatError,
|
||||
"'transfer-encoding' and 'content-length' headers are both set");
|
||||
// Test content length and transfer encoding both set
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), FormatError,
|
||||
"'transfer-encoding' and 'content-length' headers are both set");
|
||||
|
||||
// Test 5xx error with no retry
|
||||
TEST_ERROR(httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), ServiceError, "[503] Slow Down");
|
||||
// Test 5xx error with no retry
|
||||
TEST_ERROR(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), ServiceError,
|
||||
"[503] Slow Down");
|
||||
|
||||
// Request with no content
|
||||
client->timeout = 2000;
|
||||
// Request with no content
|
||||
client->timeout = 2000;
|
||||
|
||||
HttpHeader *headerRequest = httpHeaderNew(NULL);
|
||||
httpHeaderAdd(headerRequest, strNew("host"), strNew("myhost.com"));
|
||||
HttpHeader *headerRequest = httpHeaderNew(NULL);
|
||||
httpHeaderAdd(headerRequest, strNew("host"), strNew("myhost.com"));
|
||||
|
||||
HttpQuery *query = httpQueryNew();
|
||||
httpQueryAdd(query, strNew("name"), strNew("/path/A Z.txt"));
|
||||
httpQueryAdd(query, strNew("type"), strNew("test"));
|
||||
HttpQuery *query = httpQueryNew();
|
||||
httpQueryAdd(query, strNew("name"), strNew("/path/A Z.txt"));
|
||||
httpQueryAdd(query, strNew("type"), strNew("test"));
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), query, headerRequest, NULL, false), "request with no content");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 200, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "OK", " check response message");
|
||||
TEST_RESULT_UINT(httpClientEof(client), true, " io is eof");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{connection: 'ack', key1: '0', key2: 'value2'}",
|
||||
" check response headers");
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), query, headerRequest, NULL, false),
|
||||
"request with no content");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 200, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "OK", " check response message");
|
||||
TEST_RESULT_UINT(httpClientEof(client), true, " io is eof");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{connection: 'ack', key1: '0', key2: 'value2'}",
|
||||
" check response headers");
|
||||
|
||||
// Head request with content-length but no content
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("HEAD"), strNew("/"), NULL, httpHeaderNew(NULL), NULL, true),
|
||||
"head request with content-length");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 200, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "OK", " check response message");
|
||||
TEST_RESULT_BOOL(httpClientEof(client), true, " io is eof");
|
||||
TEST_RESULT_BOOL(httpClientBusy(client), false, " client is not busy");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{content-length: '380'}", " check response headers");
|
||||
// Head request with content-length but no content
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("HEAD"), strNew("/"), NULL, httpHeaderNew(NULL), NULL, true),
|
||||
"head request with content-length");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 200, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "OK", " check response message");
|
||||
TEST_RESULT_BOOL(httpClientEof(client), true, " io is eof");
|
||||
TEST_RESULT_BOOL(httpClientBusy(client), false, " client is not busy");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{content-length: '380'}", " check response headers");
|
||||
|
||||
// Head request with transfer encoding but no content
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("HEAD"), strNew("/"), NULL, httpHeaderNew(NULL), NULL, true),
|
||||
"head request with transfer encoding");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 200, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "OK", " check response message");
|
||||
TEST_RESULT_BOOL(httpClientEof(client), true, " io is eof");
|
||||
TEST_RESULT_BOOL(httpClientBusy(client), false, " client is not busy");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{transfer-encoding: 'chunked'}", " check response headers");
|
||||
// Head request with transfer encoding but no content
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("HEAD"), strNew("/"), NULL, httpHeaderNew(NULL), NULL, true),
|
||||
"head request with transfer encoding");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 200, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "OK", " check response message");
|
||||
TEST_RESULT_BOOL(httpClientEof(client), true, " io is eof");
|
||||
TEST_RESULT_BOOL(httpClientBusy(client), false, " client is not busy");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{transfer-encoding: 'chunked'}",
|
||||
" check response headers");
|
||||
|
||||
// Head request with connection close but no content
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("HEAD"), strNew("/"), NULL, httpHeaderNew(NULL), NULL, true),
|
||||
"head request with connection close");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 200, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "OK", " check response message");
|
||||
TEST_RESULT_BOOL(httpClientEof(client), true, " io is eof");
|
||||
TEST_RESULT_BOOL(httpClientBusy(client), false, " client is not busy");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{connection: 'close'}", " check response headers");
|
||||
// Head request with connection close but no content
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("HEAD"), strNew("/"), NULL, httpHeaderNew(NULL), NULL, true),
|
||||
"head request with connection close");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 200, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "OK", " check response message");
|
||||
TEST_RESULT_BOOL(httpClientEof(client), true, " io is eof");
|
||||
TEST_RESULT_BOOL(httpClientBusy(client), false, " client is not busy");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{connection: 'close'}", " check response headers");
|
||||
|
||||
// Error with content length 0
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), "error with content length 0");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 404, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "Not Found", " check response message");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{content-length: '0'}", " check response headers");
|
||||
// Error with content length 0
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), "error with content length 0");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 404, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "Not Found", " check response message");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{content-length: '0'}", " check response headers");
|
||||
|
||||
// Error with content
|
||||
Buffer *buffer = NULL;
|
||||
// Error with content
|
||||
Buffer *buffer = NULL;
|
||||
|
||||
TEST_ASSIGN(
|
||||
buffer, httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), "error with content length");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 403, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "Auth Error", " check response message");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{content-length: '7'}", " check response headers");
|
||||
TEST_RESULT_STR_Z(strNewBuf(buffer), "CONTENT", " check response");
|
||||
TEST_ASSIGN(
|
||||
buffer, httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false),
|
||||
"error with content length");
|
||||
TEST_RESULT_UINT(httpClientResponseCode(client), 403, " check response code");
|
||||
TEST_RESULT_STR_Z(httpClientResponseMessage(client), "Auth Error", " check response message");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{content-length: '7'}", " check response headers");
|
||||
TEST_RESULT_STR_Z(strNewBuf(buffer), "CONTENT", " check response");
|
||||
|
||||
// Request with content using content-length
|
||||
ioBufferSizeSet(30);
|
||||
// Request with content using content-length
|
||||
ioBufferSizeSet(30);
|
||||
|
||||
TEST_ASSIGN(
|
||||
buffer,
|
||||
httpClientRequest(
|
||||
client, strNew("GET"), strNew("/path/file 1.txt"), NULL,
|
||||
httpHeaderAdd(httpHeaderNew(NULL), strNew("content-length"), strNew("30")),
|
||||
BUFSTRDEF("012345678901234567890123456789"), true),
|
||||
"request with content length");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{connection: 'close'}",
|
||||
" check response headers");
|
||||
TEST_RESULT_STR_Z(strNewBuf(buffer), "01234567890123456789012345678901", " check response");
|
||||
TEST_RESULT_UINT(httpClientRead(client, bufNew(1), true), 0, " call internal read to check eof");
|
||||
TEST_ASSIGN(
|
||||
buffer,
|
||||
httpClientRequest(
|
||||
client, strNew("GET"), strNew("/path/file 1.txt"), NULL,
|
||||
httpHeaderAdd(httpHeaderNew(NULL), strNew("content-length"), strNew("30")),
|
||||
BUFSTRDEF("012345678901234567890123456789"), true),
|
||||
"request with content length");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{connection: 'close'}",
|
||||
" check response headers");
|
||||
TEST_RESULT_STR_Z(strNewBuf(buffer), "01234567890123456789012345678901", " check response");
|
||||
TEST_RESULT_UINT(httpClientRead(client, bufNew(1), true), 0, " call internal read to check eof");
|
||||
|
||||
// Request with eof before content complete with retry
|
||||
TEST_ASSIGN(
|
||||
buffer, httpClientRequest(client, strNew("GET"), strNew("/path/file 1.txt"), NULL, NULL, NULL, true),
|
||||
"request with content length retry");
|
||||
TEST_RESULT_STR_Z(strNewBuf(buffer), "01234567890123456789012345678901", " check response");
|
||||
TEST_RESULT_UINT(httpClientRead(client, bufNew(1), true), 0, " call internal read to check eof");
|
||||
// Request with eof before content complete with retry
|
||||
TEST_ASSIGN(
|
||||
buffer, httpClientRequest(client, strNew("GET"), strNew("/path/file 1.txt"), NULL, NULL, NULL, true),
|
||||
"request with content length retry");
|
||||
TEST_RESULT_STR_Z(strNewBuf(buffer), "01234567890123456789012345678901", " check response");
|
||||
TEST_RESULT_UINT(httpClientRead(client, bufNew(1), true), 0, " call internal read to check eof");
|
||||
|
||||
// Request with eof before content and error
|
||||
buffer = bufNew(32);
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/path/file 1.txt"), NULL, NULL, NULL, false),
|
||||
"request with content length error");
|
||||
TEST_RESULT_BOOL(httpClientBusy(client), true, " client is busy");
|
||||
TEST_ERROR(
|
||||
ioRead(httpClientIoRead(client), buffer), FileReadError, "unexpected EOF reading HTTP content");
|
||||
// Request with eof before content and error
|
||||
buffer = bufNew(32);
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/path/file 1.txt"), NULL, NULL, NULL, false),
|
||||
"request with content length error");
|
||||
TEST_RESULT_BOOL(httpClientBusy(client), true, " client is busy");
|
||||
TEST_ERROR(
|
||||
ioRead(httpClientIoRead(client), buffer), FileReadError, "unexpected EOF reading HTTP content");
|
||||
|
||||
// Request with content using chunked encoding
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false), "request with chunked encoding");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{transfer-encoding: 'chunked'}", " check response headers");
|
||||
// Request with content using chunked encoding
|
||||
TEST_RESULT_VOID(
|
||||
httpClientRequest(client, strNew("GET"), strNew("/"), NULL, NULL, NULL, false),
|
||||
"request with chunked encoding");
|
||||
TEST_RESULT_STR_Z(
|
||||
httpHeaderToLog(httpClientResponseHeader(client)), "{transfer-encoding: 'chunked'}",
|
||||
" check response headers");
|
||||
|
||||
buffer = bufNew(35);
|
||||
TEST_RESULT_VOID(ioRead(httpClientIoRead(client), buffer), " read response");
|
||||
TEST_RESULT_STR_Z(strNewBuf(buffer), "01234567890123456789012345678901012", " check response");
|
||||
buffer = bufNew(35);
|
||||
TEST_RESULT_VOID(ioRead(httpClientIoRead(client), buffer), " read response");
|
||||
TEST_RESULT_STR_Z(strNewBuf(buffer), "01234567890123456789012345678901012", " check response");
|
||||
|
||||
TEST_RESULT_BOOL(httpClientStatStr() != NULL, true, "check statistics exist");
|
||||
TEST_RESULT_BOOL(httpClientStatStr() != NULL, true, "check statistics exist");
|
||||
|
||||
TEST_RESULT_VOID(httpClientFree(client), "free client");
|
||||
TEST_RESULT_VOID(httpClientFree(client), "free client");
|
||||
}
|
||||
HARNESS_FORK_PARENT_END();
|
||||
}
|
||||
HARNESS_FORK_END();
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
|
@ -6,6 +6,7 @@ Test Tls Client
|
||||
|
||||
#include "common/time.h"
|
||||
|
||||
#include "common/harnessFork.h"
|
||||
#include "common/harnessTls.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
@ -16,46 +17,38 @@ testTlsServerAltName(void)
|
||||
{
|
||||
FUNCTION_HARNESS_VOID();
|
||||
|
||||
if (fork() == 0)
|
||||
harnessTlsServerInit(
|
||||
harnessTlsTestPort(),
|
||||
strPtr(strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-alt-name.crt", testRepoPath())),
|
||||
strPtr(strNewFmt("%s/" TEST_CERTIFICATE_PREFIX ".key", testRepoPath())));
|
||||
|
||||
// Certificate error on invalid ca path
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerClose();
|
||||
|
||||
if (testContainer())
|
||||
{
|
||||
// Change log process id to aid in debugging
|
||||
hrnLogProcessIdSet(1);
|
||||
|
||||
harnessTlsServerInit(
|
||||
harnessTlsTestPort(),
|
||||
strPtr(strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-alt-name.crt", testRepoPath())),
|
||||
strPtr(strNewFmt("%s/" TEST_CERTIFICATE_PREFIX ".key", testRepoPath())));
|
||||
|
||||
// Certificate error on invalid ca path
|
||||
// Success on valid ca file and match common name
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerClose();
|
||||
|
||||
if (testContainer())
|
||||
{
|
||||
// Success on valid ca file and match common name
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerClose();
|
||||
|
||||
// Success on valid ca file and match alt name
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerClose();
|
||||
|
||||
// Unable to find matching hostname in certificate
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerClose();
|
||||
}
|
||||
|
||||
// Certificate error
|
||||
// Success on valid ca file and match alt name
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerClose();
|
||||
|
||||
// Certificate ignored
|
||||
// Unable to find matching hostname in certificate
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerClose();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// Certificate error
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerClose();
|
||||
|
||||
// Certificate ignored
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerClose();
|
||||
|
||||
FUNCTION_HARNESS_RESULT_VOID();
|
||||
}
|
||||
|
||||
@ -67,40 +60,32 @@ testTlsServer(void)
|
||||
{
|
||||
FUNCTION_HARNESS_VOID();
|
||||
|
||||
if (fork() == 0)
|
||||
{
|
||||
// Change log process id to aid in debugging
|
||||
hrnLogProcessIdSet(1);
|
||||
harnessTlsServerInitDefault();
|
||||
|
||||
harnessTlsServerInitDefault();
|
||||
// First protocol exchange
|
||||
harnessTlsServerAccept();
|
||||
|
||||
// First protocol exchange
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerExpect("some protocol info");
|
||||
harnessTlsServerReply("something:0\n");
|
||||
|
||||
harnessTlsServerExpect("some protocol info");
|
||||
harnessTlsServerReply("something:0\n");
|
||||
sleepMSec(100);
|
||||
harnessTlsServerReply("some ");
|
||||
|
||||
sleepMSec(100);
|
||||
harnessTlsServerReply("some ");
|
||||
sleepMSec(100);
|
||||
harnessTlsServerReply("contentAND MORE");
|
||||
|
||||
sleepMSec(100);
|
||||
harnessTlsServerReply("contentAND MORE");
|
||||
// This will cause the client to disconnect
|
||||
sleepMSec(500);
|
||||
|
||||
// This will cause the client to disconnect
|
||||
sleepMSec(500);
|
||||
// Second protocol exchange
|
||||
harnessTlsServerExpect("more protocol info");
|
||||
harnessTlsServerReply("0123456789AB");
|
||||
harnessTlsServerClose();
|
||||
|
||||
// Second protocol exchange
|
||||
harnessTlsServerExpect("more protocol info");
|
||||
harnessTlsServerReply("0123456789AB");
|
||||
harnessTlsServerClose();
|
||||
|
||||
// Need data in read buffer to test tlsWriteContinue()
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerReply("0123456789AB");
|
||||
harnessTlsServerClose();
|
||||
|
||||
exit(0);
|
||||
}
|
||||
// Need data in read buffer to test tlsWriteContinue()
|
||||
harnessTlsServerAccept();
|
||||
harnessTlsServerReply("0123456789AB");
|
||||
harnessTlsServerClose();
|
||||
|
||||
FUNCTION_HARNESS_RESULT_VOID();
|
||||
}
|
||||
@ -289,57 +274,72 @@ testRun(void)
|
||||
}
|
||||
}
|
||||
|
||||
// Start server to test various certificate errors
|
||||
TEST_RESULT_VOID(testTlsServerAltName(), "tls alt name server begin");
|
||||
|
||||
TEST_ERROR(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("localhost"), harnessTlsTestPort(), 500), 500, true, strNew("bogus.crt"),
|
||||
strNew("/bogus"))),
|
||||
CryptoError, "unable to set user-defined CA certificate location: [33558530] No such file or directory");
|
||||
TEST_ERROR_FMT(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(sckClientNew(strNew("localhost"), harnessTlsTestPort(), 500), 500, true, NULL, strNew("/bogus"))),
|
||||
CryptoError, "unable to verify certificate presented by 'localhost:%u': [20] unable to get local issuer certificate",
|
||||
harnessTlsTestPort());
|
||||
|
||||
if (testContainer())
|
||||
HARNESS_FORK_BEGIN()
|
||||
{
|
||||
TEST_RESULT_VOID(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("test.pgbackrest.org"), harnessTlsTestPort(), 500), 500, true,
|
||||
strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-ca.crt", testRepoPath()), NULL)),
|
||||
"success on valid ca file and match common name");
|
||||
TEST_RESULT_VOID(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("host.test2.pgbackrest.org"), harnessTlsTestPort(), 500), 500, true,
|
||||
strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-ca.crt", testRepoPath()), NULL)),
|
||||
"success on valid ca file and match alt name");
|
||||
TEST_ERROR(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("test3.pgbackrest.org"), harnessTlsTestPort(), 500), 500, true,
|
||||
strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-ca.crt", testRepoPath()), NULL)),
|
||||
CryptoError,
|
||||
"unable to find hostname 'test3.pgbackrest.org' in certificate common name or subject alternative names");
|
||||
HARNESS_FORK_CHILD_BEGIN(0, false)
|
||||
{
|
||||
// Start server to test various certificate errors
|
||||
TEST_RESULT_VOID(testTlsServerAltName(), "tls alt name server begin");
|
||||
}
|
||||
HARNESS_FORK_CHILD_END();
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
TEST_ERROR(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("localhost"), harnessTlsTestPort(), 500), 500, true, strNew("bogus.crt"),
|
||||
strNew("/bogus"))),
|
||||
CryptoError, "unable to set user-defined CA certificate location: [33558530] No such file or directory");
|
||||
TEST_ERROR_FMT(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("localhost"), harnessTlsTestPort(), 500), 500, true, NULL, strNew("/bogus"))),
|
||||
CryptoError,
|
||||
"unable to verify certificate presented by 'localhost:%u': [20] unable to get local issuer certificate",
|
||||
harnessTlsTestPort());
|
||||
|
||||
if (testContainer())
|
||||
{
|
||||
TEST_RESULT_VOID(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("test.pgbackrest.org"), harnessTlsTestPort(), 500), 500, true,
|
||||
strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-ca.crt", testRepoPath()), NULL)),
|
||||
"success on valid ca file and match common name");
|
||||
TEST_RESULT_VOID(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("host.test2.pgbackrest.org"), harnessTlsTestPort(), 500), 500, true,
|
||||
strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-ca.crt", testRepoPath()), NULL)),
|
||||
"success on valid ca file and match alt name");
|
||||
TEST_ERROR(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("test3.pgbackrest.org"), harnessTlsTestPort(), 500), 500, true,
|
||||
strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-ca.crt", testRepoPath()), NULL)),
|
||||
CryptoError,
|
||||
"unable to find hostname 'test3.pgbackrest.org' in certificate common name or subject alternative names");
|
||||
}
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("localhost"), harnessTlsTestPort(), 500), 500, true,
|
||||
strNewFmt("%s/" TEST_CERTIFICATE_PREFIX ".crt", testRepoPath()),
|
||||
NULL)),
|
||||
CryptoError,
|
||||
"unable to verify certificate presented by 'localhost:%u': [20] unable to get local issuer certificate",
|
||||
harnessTlsTestPort());
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(sckClientNew(strNew("localhost"), harnessTlsTestPort(), 500), 500, false, NULL, NULL)),
|
||||
"success on no verify");
|
||||
}
|
||||
HARNESS_FORK_PARENT_END();
|
||||
}
|
||||
|
||||
TEST_ERROR_FMT(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(
|
||||
sckClientNew(strNew("localhost"), harnessTlsTestPort(), 500), 500, true,
|
||||
strNewFmt("%s/" TEST_CERTIFICATE_PREFIX ".crt", testRepoPath()),
|
||||
NULL)),
|
||||
CryptoError, "unable to verify certificate presented by 'localhost:%u': [20] unable to get local issuer certificate",
|
||||
harnessTlsTestPort());
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
tlsClientOpen(
|
||||
tlsClientNew(sckClientNew(strNew("localhost"), harnessTlsTestPort(), 500), 500, false, NULL, NULL)),
|
||||
"success on no verify");
|
||||
HARNESS_FORK_END();
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
@ -353,65 +353,79 @@ testRun(void)
|
||||
tlsClientStatLocal = (TlsClientStat){0};
|
||||
TEST_RESULT_PTR(tlsClientStatStr(), NULL, "no stats yet");
|
||||
|
||||
TEST_RESULT_VOID(testTlsServer(), "tls server begin");
|
||||
ioBufferSizeSet(12);
|
||||
HARNESS_FORK_BEGIN()
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, false)
|
||||
{
|
||||
TEST_RESULT_VOID(testTlsServer(), "tls server begin");
|
||||
}
|
||||
HARNESS_FORK_CHILD_END();
|
||||
|
||||
TEST_ASSIGN(
|
||||
client, tlsClientNew(sckClientNew(harnessTlsTestHost(), harnessTlsTestPort(), 500), 500, testContainer(), NULL, NULL),
|
||||
"new client");
|
||||
TEST_RESULT_VOID(tlsClientOpen(client), "open client");
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
ioBufferSizeSet(12);
|
||||
|
||||
const Buffer *input = BUFSTRDEF("some protocol info");
|
||||
TEST_RESULT_VOID(ioWrite(tlsClientIoWrite(client), input), "write input");
|
||||
ioWriteFlush(tlsClientIoWrite(client));
|
||||
TEST_ASSIGN(
|
||||
client,
|
||||
tlsClientNew(sckClientNew(harnessTlsTestHost(), harnessTlsTestPort(), 500), 500, testContainer(), NULL, NULL),
|
||||
"new client");
|
||||
TEST_RESULT_VOID(tlsClientOpen(client), "open client");
|
||||
|
||||
TEST_RESULT_STR_Z(ioReadLine(tlsClientIoRead(client)), "something:0", "read line");
|
||||
TEST_RESULT_BOOL(ioReadEof(tlsClientIoRead(client)), false, " check eof = false");
|
||||
const Buffer *input = BUFSTRDEF("some protocol info");
|
||||
TEST_RESULT_VOID(ioWrite(tlsClientIoWrite(client), input), "write input");
|
||||
ioWriteFlush(tlsClientIoWrite(client));
|
||||
|
||||
Buffer *output = bufNew(12);
|
||||
TEST_RESULT_UINT(ioRead(tlsClientIoRead(client), output), 12, "read output");
|
||||
TEST_RESULT_STR_Z(strNewBuf(output), "some content", " check output");
|
||||
TEST_RESULT_BOOL(ioReadEof(tlsClientIoRead(client)), false, " check eof = false");
|
||||
TEST_RESULT_STR_Z(ioReadLine(tlsClientIoRead(client)), "something:0", "read line");
|
||||
TEST_RESULT_BOOL(ioReadEof(tlsClientIoRead(client)), false, " check eof = false");
|
||||
|
||||
output = bufNew(8);
|
||||
TEST_RESULT_UINT(ioRead(tlsClientIoRead(client), output), 8, "read output");
|
||||
TEST_RESULT_STR_Z(strNewBuf(output), "AND MORE", " check output");
|
||||
TEST_RESULT_BOOL(ioReadEof(tlsClientIoRead(client)), false, " check eof = false");
|
||||
Buffer *output = bufNew(12);
|
||||
TEST_RESULT_UINT(ioRead(tlsClientIoRead(client), output), 12, "read output");
|
||||
TEST_RESULT_STR_Z(strNewBuf(output), "some content", " check output");
|
||||
TEST_RESULT_BOOL(ioReadEof(tlsClientIoRead(client)), false, " check eof = false");
|
||||
|
||||
output = bufNew(12);
|
||||
TEST_ERROR_FMT(
|
||||
ioRead(tlsClientIoRead(client), output), FileReadError,
|
||||
"timeout after 500ms waiting for read from '%s:%u'", strPtr(harnessTlsTestHost()), harnessTlsTestPort());
|
||||
output = bufNew(8);
|
||||
TEST_RESULT_UINT(ioRead(tlsClientIoRead(client), output), 8, "read output");
|
||||
TEST_RESULT_STR_Z(strNewBuf(output), "AND MORE", " check output");
|
||||
TEST_RESULT_BOOL(ioReadEof(tlsClientIoRead(client)), false, " check eof = false");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
input = BUFSTRDEF("more protocol info");
|
||||
TEST_RESULT_VOID(tlsClientOpen(client), "open client again (it is already open)");
|
||||
TEST_RESULT_VOID(ioWrite(tlsClientIoWrite(client), input), "write input");
|
||||
ioWriteFlush(tlsClientIoWrite(client));
|
||||
output = bufNew(12);
|
||||
TEST_ERROR_FMT(
|
||||
ioRead(tlsClientIoRead(client), output), FileReadError,
|
||||
"timeout after 500ms waiting for read from '%s:%u'", strPtr(harnessTlsTestHost()), harnessTlsTestPort());
|
||||
|
||||
output = bufNew(12);
|
||||
TEST_RESULT_UINT(ioRead(tlsClientIoRead(client), output), 12, "read output");
|
||||
TEST_RESULT_STR_Z(strNewBuf(output), "0123456789AB", " check output");
|
||||
TEST_RESULT_BOOL(ioReadEof(tlsClientIoRead(client)), false, " check eof = false");
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
input = BUFSTRDEF("more protocol info");
|
||||
TEST_RESULT_VOID(tlsClientOpen(client), "open client again (it is already open)");
|
||||
TEST_RESULT_VOID(ioWrite(tlsClientIoWrite(client), input), "write input");
|
||||
ioWriteFlush(tlsClientIoWrite(client));
|
||||
|
||||
output = bufNew(12);
|
||||
TEST_RESULT_UINT(ioRead(tlsClientIoRead(client), output), 0, "read no output after eof");
|
||||
TEST_RESULT_BOOL(ioReadEof(tlsClientIoRead(client)), true, " check eof = true");
|
||||
output = bufNew(12);
|
||||
TEST_RESULT_UINT(ioRead(tlsClientIoRead(client), output), 12, "read output");
|
||||
TEST_RESULT_STR_Z(strNewBuf(output), "0123456789AB", " check output");
|
||||
TEST_RESULT_BOOL(ioReadEof(tlsClientIoRead(client)), false, " check eof = false");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_VOID(tlsClientOpen(client), "open client again (was closed by server)");
|
||||
TEST_RESULT_BOOL(tlsWriteContinue(client, -1, SSL_ERROR_WANT_READ, 1), true, "continue on WANT_READ");
|
||||
TEST_RESULT_BOOL(tlsWriteContinue(client, 0, SSL_ERROR_NONE, 1), true, "continue on WANT_READ");
|
||||
TEST_ERROR(
|
||||
tlsWriteContinue(client, 77, 0, 88), FileWriteError,
|
||||
"unable to write to tls, write size 77 does not match expected size 88");
|
||||
TEST_ERROR(tlsWriteContinue(client, 0, SSL_ERROR_ZERO_RETURN, 1), FileWriteError, "unable to write to tls [6]");
|
||||
output = bufNew(12);
|
||||
TEST_RESULT_UINT(ioRead(tlsClientIoRead(client), output), 0, "read no output after eof");
|
||||
TEST_RESULT_BOOL(ioReadEof(tlsClientIoRead(client)), true, " check eof = true");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_BOOL(sckClientStatStr() != NULL, true, "check statistics exist");
|
||||
TEST_RESULT_BOOL(tlsClientStatStr() != NULL, true, "check statistics exist");
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_VOID(tlsClientOpen(client), "open client again (was closed by server)");
|
||||
TEST_RESULT_BOOL(tlsWriteContinue(client, -1, SSL_ERROR_WANT_READ, 1), true, "continue on WANT_READ");
|
||||
TEST_RESULT_BOOL(tlsWriteContinue(client, 0, SSL_ERROR_NONE, 1), true, "continue on WANT_READ");
|
||||
TEST_ERROR(
|
||||
tlsWriteContinue(client, 77, 0, 88), FileWriteError,
|
||||
"unable to write to tls, write size 77 does not match expected size 88");
|
||||
TEST_ERROR(tlsWriteContinue(client, 0, SSL_ERROR_ZERO_RETURN, 1), FileWriteError, "unable to write to tls [6]");
|
||||
|
||||
TEST_RESULT_VOID(tlsClientFree(client), "free client");
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
TEST_RESULT_BOOL(sckClientStatStr() != NULL, true, "check statistics exist");
|
||||
TEST_RESULT_BOOL(tlsClientStatStr() != NULL, true, "check statistics exist");
|
||||
|
||||
TEST_RESULT_VOID(tlsClientFree(client), "free client");
|
||||
}
|
||||
HARNESS_FORK_PARENT_END();
|
||||
}
|
||||
HARNESS_FORK_END();
|
||||
}
|
||||
|
||||
FUNCTION_HARNESS_RESULT_VOID();
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user