pgbackrest.git / summary / log / commit / refs
commit 65858d12dd67f3bf6983ad5c8521edb168da004b
Author: David Steele <david@pgmasters.net>
Date: Mon Aug 10 20:16:11 2020 +0000
Improve server test harness to support multiple protocols/connections.
The prior implementation only supported a single connection on TLS. This is not flexible enough for complex testing scenarios which might require multiple simultaneous connections on different protocols.
Allow multiple simultaneous connections and add plain sockets as a protocol option. Rename the functions used for server scripting to hrnServerScript*() to make it clear they are related. Improve error messages when less input is received by the server than expected.
Also, do a bit of cleanup and add more comments.
test/code-count/file-type.yaml | 16 +-
harnessServer.c} | 258 +++++++++++++---------
test/src/common/harnessServer.h | 83 +++++++
test/src/common/harnessTls.h | 62 ------
test/src/module/common/ioHttpTest.c | 203 ++++++++---------
test/src/module/common/ioTlsTest.c | 127 ++++++-----
test/src/module/storage/azureTest.c | 179 ++++++++-------
test/src/module/storage/s3Test.c | 176 ++++++++-------
8 files changed, 597 insertions(+), 507 deletions(-)
diff --git a/test/code-count/file-type.yaml b/test/code-count/file-type.yaml
index b46f2bdee..d35a4ab97 100644
--- a/test/code-count/file-type.yaml
+++ b/test/code-count/file-type.yaml
@@ -1799,6 +1799,14 @@ test/src/common/harnessPq.h:
class: test/harness
type: c/h
+test/src/common/harnessServer.c:
+ class: test/harness
+ type: c
+
+test/src/common/harnessServer.h:
+ class: test/harness
+ type: c/h
+
test/src/common/harnessStorage.c:
class: test/harness
type: c
@@ -1819,14 +1827,6 @@ test/src/common/harnessTest.intern.h:
class: test/harness
type: c/h
-test/src/common/harnessTls.c:
- class: test/harness
- type: c
-
-test/src/common/harnessTls.h:
- class: test/harness
- type: c/h
-
test/src/module/command/archiveCommonTest.c:
class: test/module
type: c
diff --git a/test/src/common/harnessTls.c b/test/src/common/harnessServer.c
similarity index 52%
rename from test/src/common/harnessTls.c
rename to test/src/common/harnessServer.c
index 148116531..bfcd59c18 100644
--- a/test/src/common/harnessTls.c
+++ b/test/src/common/harnessServer.c
@@ -1,5 +1,5 @@
/***********************************************************************************************************************************
-TLS Test Harness
+Server Test Harness
***********************************************************************************************************************************/
#include <arpa/inet.h>
#include <string.h>
@@ -11,6 +11,7 @@ TLS Test Harness
#include "common/crypto/common.h"
#include "common/error.h"
+#include "common/io/socket/common.h"
#include "common/io/socket/session.h"
#include "common/io/tls/session.h"
#include "common/log.h"
@@ -19,198 +20,208 @@ TLS Test Harness
#include "common/wait.h"
#include "common/harnessDebug.h"
+#include "common/harnessServer.h"
#include "common/harnessTest.h"
-#include "common/harnessTls.h"
/***********************************************************************************************************************************
Command enum
***********************************************************************************************************************************/
typedef enum
{
- hrnTlsCmdAbort,
- hrnTlsCmdAccept,
- hrnTlsCmdClose,
- hrnTlsCmdDone,
- hrnTlsCmdExpect,
- hrnTlsCmdReply,
- hrnTlsCmdSleep,
-} HrnTlsCmd;
+ hrnServerCmdAbort,
+ hrnServerCmdAccept,
+ hrnServerCmdClose,
+ hrnServerCmdDone,
+ hrnServerCmdExpect,
+ hrnServerCmdReply,
+ hrnServerCmdSleep,
+} HrnServerCmd;
/***********************************************************************************************************************************
Constants
***********************************************************************************************************************************/
-#define TLS_TEST_HOST "tls.test.pgbackrest.org"
-#define TLS_CERT_TEST_KEY TLS_CERT_FAKE_PATH "/pgbackrest-test.key"
-
-/***********************************************************************************************************************************
-Local variables
-***********************************************************************************************************************************/
-static struct
-{
- IoWrite *clientWrite; // Write interface for client to send commands to the server
-} hrnTlsLocal;
+#define HRN_SERVER_HOST "tls.test.pgbackrest.org"
+#define HRN_SERVER_FAKE_CERT_PATH "/etc/fake-cert"
+#define HRN_SERVER_FAKE_KEY_FILE HRN_SERVER_FAKE_CERT_PATH "/pgbackrest-test.key"
+#define HRN_SERVER_FAKE_CERT_FILE HRN_SERVER_FAKE_CERT_PATH "/pgbackrest-test.crt"
/***********************************************************************************************************************************
Send commands to the server
***********************************************************************************************************************************/
static void
-hrnTlsServerCommand(HrnTlsCmd cmd, const Variant *data)
+hrnServerScriptCommand(IoWrite *write, HrnServerCmd cmd, const Variant *data)
{
FUNCTION_HARNESS_BEGIN();
+ FUNCTION_HARNESS_PARAM(IO_WRITE, write);
FUNCTION_HARNESS_PARAM(ENUM, cmd);
FUNCTION_HARNESS_PARAM(VARIANT, data);
FUNCTION_HARNESS_END();
- ASSERT(hrnTlsLocal.clientWrite != NULL);
+ ASSERT(write != NULL);
- ioWriteStrLine(hrnTlsLocal.clientWrite, jsonFromUInt(cmd));
- ioWriteStrLine(hrnTlsLocal.clientWrite, jsonFromVar(data));
- ioWriteFlush(hrnTlsLocal.clientWrite);
+ ioWriteStrLine(write, jsonFromUInt(cmd));
+ ioWriteStrLine(write, jsonFromVar(data));
+ ioWriteFlush(write);
FUNCTION_HARNESS_RESULT_VOID();
}
/**********************************************************************************************************************************/
-void hrnTlsClientBegin(IoWrite *write)
+IoWrite *hrnServerScriptBegin(IoWrite *write)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(IO_WRITE, write);
FUNCTION_HARNESS_END();
- ASSERT(hrnTlsLocal.clientWrite == NULL);
ASSERT(write != NULL);
- hrnTlsLocal.clientWrite = write;
+ write = write;
ioWriteOpen(write);
- FUNCTION_HARNESS_RESULT_VOID();
+ FUNCTION_HARNESS_RESULT(IO_WRITE, write);
}
-void hrnTlsClientEnd(void)
+void hrnServerScriptEnd(IoWrite *write)
{
- FUNCTION_HARNESS_VOID();
+ FUNCTION_HARNESS_BEGIN();
+ FUNCTION_HARNESS_PARAM(IO_WRITE, write);
+ FUNCTION_HARNESS_END();
- ASSERT(hrnTlsLocal.clientWrite != NULL);
+ ASSERT(write != NULL);
- hrnTlsServerCommand(hrnTlsCmdDone, NULL);
- hrnTlsLocal.clientWrite = NULL;
+ hrnServerScriptCommand(write, hrnServerCmdDone, NULL);
FUNCTION_HARNESS_RESULT_VOID();
}
/**********************************************************************************************************************************/
void
-hrnTlsServerAbort(void)
+hrnServerScriptAbort(IoWrite *write)
{
- FUNCTION_HARNESS_VOID();
+ FUNCTION_HARNESS_BEGIN();
+ FUNCTION_HARNESS_PARAM(IO_WRITE, write);
+ FUNCTION_HARNESS_END();
- hrnTlsServerCommand(hrnTlsCmdAbort, NULL);
+ hrnServerScriptCommand(write, hrnServerCmdAbort, NULL);
FUNCTION_HARNESS_RESULT_VOID();
}
void
-hrnTlsServerAccept(void)
+hrnServerScriptAccept(IoWrite *write)
{
- FUNCTION_HARNESS_VOID();
+ FUNCTION_HARNESS_BEGIN();
+ FUNCTION_HARNESS_PARAM(IO_WRITE, write);
+ FUNCTION_HARNESS_END();
- hrnTlsServerCommand(hrnTlsCmdAccept, NULL);
+ hrnServerScriptCommand(write, hrnServerCmdAccept, NULL);
FUNCTION_HARNESS_RESULT_VOID();
}
void
-hrnTlsServerClose()
+hrnServerScriptClose(IoWrite *write)
{
- FUNCTION_HARNESS_VOID();
+ FUNCTION_HARNESS_BEGIN();
+ FUNCTION_HARNESS_PARAM(IO_WRITE, write);
+ FUNCTION_HARNESS_END();
- hrnTlsServerCommand(hrnTlsCmdClose, NULL);
+ hrnServerScriptCommand(write, hrnServerCmdClose, NULL);
FUNCTION_HARNESS_RESULT_VOID();
}
void
-hrnTlsServerExpect(const String *data)
+hrnServerScriptExpect(IoWrite *write, const String *data)
{
FUNCTION_HARNESS_BEGIN();
+ FUNCTION_HARNESS_PARAM(IO_WRITE, write);
FUNCTION_HARNESS_PARAM(STRING, data);
FUNCTION_HARNESS_END();
ASSERT(data != NULL);
- hrnTlsServerCommand(hrnTlsCmdExpect, VARSTR(data));
+ hrnServerScriptCommand(write, hrnServerCmdExpect, VARSTR(data));
FUNCTION_HARNESS_RESULT_VOID();
}
void
-hrnTlsServerExpectZ(const char *data)
+hrnServerScriptExpectZ(IoWrite *write, const char *data)
{
FUNCTION_HARNESS_BEGIN();
+ FUNCTION_HARNESS_PARAM(IO_WRITE, write);
FUNCTION_HARNESS_PARAM(STRINGZ, data);
FUNCTION_HARNESS_END();
ASSERT(data != NULL);
- hrnTlsServerCommand(hrnTlsCmdExpect, VARSTRZ(data));
+ hrnServerScriptCommand(write, hrnServerCmdExpect, VARSTRZ(data));
FUNCTION_HARNESS_RESULT_VOID();
}
void
-hrnTlsServerReply(const String *data)
+hrnServerScriptReply(IoWrite *write, const String *data)
{
FUNCTION_HARNESS_BEGIN();
+ FUNCTION_HARNESS_PARAM(IO_WRITE, write);
FUNCTION_HARNESS_PARAM(STRING, data);
FUNCTION_HARNESS_END();
ASSERT(data != NULL);
- hrnTlsServerCommand(hrnTlsCmdReply, VARSTR(data));
+ hrnServerScriptCommand(write, hrnServerCmdReply, VARSTR(data));
FUNCTION_HARNESS_RESULT_VOID();
}
void
-hrnTlsServerReplyZ(const char *data)
+hrnServerScriptReplyZ(IoWrite *write, const char *data)
{
FUNCTION_HARNESS_BEGIN();
+ FUNCTION_HARNESS_PARAM(IO_WRITE, write);
FUNCTION_HARNESS_PARAM(STRINGZ, data);
FUNCTION_HARNESS_END();
ASSERT(data != NULL);
- hrnTlsServerCommand(hrnTlsCmdReply, VARSTRZ(data));
+ hrnServerScriptCommand(write, hrnServerCmdReply, VARSTRZ(data));
FUNCTION_HARNESS_RESULT_VOID();
}
void
-hrnTlsServerSleep(TimeMSec sleepMs)
+hrnServerScriptSleep(IoWrite *write, TimeMSec sleepMs)
{
FUNCTION_HARNESS_BEGIN();
+ FUNCTION_HARNESS_PARAM(IO_WRITE, write);
FUNCTION_HARNESS_PARAM(TIME_MSEC, sleepMs);
FUNCTION_HARNESS_END();
ASSERT(sleepMs > 0);
- hrnTlsServerCommand(hrnTlsCmdSleep, VARUINT64(sleepMs));
+ hrnServerScriptCommand(write, hrnServerCmdSleep, VARUINT64(sleepMs));
FUNCTION_HARNESS_RESULT_VOID();
}
/**********************************************************************************************************************************/
-void hrnTlsServerRunParam(IoRead *read, const String *certificate, const String *key)
+void hrnServerRun(IoRead *read, HrnServerProtocol protocol, HrnServerRunParam param)
{
FUNCTION_HARNESS_BEGIN();
FUNCTION_HARNESS_PARAM(IO_READ, read);
- FUNCTION_HARNESS_PARAM(STRING, certificate);
- FUNCTION_HARNESS_PARAM(STRING, key);
+ FUNCTION_HARNESS_PARAM(ENUM, protocol);
+ FUNCTION_HARNESS_PARAM(UINT, param.port);
+ FUNCTION_HARNESS_PARAM(STRING, param.certificate);
+ FUNCTION_HARNESS_PARAM(STRING, param.key);
FUNCTION_HARNESS_END();
ASSERT(read != NULL);
- ASSERT(certificate != NULL);
- ASSERT(key != NULL);
+
+ // Set port to index 0 if not specified
+ if (param.port == 0)
+ param.port = hrnServerPort(0);
// Open read connection to client
ioReadOpen(read);
@@ -218,24 +229,51 @@ void hrnTlsServerRunParam(IoRead *read, const String *certificate, const String
// Add test hosts
if (testContainer())
{
- if (system("echo \"127.0.0.1 " TLS_TEST_HOST "\" | sudo tee -a /etc/hosts > /dev/null") != 0)
+ if (system("echo \"127.0.0.1 " HRN_SERVER_HOST "\" | sudo tee -a /etc/hosts > /dev/null") != 0)
THROW(AssertError, "unable to add test host to /etc/hosts");
}
// Initialize ssl and create a context
- cryptoInit();
+ SSL_CTX *serverContext = NULL;
- const SSL_METHOD *method = SSLv23_method();
- cryptoError(method == NULL, "unable to load TLS method");
+ if (protocol == hrnServerProtocolTls)
+ {
+ ASSERT((param.certificate != NULL && param.key != NULL) || (param.certificate == NULL && param.key == NULL));
- SSL_CTX *serverContext = SSL_CTX_new(method);
- cryptoError(serverContext == NULL, "unable to create TLS context");
+ // If certificate and key are not set then use defaults
+ if (param.certificate == NULL)
+ {
+ // If running in a container use the installed certificate
+ if (testContainer())
+ {
+ param.certificate = strNew(HRN_SERVER_FAKE_CERT_FILE);
+ param.key = strNew(HRN_SERVER_FAKE_KEY_FILE);
+ }
+ // Else use a certificate from the test path -- tests will need to disable verify
+ else
+ {
+ param.certificate = strNewFmt("%s/" HRN_SERVER_CERT_PREFIX ".crt", testRepoPath());
+ param.key = strNewFmt("%s/" HRN_SERVER_CERT_PREFIX ".key", testRepoPath());
+ }
+ }
+
+ // Initialize TLS
+ cryptoInit();
- // Configure the context by setting key and cert
- cryptoError(
- SSL_CTX_use_certificate_file(serverContext, strZ(certificate), SSL_FILETYPE_PEM) <= 0, "unable to load server certificate");
- cryptoError(
- SSL_CTX_use_PrivateKey_file(serverContext, strZ(key), SSL_FILETYPE_PEM) <= 0, "unable to load server private key");
+ const SSL_METHOD *method = SSLv23_method();
+ cryptoError(method == NULL, "unable to load TLS method");
+
+ serverContext = SSL_CTX_new(method);
+ cryptoError(serverContext == NULL, "unable to create TLS context");
+
+ // Configure the context by setting key and cert
+ cryptoError(
+ SSL_CTX_use_certificate_file(serverContext, strZ(param.certificate), SSL_FILETYPE_PEM) <= 0,
+ "unable to load server certificate");
+ cryptoError(
+ SSL_CTX_use_PrivateKey_file(serverContext, strZ(param.key), SSL_FILETYPE_PEM) <= 0,
+ "unable to load server private key");
+ }
// Create the socket
int serverSocket;
@@ -243,7 +281,7 @@ void hrnTlsServerRunParam(IoRead *read, const String *certificate, const String
struct sockaddr_in address;
address.sin_family = AF_INET;
- address.sin_port = htons((uint16_t)hrnTlsServerPort());
+ address.sin_port = htons((uint16_t)param.port);
address.sin_addr.s_addr = htonl(INADDR_ANY);
if ((serverSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
@@ -276,21 +314,25 @@ void hrnTlsServerRunParam(IoRead *read, const String *certificate, const String
do
{
- HrnTlsCmd cmd = jsonToUInt(ioReadLine(read));
+ HrnServerCmd cmd = jsonToUInt(ioReadLine(read));
const Variant *data = jsonToVar(ioReadLine(read));
switch (cmd)
{
- case hrnTlsCmdAbort:
+ case hrnServerCmdAbort:
{
+ // Only makes since to abort in TLS, otherwise it is just a close
+ ASSERT(protocol == hrnServerProtocolTls);
+
ioSessionFree(serverSession);
serverSession = NULL;
break;
}
- case hrnTlsCmdAccept:
+ case hrnServerCmdAccept:
{
+ // Accept the socket connection
struct sockaddr_in addr;
unsigned int len = sizeof(addr);
@@ -299,18 +341,24 @@ void hrnTlsServerRunParam(IoRead *read, const String *certificate, const String
if (testClientSocket < 0)
THROW_SYS_ERROR(AssertError, "unable to accept socket");
- SSL *testClientSSL = SSL_new(serverContext);
+ // Create socket session
+ sckOptionSet(testClientSocket);
+ serverSession = sckSessionNew(ioSessionRoleServer, testClientSocket, STRDEF("localhost"), param.port, 5000);
- serverSession = tlsSessionNew(
- testClientSSL, sckSessionNew(ioSessionRoleServer, testClientSocket, STRDEF("client"), 0, 5000), 5000);
+ // Start TLS if requested
+ if (protocol == hrnServerProtocolTls)
+ {
+ SSL *testClientSSL = SSL_new(serverContext);
+ serverSession = tlsSessionNew(testClientSSL, serverSession, 5000);
+ }
break;
}
- case hrnTlsCmdClose:
+ case hrnServerCmdClose:
{
if (serverSession == NULL)
- THROW(AssertError, "TLS session is already closed");
+ THROW(AssertError, "session is already closed");
ioSessionClose(serverSession);
ioSessionFree(serverSession);
@@ -319,19 +367,30 @@ void hrnTlsServerRunParam(IoRead *read, const String *certificate, const String
break;
}
- case hrnTlsCmdDone:
+ case hrnServerCmdDone:
{
done = true;
-
break;
}
- case hrnTlsCmdExpect:
+ case hrnServerCmdExpect:
{
const String *expected = varStr(data);
+
+ // Read as much as possible
Buffer *buffer = bufNew(strSize(expected));
- ioRead(ioSessionIoRead(serverSession), buffer);
+ TRY_BEGIN()
+ {
+ ioRead(ioSessionIoRead(serverSession), buffer);
+ }
+ CATCH(FileReadError)
+ {
+ // If nothing was read then throw the original error
+ if (bufUsed(buffer) == 0)
+ THROW_FMT(AssertError, "server expected '%s' but got EOF", strZ(expected));
+ }
+ TRY_END();
// Treat any ? characters as wildcards so variable elements (e.g. auth hashes) can be ignored
String *actual = strNewBuf(buffer);
@@ -349,7 +408,7 @@ void hrnTlsServerRunParam(IoRead *read, const String *certificate, const String
break;
}
- case hrnTlsCmdReply:
+ case hrnServerCmdReply:
{
ioWrite(ioSessionIoWrite(serverSession), BUFSTR(varStr(data)));
ioWriteFlush(ioSessionIoWrite(serverSession));
@@ -357,7 +416,7 @@ void hrnTlsServerRunParam(IoRead *read, const String *certificate, const String
break;
}
- case hrnTlsCmdSleep:
+ case hrnServerCmdSleep:
{
sleepMSec(varUInt64Force(data));
@@ -368,37 +427,22 @@ void hrnTlsServerRunParam(IoRead *read, const String *certificate, const String
while (!done);
// Free TLS context
- SSL_CTX_free(serverContext);
-
- FUNCTION_HARNESS_RESULT_VOID();
-}
-
-void hrnTlsServerRun(IoRead *read)
-{
- FUNCTION_HARNESS_BEGIN();
- FUNCTION_HARNESS_PARAM(IO_READ, read);
- FUNCTION_HARNESS_END();
-
- if (testContainer())
- hrnTlsServerRunParam(read, STRDEF(TLS_CERT_TEST_CERT), STRDEF(TLS_CERT_TEST_KEY));
- else
- {
- hrnTlsServerRunParam(
- read, strNewFmt("%s/" TEST_CERTIFICATE_PREFIX ".crt", testRepoPath()),
- strNewFmt("%s/" TEST_CERTIFICATE_PREFIX ".key", testRepoPath()));
- }
+ if (protocol == hrnServerProtocolTls)
+ SSL_CTX_free(serverContext);
FUNCTION_HARNESS_RESULT_VOID();
}
/**********************************************************************************************************************************/
-const String *hrnTlsServerHost(void)
+const String *hrnServerHost(void)
{
- return strNew(testContainer() ? TLS_TEST_HOST : "127.0.0.1");
+ return strNew(testContainer() ? HRN_SERVER_HOST : "127.0.0.1");
}
/**********************************************************************************************************************************/
-unsigned int hrnTlsServerPort(void)
+unsigned int hrnServerPort(unsigned int portIdx)
{
- return 44443 + testIdx();
+ ASSERT(portIdx < HRN_SERVER_PORT_MAX);
+
+ return 44443 + (HRN_SERVER_PORT_MAX * testIdx()) + portIdx;
}
diff --git a/test/src/common/harnessServer.h b/test/src/common/harnessServer.h
new file mode 100644
index 000000000..bf5c1c2eb
--- /dev/null
+++ b/test/src/common/harnessServer.h
@@ -0,0 +1,83 @@
+/***********************************************************************************************************************************
+Server Test Harness
+
+Simple server for testing client functionality using multiple protocols and connections. Server behavior can be scripted from the
+client using the hrnServerScript() functions.
+***********************************************************************************************************************************/
+#ifndef TEST_COMMON_HARNESS_SERVER_H
+#define TEST_COMMON_HARNESS_SERVER_H
+
+#include "common/io/read.h"
+#include "common/io/write.h"
+
+/***********************************************************************************************************************************
+Server protocol type
+***********************************************************************************************************************************/
+typedef enum
+{
+ hrnServerProtocolSocket,
+ hrnServerProtocolTls,
+} HrnServerProtocol;
+
+/***********************************************************************************************************************************
+Maximum number of ports allowed for each test
+***********************************************************************************************************************************/
+#define HRN_SERVER_PORT_MAX 4
+
+/***********************************************************************************************************************************
+Path and prefix for test certificates
+***********************************************************************************************************************************/
+#define HRN_SERVER_CERT_PREFIX "test/certificate/pgbackrest-test"
+
+/***********************************************************************************************************************************
+Functions
+***********************************************************************************************************************************/
+// Run server
+typedef struct HrnServerRunParam
+{
+ VAR_PARAM_HEADER;
+ unsigned int port; // Server port, defaults to hrnServerPort(0)
+ const String *certificate; // TLS certificate when protocol = hrnServerProtocolTls
+ const String *key; // TLS key when protocol = hrnServerProtocolTls
+} HrnServerRunParam;
+
+#define hrnServerRunP(read, protocol, ...) \
+ hrnServerRun(read, protocol, (HrnServerRunParam){VAR_PARAM_INIT, __VA_ARGS__})
+
+void hrnServerRun(IoRead *read, HrnServerProtocol protocol, HrnServerRunParam param);
+
+// Begin/end server script
+IoWrite *hrnServerScriptBegin(IoWrite *write);
+void hrnServerScriptEnd(IoWrite *write);
+
+// Abort the server session (i.e. don't perform proper TLS shutdown)
+void hrnServerScriptAbort(IoWrite *write);
+
+// Accept new connection
+void hrnServerScriptAccept(IoWrite *write);
+
+// Close the connection
+void hrnServerScriptClose(IoWrite *write);
+
+// Expect the specfified string
+void hrnServerScriptExpect(IoWrite *write, const String *data);
+void hrnServerScriptExpectZ(IoWrite *write, const char *data);
+
+// Reply with the specfified string
+void hrnServerScriptReply(IoWrite *write, const String *data);
+void hrnServerScriptReplyZ(IoWrite *write, const char *data);
+
+// Sleep specfified milliseconds
+void hrnServerScriptSleep(IoWrite *write, TimeMSec sleepMs);
+
+/***********************************************************************************************************************************
+Getters/Setters
+***********************************************************************************************************************************/
+// Hostname to use for testing -- this will vary based on whether the test is running in a container
+const String *hrnServerHost(void);
+
+// Port to use for testing. This will be unique for each test running in parallel to avoid conflicts. A range is allocated to each
+// test so multiple ports can be requested.
+unsigned int hrnServerPort(unsigned int portIdx);
+
+#endif
diff --git a/test/src/common/harnessTls.h b/test/src/common/harnessTls.h
deleted file mode 100644
index 0e6cec47a..000000000
--- a/test/src/common/harnessTls.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/***********************************************************************************************************************************
-TLS Test Harness
-
-Simple TLS server for testing TLS client functionality.
-***********************************************************************************************************************************/
-#ifndef TEST_COMMON_HARNESS_TLS_H
-#define TEST_COMMON_HARNESS_TLS_H
-
-#include "common/debug.h"
-#include "common/io/tls/session.h"
-
-/***********************************************************************************************************************************
-Path and prefix for test certificates
-***********************************************************************************************************************************/
-#define TEST_CERTIFICATE_PREFIX "test/certificate/pgbackrest-test"
-
-/***********************************************************************************************************************************
-TLS test defaults
-***********************************************************************************************************************************/
-#define TLS_CERT_FAKE_PATH "/etc/fake-cert"
-#define TLS_CERT_TEST_CERT TLS_CERT_FAKE_PATH "/pgbackrest-test.crt"
-
-/***********************************************************************************************************************************
-Functions
-***********************************************************************************************************************************/
-// Begin/end client
-void hrnTlsClientBegin(IoWrite *write);
-void hrnTlsClientEnd(void);
-
-// Run server
-void hrnTlsServerRun(IoRead *read);
-
-// Abort the server session (i.e. don't perform proper TLS shutdown)
-void hrnTlsServerAbort(void);
-
-// Accept new TLS connection
-void hrnTlsServerAccept(void);
-
-// Close the TLS connection
-void hrnTlsServerClose(void);
-
-// Expect the specfified string
-void hrnTlsServerExpect(const String *data);
-void hrnTlsServerExpectZ(const char *data);
-
-// Reply with the specfified string
-void hrnTlsServerReply(const String *data);
-void hrnTlsServerReplyZ(const char *data);
-
-// Sleep specfified milliseconds
-void hrnTlsServerSleep(TimeMSec sleepMs);
-
-/***********************************************************************************************************************************
-Getters/Setters
-***********************************************************************************************************************************/
-// Hostname to use for testing -- this will vary based on whether the test is running in a container
-const String *hrnTlsServerHost(void);
-
-// Port to use for testing. This will be unique for each test running in parallel to avoid conflicts
-unsigned int hrnTlsServerPort(void);
-
-#endif
diff --git a/test/src/module/common/ioHttpTest.c b/test/src/module/common/ioHttpTest.c
index f6a02d30d..a8ce0901e 100644
--- a/test/src/module/common/ioHttpTest.c
+++ b/test/src/module/common/ioHttpTest.c
@@ -9,7 +9,7 @@ Test HTTP
#include "common/io/socket/client.h"
#include "common/harnessFork.h"
-#include "common/harnessTls.h"
+#include "common/harnessServer.h"
/***********************************************************************************************************************************
Test Run
@@ -177,17 +177,11 @@ testRun(void)
TEST_RESULT_STR(httpClientStatStr(), NULL, "no stats yet");
- TEST_ASSIGN(
- client,
- httpClientNew(
- tlsClientNew(
- sckClientNew(strNew("localhost"), hrnTlsServerPort(), 500), strNew("X"), 500, testContainer(), NULL, NULL),
- 500),
- "new client");
+ TEST_ASSIGN(client, httpClientNew(sckClientNew(strNew("localhost"), hrnServerPort(0), 500), 500), "new client");
TEST_ERROR_FMT(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), HostConnectError,
- "unable to connect to 'localhost:%u': [111] Connection refused", hrnTlsServerPort());
+ "unable to connect to 'localhost:%u': [111] Connection refused", hrnServerPort(0));
HARNESS_FORK_BEGIN()
{
@@ -195,40 +189,35 @@ testRun(void)
{
// Start HTTP test server
TEST_RESULT_VOID(
- hrnTlsServerRun(ioFdReadNew(strNew("test server read"), HARNESS_FORK_CHILD_READ(), 5000)),
- "HTTP server begin");
+ hrnServerRunP(
+ ioFdReadNew(strNew("test server read"), HARNESS_FORK_CHILD_READ(), 5000), hrnServerProtocolSocket),
+ "http server run");
}
HARNESS_FORK_CHILD_END();
HARNESS_FORK_PARENT_BEGIN()
{
- hrnTlsClientBegin(ioFdWriteNew(strNew("test client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000));
+ IoWrite *http = hrnServerScriptBegin(
+ ioFdWriteNew(strNew("test client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000));
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("create client");
ioBufferSizeSet(35);
- TEST_ASSIGN(
- client,
- httpClientNew(
- tlsClientNew(
- sckClientNew(hrnTlsServerHost(), hrnTlsServerPort(), 5000), hrnTlsServerHost(), 5000, testContainer(),
- NULL, NULL),
- 5000),
- "new client");
+ TEST_ASSIGN(client, httpClientNew(sckClientNew(hrnServerHost(), hrnServerPort(0), 5000), 5000), "new client");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("no output from server");
client->timeout = 0;
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerSleep(600);
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptSleep(http, 600);
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ERROR(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), FileReadError,
@@ -237,12 +226,12 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("no CR at end of status");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.0 200 OK\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.0 200 OK\n");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ERROR(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), FormatError,
@@ -251,12 +240,12 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("status too short");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.0 200\r\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.0 200\r\n");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ERROR(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), FormatError,
@@ -265,12 +254,12 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("invalid HTTP version");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.0 200 OK\r\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.0 200 OK\r\n");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ERROR(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), FormatError,
@@ -279,12 +268,12 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("no space in status");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200OK\r\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200OK\r\n");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ERROR(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), FormatError,
@@ -293,12 +282,12 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("unexpected end of headers");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\n");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ERROR(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), FileReadError,
@@ -307,12 +296,12 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("missing colon in header");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\nheader-value\r\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\nheader-value\r\n");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ERROR(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), FormatError,
@@ -321,12 +310,12 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("invalid transfer encoding");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\ntransfer-encoding:bogus\r\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\ntransfer-encoding:bogus\r\n");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ERROR(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), FormatError,
@@ -335,12 +324,12 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("content length and transfer encoding both set");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\ntransfer-encoding:chunked\r\ncontent-length:777\r\n\r\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\ntransfer-encoding:chunked\r\ncontent-length:777\r\n\r\n");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ERROR(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), FormatError,
@@ -349,12 +338,12 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("5xx error with no retry");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 503 Slow Down\r\n\r\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 503 Slow Down\r\n\r\n");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ERROR(
httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/")), false), ServiceError,
@@ -363,16 +352,17 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("request with no content (with an internal error)");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET /?name=%2Fpath%2FA%20Z.txt&type=test HTTP/1.1\r\nhost:myhost.com\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 500 Internal Error\r\nConnection:close\r\n\r\n");
+ hrnServerScriptExpectZ(http, "GET /?name=%2Fpath%2FA%20Z.txt&type=test HTTP/1.1\r\nhost:myhost.com\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 500 Internal Error\r\nConnection:close\r\n\r\n");
- hrnTlsServerClose();
- hrnTlsServerAccept();
+ hrnServerScriptClose(http);
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET /?name=%2Fpath%2FA%20Z.txt&type=test HTTP/1.1\r\nhost:myhost.com\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\nkey1:0\r\n key2 : value2\r\nConnection:ack\r\ncontent-length:0\r\n\r\n");
+ hrnServerScriptExpectZ(http, "GET /?name=%2Fpath%2FA%20Z.txt&type=test HTTP/1.1\r\nhost:myhost.com\r\n\r\n");
+ hrnServerScriptReplyZ(
+ http, "HTTP/1.1 200 OK\r\nkey1:0\r\n key2 : value2\r\nConnection:ack\r\ncontent-length:0\r\n\r\n");
HttpHeader *headerRequest = httpHeaderNew(NULL);
httpHeaderAdd(headerRequest, strNew("host"), strNew("myhost.com"));
@@ -419,8 +409,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("head request with content-length but no content");
- hrnTlsServerExpectZ("HEAD / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\ncontent-length:380\r\n\r\n");
+ hrnServerScriptExpectZ(http, "HEAD / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\ncontent-length:380\r\n\r\n");
TEST_ASSIGN(response, httpRequestResponse(httpRequestNewP(client, strNew("HEAD"), strNew("/")), true), "request");
TEST_RESULT_UINT(httpResponseCode(response), 200, "check response code");
@@ -433,8 +423,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("head request with transfer encoding but no content");
- hrnTlsServerExpectZ("HEAD / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
+ hrnServerScriptExpectZ(http, "HEAD / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
TEST_ASSIGN(response, httpRequestResponse(httpRequestNewP(client, strNew("HEAD"), strNew("/")), true), "request");
TEST_RESULT_UINT(httpResponseCode(response), 200, "check response code");
@@ -447,10 +437,10 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("head request with connection close but no content");
- hrnTlsServerExpectZ("HEAD / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\nConnection:close\r\n\r\n");
+ hrnServerScriptExpectZ(http, "HEAD / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\nConnection:close\r\n\r\n");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ASSIGN(response, httpRequestResponse(httpRequestNewP(client, strNew("HEAD"), strNew("/")), true), "request");
TEST_RESULT_UINT(httpResponseCode(response), 200, "check response code");
@@ -463,22 +453,23 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("error with content (with a few slow down errors)");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 503 Slow Down\r\ncontent-length:3\r\nConnection:close\r\n\r\n123");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 503 Slow Down\r\ncontent-length:3\r\nConnection:close\r\n\r\n123");
- hrnTlsServerClose();
- hrnTlsServerAccept();
+ hrnServerScriptClose(http);
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 503 Slow Down\r\nTransfer-Encoding:chunked\r\nConnection:close\r\n\r\n0\r\n\r\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(
+ http, "HTTP/1.1 503 Slow Down\r\nTransfer-Encoding:chunked\r\nConnection:close\r\n\r\n0\r\n\r\n");
- hrnTlsServerClose();
- hrnTlsServerAccept();
+ hrnServerScriptClose(http);
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 404 Not Found\r\n\r\n");
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 404 Not Found\r\n\r\n");
TEST_ASSIGN(request, httpRequestNewP(client, strNew("GET"), strNew("/")), "request");
TEST_ASSIGN(response, httpRequestResponse(request, false), "response");
@@ -497,8 +488,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("error with content");
- hrnTlsServerExpectZ("GET /?a=b HTTP/1.1\r\nhdr1:1\r\nhdr2:2\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 403 \r\ncontent-length:7\r\n\r\nCONTENT");
+ hrnServerScriptExpectZ(http, "GET /?a=b HTTP/1.1\r\nhdr1:1\r\nhdr2:2\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 403 \r\ncontent-length:7\r\n\r\nCONTENT");
StringList *headerRedact = strLstNew();
strLstAdd(headerRedact, STRDEF("hdr2"));
@@ -535,10 +526,11 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("request with content using content-length");
- hrnTlsServerExpectZ("GET /path/file%201.txt HTTP/1.1\r\ncontent-length:30\r\n\r\n012345678901234567890123456789");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\nConnection:close\r\n\r\n01234567890123456789012345678901");
+ hrnServerScriptExpectZ(
+ http, "GET /path/file%201.txt HTTP/1.1\r\ncontent-length:30\r\n\r\n012345678901234567890123456789");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\nConnection:close\r\n\r\n01234567890123456789012345678901");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
ioBufferSizeSet(30);
@@ -558,16 +550,16 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("request with eof before content complete with retry");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET /path/file%201.txt HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\ncontent-length:32\r\n\r\n0123456789012345678901234567890");
+ hrnServerScriptExpectZ(http, "GET /path/file%201.txt HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\ncontent-length:32\r\n\r\n0123456789012345678901234567890");
- hrnTlsServerClose();
- hrnTlsServerAccept();
+ hrnServerScriptClose(http);
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET /path/file%201.txt HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\ncontent-length:32\r\n\r\n01234567890123456789012345678901");
+ hrnServerScriptExpectZ(http, "GET /path/file%201.txt HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\ncontent-length:32\r\n\r\n01234567890123456789012345678901");
TEST_ASSIGN(
response, httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/path/file 1.txt")), true),
@@ -578,10 +570,10 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("request with eof before content complete");
- hrnTlsServerExpectZ("GET /path/file%201.txt HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ("HTTP/1.1 200 OK\r\ncontent-length:32\r\n\r\n0123456789012345678901234567890");
+ hrnServerScriptExpectZ(http, "GET /path/file%201.txt HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(http, "HTTP/1.1 200 OK\r\ncontent-length:32\r\n\r\n0123456789012345678901234567890");
- hrnTlsServerClose();
+ hrnServerScriptClose(http);
TEST_ASSIGN(
response, httpRequestResponse(httpRequestNewP(client, strNew("GET"), strNew("/path/file 1.txt")), false),
@@ -593,10 +585,11 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("request with chunked content");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(http);
- hrnTlsServerExpectZ("GET / HTTP/1.1\r\n\r\n");
- hrnTlsServerReplyZ(
+ hrnServerScriptExpectZ(http, "GET / HTTP/1.1\r\n\r\n");
+ hrnServerScriptReplyZ(
+ http,
"HTTP/1.1 200 OK\r\nTransfer-Encoding:chunked\r\n\r\n"
"20\r\n01234567890123456789012345678901\r\n"
"10\r\n0123456789012345\r\n"
@@ -614,8 +607,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("close connection and end server process");
- hrnTlsServerClose();
- hrnTlsClientEnd();
+ hrnServerScriptClose(http);
+ hrnServerScriptEnd(http);
}
HARNESS_FORK_PARENT_END();
}
diff --git a/test/src/module/common/ioTlsTest.c b/test/src/module/common/ioTlsTest.c
index 1a3d9dff6..fe1bea75d 100644
--- a/test/src/module/common/ioTlsTest.c
+++ b/test/src/module/common/ioTlsTest.c
@@ -8,12 +8,7 @@ Test Tls Client
#include "common/io/fdWrite.h"
#include "common/harnessFork.h"
-#include "common/harnessTls.h"
-
-/***********************************************************************************************************************************
-Version that allows custom certs
-***********************************************************************************************************************************/
-void hrnTlsServerRunParam(IoRead *read, const String *certificate, const String *key);
+#include "common/harnessServer.h"
/***********************************************************************************************************************************
Test Run
@@ -184,14 +179,14 @@ testRun(void)
{
IoClient *client = NULL;
- TEST_ASSIGN(client, sckClientNew(strNew("localhost"), hrnTlsServerPort(), 100), "new client");
+ TEST_ASSIGN(client, sckClientNew(strNew("localhost"), hrnServerPort(0), 100), "new client");
TEST_ERROR_FMT(
ioClientOpen(client), HostConnectError, "unable to connect to 'localhost:%u': [111] Connection refused",
- hrnTlsServerPort());
+ hrnServerPort(0));
// This address should not be in use in a test environment -- if it is the test will fail
- TEST_ASSIGN(client, sckClientNew(strNew("172.31.255.255"), hrnTlsServerPort(), 100), "new client");
- TEST_ERROR_FMT(ioClientOpen(client), HostConnectError, "timeout connecting to '172.31.255.255:%u'", hrnTlsServerPort());
+ TEST_ASSIGN(client, sckClientNew(strNew("172.31.255.255"), hrnServerPort(0), 100), "new client");
+ TEST_ERROR_FMT(ioClientOpen(client), HostConnectError, "timeout connecting to '172.31.255.255:%u'", hrnServerPort(0));
}
// Additional coverage not provided by testing with actual certificates
@@ -226,11 +221,11 @@ testRun(void)
ioClientOpen(client), HostConnectError, "unable to get address for '99.99.99.99.99': [-2] Name or service not known");
TEST_ASSIGN(
- client, tlsClientNew(sckClientNew(strNew("localhost"), hrnTlsServerPort(), 100), strNew("X"), 100, true, NULL, NULL),
+ client, tlsClientNew(sckClientNew(strNew("localhost"), hrnServerPort(0), 100), strNew("X"), 100, true, NULL, NULL),
"new client");
TEST_ERROR_FMT(
ioClientOpen(client), HostConnectError, "unable to connect to 'localhost:%u': [111] Connection refused",
- hrnTlsServerPort());
+ hrnServerPort(0));
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("bogus client cert/path");
@@ -239,8 +234,7 @@ testRun(void)
ioClientOpen(
tlsClientNew(
sckClientNew(
- strNew("localhost"), hrnTlsServerPort(), 5000), strNew("X"), 0, true, strNew("bogus.crt"),
- strNew("/bogus"))),
+ strNew("localhost"), hrnServerPort(0), 5000), strNew("X"), 0, true, strNew("bogus.crt"), strNew("/bogus"))),
CryptoError, "unable to set user-defined CA certificate location: [33558530] No such file or directory");
// Certificate location and validation errors
@@ -260,105 +254,105 @@ testRun(void)
{
// Start server to test various certificate errors
TEST_RESULT_VOID(
- hrnTlsServerRunParam(
- ioFdReadNew(strNew("test server read"), HARNESS_FORK_CHILD_READ(), 5000),
- strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-alt-name.crt", testRepoPath()),
- strNewFmt("%s/" TEST_CERTIFICATE_PREFIX ".key", testRepoPath())),
- "tls alt name server begin");
+ hrnServerRunP(
+ ioFdReadNew(strNew("test server read"), HARNESS_FORK_CHILD_READ(), 5000), hrnServerProtocolTls,
+ .certificate = strNewFmt("%s/" HRN_SERVER_CERT_PREFIX "-alt-name.crt", testRepoPath()),
+ .key = strNewFmt("%s/" HRN_SERVER_CERT_PREFIX ".key", testRepoPath())),
+ "tls alt name server run");
}
HARNESS_FORK_CHILD_END();
HARNESS_FORK_PARENT_BEGIN()
{
- hrnTlsClientBegin(ioFdWriteNew(strNew("test client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 1000));
+ IoWrite *tls = hrnServerScriptBegin(
+ ioFdWriteNew(strNew("test client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 1000));
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("certificate error on invalid ca path");
- hrnTlsServerAccept();
- hrnTlsServerClose();
+ hrnServerScriptAccept(tls);
+ hrnServerScriptClose(tls);
TEST_ERROR_FMT(
ioClientOpen(
tlsClientNew(
- sckClientNew(strNew("localhost"), hrnTlsServerPort(), 5000), strNew("X"), 0, true, NULL,
+ sckClientNew(strNew("localhost"), hrnServerPort(0), 5000), strNew("X"), 0, true, NULL,
strNew("/bogus"))),
CryptoError,
"unable to verify certificate presented by 'localhost:%u': [20] unable to get local issuer certificate",
- hrnTlsServerPort());
+ hrnServerPort(0));
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("valid ca file and match common name");
- hrnTlsServerAccept();
- hrnTlsServerClose();
+ hrnServerScriptAccept(tls);
+ hrnServerScriptClose(tls);
TEST_RESULT_VOID(
ioClientOpen(
tlsClientNew(
- sckClientNew(strNew("test.pgbackrest.org"), hrnTlsServerPort(), 5000), strNew("test.pgbackrest.org"),
- 0, true, strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-ca.crt", testRepoPath()), NULL)),
+ sckClientNew(strNew("test.pgbackrest.org"), hrnServerPort(0), 5000), strNew("test.pgbackrest.org"),
+ 0, true, strNewFmt("%s/" HRN_SERVER_CERT_PREFIX "-ca.crt", testRepoPath()), NULL)),
"open connection");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("valid ca file and match alt name");
- hrnTlsServerAccept();
- hrnTlsServerClose();
+ hrnServerScriptAccept(tls);
+ hrnServerScriptClose(tls);
TEST_RESULT_VOID(
ioClientOpen(
tlsClientNew(
- sckClientNew(strNew("host.test2.pgbackrest.org"), hrnTlsServerPort(), 5000),
+ sckClientNew(strNew("host.test2.pgbackrest.org"), hrnServerPort(0), 5000),
strNew("host.test2.pgbackrest.org"), 0, true,
- strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-ca.crt", testRepoPath()), NULL)),
+ strNewFmt("%s/" HRN_SERVER_CERT_PREFIX "-ca.crt", testRepoPath()), NULL)),
"open connection");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("unable to find matching hostname in certificate");
- hrnTlsServerAccept();
- hrnTlsServerClose();
+ hrnServerScriptAccept(tls);
+ hrnServerScriptClose(tls);
TEST_ERROR(
ioClientOpen(
tlsClientNew(
- sckClientNew(strNew("test3.pgbackrest.org"), hrnTlsServerPort(), 5000),
- strNew("test3.pgbackrest.org"), 0, true,
- strNewFmt("%s/" TEST_CERTIFICATE_PREFIX "-ca.crt", testRepoPath()), NULL)),
+ sckClientNew(strNew("test3.pgbackrest.org"), hrnServerPort(0), 5000), strNew("test3.pgbackrest.org"),
+ 0, true, strNewFmt("%s/" HRN_SERVER_CERT_PREFIX "-ca.crt", testRepoPath()), NULL)),
CryptoError,
"unable to find hostname 'test3.pgbackrest.org' in certificate common name or subject alternative names");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("certificate error");
- hrnTlsServerAccept();
- hrnTlsServerClose();
+ hrnServerScriptAccept(tls);
+ hrnServerScriptClose(tls);
TEST_ERROR_FMT(
ioClientOpen(
tlsClientNew(
- sckClientNew(strNew("localhost"), hrnTlsServerPort(), 5000), strNew("X"), 0, true,
- strNewFmt("%s/" TEST_CERTIFICATE_PREFIX ".crt", testRepoPath()),
+ sckClientNew(strNew("localhost"), hrnServerPort(0), 5000), strNew("X"), 0, true,
+ strNewFmt("%s/" HRN_SERVER_CERT_PREFIX ".crt", testRepoPath()),
NULL)),
CryptoError,
"unable to verify certificate presented by 'localhost:%u': [20] unable to get local issuer certificate",
- hrnTlsServerPort());
+ hrnServerPort(0));
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("no certificate verify");
- hrnTlsServerAccept();
- hrnTlsServerClose();
+ hrnServerScriptAccept(tls);
+ hrnServerScriptClose(tls);
TEST_RESULT_VOID(
ioClientOpen(
tlsClientNew(
- sckClientNew(strNew("localhost"), hrnTlsServerPort(), 5000), strNew("X"), 0, false, NULL, NULL)),
+ sckClientNew(strNew("localhost"), hrnServerPort(0), 5000), strNew("X"), 0, false, NULL, NULL)),
"open connection");
// -----------------------------------------------------------------------------------------------------------------
- hrnTlsClientEnd();
+ hrnServerScriptEnd(tls);
}
HARNESS_FORK_PARENT_END();
}
@@ -383,23 +377,26 @@ testRun(void)
HARNESS_FORK_CHILD_BEGIN(0, true)
{
TEST_RESULT_VOID(
- hrnTlsServerRun(ioFdReadNew(strNew("test server read"), HARNESS_FORK_CHILD_READ(), 5000)), "tls server begin");
+ hrnServerRunP(
+ ioFdReadNew(strNew("test server read"), HARNESS_FORK_CHILD_READ(), 5000), hrnServerProtocolTls),
+ "tls server run");
}
HARNESS_FORK_CHILD_END();
HARNESS_FORK_PARENT_BEGIN()
{
- hrnTlsClientBegin(ioFdWriteNew(strNew("test client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 1000));
+ IoWrite *tls =
+ hrnServerScriptBegin(ioFdWriteNew(strNew("test client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 1000));
ioBufferSizeSet(12);
TEST_ASSIGN(
client,
tlsClientNew(
- sckClientNew(hrnTlsServerHost(), hrnTlsServerPort(), 5000), hrnTlsServerHost(), 0, testContainer(), NULL,
+ sckClientNew(hrnServerHost(), hrnServerPort(0), 5000), hrnServerHost(), 0, testContainer(), NULL,
NULL),
"new client");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(tls);
TEST_ASSIGN(session, ioClientOpen(client), "open client");
TlsSession *tlsSession = (TlsSession *)session->driver;
@@ -422,8 +419,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("first protocol exchange");
- hrnTlsServerExpectZ("some protocol info");
- hrnTlsServerReplyZ("something:0\n");
+ hrnServerScriptExpectZ(tls, "some protocol info");
+ hrnServerScriptReplyZ(tls, "something:0\n");
const Buffer *input = BUFSTRDEF("some protocol info");
TEST_RESULT_VOID(ioWrite(ioSessionIoWrite(session), input), "write input");
@@ -432,11 +429,11 @@ testRun(void)
TEST_RESULT_STR_Z(ioReadLine(ioSessionIoRead(session)), "something:0", "read line");
TEST_RESULT_BOOL(ioReadEof(ioSessionIoRead(session)), false, "check eof = false");
- hrnTlsServerSleep(100);
- hrnTlsServerReplyZ("some ");
+ hrnServerScriptSleep(tls, 100);
+ hrnServerScriptReplyZ(tls, "some ");
- hrnTlsServerSleep(100);
- hrnTlsServerReplyZ("contentAND MORE");
+ hrnServerScriptSleep(tls, 100);
+ hrnServerScriptReplyZ(tls, "contentAND MORE");
Buffer *output = bufNew(12);
TEST_RESULT_UINT(ioRead(ioSessionIoRead(session), output), 12, "read output");
@@ -451,22 +448,22 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("read eof");
- hrnTlsServerSleep(500);
+ hrnServerScriptSleep(tls, 500);
output = bufNew(12);
((IoFdRead *)((SocketSession *)tlsSession->ioSession->driver)->read->driver)->timeout = 100;
TEST_ERROR_FMT(
ioRead(ioSessionIoRead(session), output), FileReadError,
- "timeout after 100ms waiting for read from '%s:%u'", strZ(hrnTlsServerHost()), hrnTlsServerPort());
+ "timeout after 100ms waiting for read from '%s:%u'", strZ(hrnServerHost()), hrnServerPort(0));
((IoFdRead *)((SocketSession *)tlsSession->ioSession->driver)->read->driver)->timeout = 5000;
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("second protocol exchange");
- hrnTlsServerExpectZ("more protocol info");
- hrnTlsServerReplyZ("0123456789AB");
+ hrnServerScriptExpectZ(tls, "more protocol info");
+ hrnServerScriptReplyZ(tls, "0123456789AB");
- hrnTlsServerClose();
+ hrnServerScriptClose(tls);
input = BUFSTRDEF("more protocol info");
TEST_RESULT_VOID(ioWrite(ioSessionIoWrite(session), input), "write input");
@@ -486,9 +483,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("aborted connection before read complete (blocking socket)");
- hrnTlsServerAccept();
- hrnTlsServerReplyZ("0123456789AB");
- hrnTlsServerAbort();
+ hrnServerScriptAccept(tls);
+ hrnServerScriptReplyZ(tls, "0123456789AB");
+ hrnServerScriptAbort(tls);
socketLocal.block = true;
TEST_ASSIGN(session, ioClientOpen(client), "open client again (was closed by server)");
@@ -503,7 +500,7 @@ testRun(void)
TEST_RESULT_VOID(ioClientFree(client), "free client");
// -----------------------------------------------------------------------------------------------------------------
- hrnTlsClientEnd();
+ hrnServerScriptEnd(tls);
}
HARNESS_FORK_PARENT_END();
}
diff --git a/test/src/module/storage/azureTest.c b/test/src/module/storage/azureTest.c
index a9ba3a163..50e1bf105 100644
--- a/test/src/module/storage/azureTest.c
+++ b/test/src/module/storage/azureTest.c
@@ -6,8 +6,8 @@ Test Azure Storage
#include "common/harnessConfig.h"
#include "common/harnessFork.h"
+#include "common/harnessServer.h"
#include "common/harnessStorage.h"
-#include "common/harnessTls.h"
/***********************************************************************************************************************************
Constants
@@ -33,11 +33,11 @@ typedef struct TestRequestParam
const char *blobType;
} TestRequestParam;
-#define testRequestP(verb, uri, ...) \
- testRequest(verb, uri, (TestRequestParam){VAR_PARAM_INIT, __VA_ARGS__})
+#define testRequestP(write, verb, uri, ...) \
+ testRequest(write, verb, uri, (TestRequestParam){VAR_PARAM_INIT, __VA_ARGS__})
static void
-testRequest(const char *verb, const char *uri, TestRequestParam param)
+testRequest(IoWrite *write, const char *verb, const char *uri, TestRequestParam param)
{
String *request = strNewFmt("%s /" TEST_ACCOUNT "/" TEST_CONTAINER, verb);
@@ -83,7 +83,7 @@ testRequest(const char *verb, const char *uri, TestRequestParam param)
strCatZ(request, "date:???, ?? ??? ???? ??:??:?? GMT\r\n");
// Add host
- strCatFmt(request, "host:%s\r\n", strZ(hrnTlsServerHost()));
+ strCatFmt(request, "host:%s\r\n", strZ(hrnServerHost()));
// Add blob type
if (param.blobType != NULL)
@@ -100,7 +100,7 @@ testRequest(const char *verb, const char *uri, TestRequestParam param)
if (param.content != NULL)
strCatZ(request, param.content);
- hrnTlsServerExpect(request);
+ hrnServerScriptExpect(write, request);
}
/***********************************************************************************************************************************
@@ -114,11 +114,11 @@ typedef struct TestResponseParam
const char *content;
} TestResponseParam;
-#define testResponseP(...) \
- testResponse((TestResponseParam){VAR_PARAM_INIT, __VA_ARGS__})
+#define testResponseP(write, ...) \
+ testResponse(write, (TestResponseParam){VAR_PARAM_INIT, __VA_ARGS__})
static void
-testResponse(TestResponseParam param)
+testResponse(IoWrite *write, TestResponseParam param)
{
// Set code to 200 if not specified
param.code = param.code == 0 ? 200 : param.code;
@@ -162,7 +162,7 @@ testResponse(TestResponseParam param)
else
strCatZ(response, "\r\n");
- hrnTlsServerReply(response);
+ hrnServerScriptReply(write, response);
}
/***********************************************************************************************************************************
@@ -273,14 +273,15 @@ testRun(void)
HARNESS_FORK_CHILD_BEGIN(0, true)
{
TEST_RESULT_VOID(
- hrnTlsServerRun(ioFdReadNew(strNew("azure server read"), HARNESS_FORK_CHILD_READ(), 5000)),
- "azure server begin");
+ hrnServerRunP(ioFdReadNew(strNew("azure server read"), HARNESS_FORK_CHILD_READ(), 5000), hrnServerProtocolTls),
+ "azure server run");
}
HARNESS_FORK_CHILD_END();
HARNESS_FORK_PARENT_BEGIN()
{
- hrnTlsClientBegin(ioFdWriteNew(strNew("azure client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000));
+ IoWrite *service = hrnServerScriptBegin(
+ ioFdWriteNew(strNew("azure client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000));
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("test against local host");
@@ -290,8 +291,8 @@ testRun(void)
strLstAddZ(argList, "--" CFGOPT_REPO1_TYPE "=" STORAGE_AZURE_TYPE);
strLstAddZ(argList, "--" CFGOPT_REPO1_PATH "=/");
strLstAddZ(argList, "--" CFGOPT_REPO1_AZURE_CONTAINER "=" TEST_CONTAINER);
- strLstAdd(argList, strNewFmt("--" CFGOPT_REPO1_AZURE_HOST "=%s", strZ(hrnTlsServerHost())));
- strLstAdd(argList, strNewFmt("--" CFGOPT_REPO1_AZURE_PORT "=%u", hrnTlsServerPort()));
+ strLstAdd(argList, strNewFmt("--" CFGOPT_REPO1_AZURE_HOST "=%s", strZ(hrnServerHost())));
+ strLstAdd(argList, strNewFmt("--" CFGOPT_REPO1_AZURE_PORT "=%u", hrnServerPort(0)));
strLstAdd(argList, strNewFmt("--%s" CFGOPT_REPO1_AZURE_VERIFY_TLS, testContainer() ? "" : "no-"));
setenv("PGBACKREST_" CFGOPT_REPO1_AZURE_ACCOUNT, TEST_ACCOUNT, true);
setenv("PGBACKREST_" CFGOPT_REPO1_AZURE_KEY, TEST_KEY_SHARED, true);
@@ -301,7 +302,7 @@ testRun(void)
TEST_ASSIGN(storage, storageRepoGet(strNew(STORAGE_AZURE_TYPE), true), "get repo storage");
driver = (StorageAzure *)storage->driver;
- TEST_RESULT_STR(driver->host, hrnTlsServerHost(), " check host");
+ TEST_RESULT_STR(driver->host, hrnServerHost(), " check host");
TEST_RESULT_STR_Z(driver->uriPrefix, "/" TEST_ACCOUNT "/" TEST_CONTAINER, " check uri prefix");
TEST_RESULT_BOOL(driver->fileId == 0, false, " check file id");
@@ -311,9 +312,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("ignore missing file");
- hrnTlsServerAccept();
- testRequestP(HTTP_VERB_GET, "/fi%26le.txt");
- testResponseP(.code = 404);
+ hrnServerScriptAccept(service);
+ testRequestP(service, HTTP_VERB_GET, "/fi%26le.txt");
+ testResponseP(service, .code = 404);
TEST_RESULT_PTR(
storageGetP(storageNewReadP(storage, strNew("fi&le.txt"), .ignoreMissing = true)), NULL, "get file");
@@ -321,8 +322,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("error on missing file");
- testRequestP(HTTP_VERB_GET, "/file.txt");
- testResponseP(.code = 404);
+ testRequestP(service, HTTP_VERB_GET, "/file.txt");
+ testResponseP(service, .code = 404);
TEST_ERROR(
storageGetP(storageNewReadP(storage, strNew("file.txt"))), FileMissingError,
@@ -331,8 +332,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("get file");
- testRequestP(HTTP_VERB_GET, "/file.txt");
- testResponseP(.content = "this is a sample file");
+ testRequestP(service, HTTP_VERB_GET, "/file.txt");
+ testResponseP(service, .content = "this is a sample file");
TEST_RESULT_STR_Z(
strNewBuf(storageGetP(storageNewReadP(storage, strNew("file.txt")))), "this is a sample file", "get file");
@@ -340,8 +341,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("get zero-length file");
- testRequestP(HTTP_VERB_GET, "/file0.txt");
- testResponseP();
+ testRequestP(service, HTTP_VERB_GET, "/file0.txt");
+ testResponseP(service);
TEST_RESULT_STR_Z(
strNewBuf(storageGetP(storageNewReadP(storage, strNew("file0.txt")))), "", "get zero-length file");
@@ -349,8 +350,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("non-404 error");
- testRequestP(HTTP_VERB_GET, "/file.txt");
- testResponseP(.code = 303, .content = "CONTENT");
+ testRequestP(service, HTTP_VERB_GET, "/file.txt");
+ testResponseP(service, .code = 303, .content = "CONTENT");
StorageRead *read = NULL;
TEST_ASSIGN(read, storageNewReadP(storage, strNew("file.txt"), .ignoreMissing = true), "new read file");
@@ -372,13 +373,13 @@ testRun(void)
"content-length: 7\n"
"*** Response Content ***:\n"
"CONTENT",
- strZ(hrnTlsServerHost()));
+ strZ(hrnServerHost()));
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("write error");
- testRequestP(HTTP_VERB_PUT, "/file.txt", .blobType = "BlockBlob", .content = "ABCD");
- testResponseP(.code = 403);
+ testRequestP(service, HTTP_VERB_PUT, "/file.txt", .blobType = "BlockBlob", .content = "ABCD");
+ testResponseP(service, .code = 403);
TEST_ERROR_FMT(
storagePutP(storageNewWriteP(storage, strNew("file.txt")), BUFSTRDEF("ABCD")), ProtocolError,
@@ -393,15 +394,15 @@ testRun(void)
"host: %s\n"
"x-ms-blob-type: BlockBlob\n"
"x-ms-version: 2019-02-02",
- strZ(hrnTlsServerHost()));
+ strZ(hrnServerHost()));
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("write file in one part (with retry)");
- testRequestP(HTTP_VERB_PUT, "/file.txt", .blobType = "BlockBlob", .content = "ABCD");
- testResponseP(.code = 503);
- testRequestP(HTTP_VERB_PUT, "/file.txt", .blobType = "BlockBlob", .content = "ABCD");
- testResponseP();
+ testRequestP(service, HTTP_VERB_PUT, "/file.txt", .blobType = "BlockBlob", .content = "ABCD");
+ testResponseP(service, .code = 503);
+ testRequestP(service, HTTP_VERB_PUT, "/file.txt", .blobType = "BlockBlob", .content = "ABCD");
+ testResponseP(service);
StorageWrite *write = NULL;
TEST_ASSIGN(write, storageNewWriteP(storage, strNew("file.txt")), "new write");
@@ -420,8 +421,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("write zero-length file");
- testRequestP(HTTP_VERB_PUT, "/file.txt", .blobType = "BlockBlob", .content = "");
- testResponseP();
+ testRequestP(service, HTTP_VERB_PUT, "/file.txt", .blobType = "BlockBlob", .content = "");
+ testResponseP(service);
TEST_ASSIGN(write, storageNewWriteP(storage, strNew("file.txt")), "new write");
TEST_RESULT_VOID(storagePutP(write, NULL), "write");
@@ -429,21 +430,23 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("write file in chunks with nothing left over on close");
- testRequestP(HTTP_VERB_PUT, "/file.txt?blockid=0AAAAAAACCCCCCCCx0000000&comp=block", .content = "1234567890123456");
- testResponseP();
+ testRequestP(
+ service, HTTP_VERB_PUT, "/file.txt?blockid=0AAAAAAACCCCCCCCx0000000&comp=block", .content = "1234567890123456");
+ testResponseP(service);
- testRequestP(HTTP_VERB_PUT, "/file.txt?blockid=0AAAAAAACCCCCCCCx0000001&comp=block", .content = "7890123456789012");
- testResponseP();
+ testRequestP(
+ service, HTTP_VERB_PUT, "/file.txt?blockid=0AAAAAAACCCCCCCCx0000001&comp=block", .content = "7890123456789012");
+ testResponseP(service);
testRequestP(
- HTTP_VERB_PUT, "/file.txt?comp=blocklist",
+ service, HTTP_VERB_PUT, "/file.txt?comp=blocklist",
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<BlockList>"
"<Uncommitted>0AAAAAAACCCCCCCCx0000000</Uncommitted>"
"<Uncommitted>0AAAAAAACCCCCCCCx0000001</Uncommitted>"
"</BlockList>\n");
- testResponseP();
+ testResponseP(service);
// Test needs a predictable file id
driver->fileId = 0x0AAAAAAACCCCCCCC;
@@ -454,21 +457,23 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("write file in chunks with something left over on close");
- testRequestP(HTTP_VERB_PUT, "/file.txt?blockid=0AAAAAAACCCCCCCDx0000000&comp=block", .content = "1234567890123456");
- testResponseP();
+ testRequestP(
+ service, HTTP_VERB_PUT, "/file.txt?blockid=0AAAAAAACCCCCCCDx0000000&comp=block", .content = "1234567890123456");
+ testResponseP(service);
- testRequestP(HTTP_VERB_PUT, "/file.txt?blockid=0AAAAAAACCCCCCCDx0000001&comp=block", .content = "7890");
- testResponseP();
+ testRequestP(
+ service, HTTP_VERB_PUT, "/file.txt?blockid=0AAAAAAACCCCCCCDx0000001&comp=block", .content = "7890");
+ testResponseP(service);
testRequestP(
- HTTP_VERB_PUT, "/file.txt?comp=blocklist",
+ service, HTTP_VERB_PUT, "/file.txt?comp=blocklist",
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<BlockList>"
"<Uncommitted>0AAAAAAACCCCCCCDx0000000</Uncommitted>"
"<Uncommitted>0AAAAAAACCCCCCCDx0000001</Uncommitted>"
"</BlockList>\n");
- testResponseP();
+ testResponseP(service);
TEST_ASSIGN(write, storageNewWriteP(storage, strNew("file.txt")), "new write");
TEST_RESULT_VOID(storagePutP(write, BUFSTRDEF("12345678901234567890")), "write");
@@ -476,8 +481,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("info for missing file");
- testRequestP(HTTP_VERB_HEAD, "/BOGUS");
- testResponseP(.code = 404);
+ testRequestP(service, HTTP_VERB_HEAD, "/BOGUS");
+ testResponseP(service, .code = 404);
TEST_RESULT_BOOL(
storageInfoP(storage, strNew("BOGUS"), .ignoreMissing = true).exists, false, "file does not exist");
@@ -485,8 +490,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("info for file");
- testRequestP(HTTP_VERB_HEAD, "/subdir/file1.txt");
- testResponseP(.header = "content-length:9999\r\nLast-Modified: Wed, 21 Oct 2015 07:28:00 GMT");
+ testRequestP(service, HTTP_VERB_HEAD, "/subdir/file1.txt");
+ testResponseP(service, .header = "content-length:9999\r\nLast-Modified: Wed, 21 Oct 2015 07:28:00 GMT");
StorageInfo info;
TEST_ASSIGN(info, storageInfoP(storage, strNew("subdir/file1.txt")), "file exists");
@@ -498,8 +503,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("info check existence only");
- testRequestP(HTTP_VERB_HEAD, "/subdir/file2.txt");
- testResponseP(.header = "content-length:777\r\nLast-Modified: Wed, 22 Oct 2015 07:28:00 GMT");
+ testRequestP(service, HTTP_VERB_HEAD, "/subdir/file2.txt");
+ testResponseP(service, .header = "content-length:777\r\nLast-Modified: Wed, 22 Oct 2015 07:28:00 GMT");
TEST_ASSIGN(
info, storageInfoP(storage, strNew("subdir/file2.txt"), .level = storageInfoLevelExists), "file exists");
@@ -511,8 +516,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("list basic level");
- testRequestP(HTTP_VERB_GET, "?comp=list&delimiter=%2F&prefix=path%2Fto%2F&restype=container");
+ testRequestP(service, HTTP_VERB_GET, "?comp=list&delimiter=%2F&prefix=path%2Fto%2F&restype=container");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<EnumerationResults>"
@@ -551,8 +557,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("list exists level");
- testRequestP(HTTP_VERB_GET, "?comp=list&delimiter=%2F&restype=container");
+ testRequestP(service, HTTP_VERB_GET, "?comp=list&delimiter=%2F&restype=container");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<EnumerationResults>"
@@ -583,8 +590,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("list a file in root with expression");
- testRequestP(HTTP_VERB_GET, "?comp=list&delimiter=%2F&prefix=test&restype=container");
+ testRequestP(service, HTTP_VERB_GET, "?comp=list&delimiter=%2F&prefix=test&restype=container");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<EnumerationResults>"
@@ -612,8 +620,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("list files with continuation");
- testRequestP(HTTP_VERB_GET, "?comp=list&delimiter=%2F&prefix=path%2Fto%2F&restype=container");
+ testRequestP(service, HTTP_VERB_GET, "?comp=list&delimiter=%2F&prefix=path%2Fto%2F&restype=container");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<EnumerationResults>"
@@ -633,8 +642,10 @@ testRun(void)
" <NextMarker>ueGcxLPRx1Tr</NextMarker>"
"</EnumerationResults>");
- testRequestP(HTTP_VERB_GET, "?comp=list&delimiter=%2F&marker=ueGcxLPRx1Tr&prefix=path%2Fto%2F&restype=container");
+ testRequestP(
+ service, HTTP_VERB_GET, "?comp=list&delimiter=%2F&marker=ueGcxLPRx1Tr&prefix=path%2Fto%2F&restype=container");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<EnumerationResults>"
@@ -668,8 +679,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("list files with expression");
- testRequestP(HTTP_VERB_GET, "?comp=list&delimiter=%2F&prefix=path%2Fto%2Ftest&restype=container");
+ testRequestP(service, HTTP_VERB_GET, "?comp=list&delimiter=%2F&prefix=path%2Fto%2Ftest&restype=container");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<EnumerationResults>"
@@ -713,7 +725,7 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("switch to SAS auth");
- hrnTlsServerClose();
+ hrnServerScriptClose(service);
strLstAddZ(argList, "--" CFGOPT_REPO1_AZURE_KEY_TYPE "=" STORAGE_AZURE_KEY_TYPE_SAS);
setenv("PGBACKREST_" CFGOPT_REPO1_AZURE_KEY, TEST_KEY_SAS, true);
@@ -724,29 +736,29 @@ testRun(void)
driver = (StorageAzure *)storage->driver;
TEST_RESULT_PTR_NE(driver->sasKey, NULL, "check sas key");
- hrnTlsServerAccept();
+ hrnServerScriptAccept(service);
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove file");
- testRequestP(HTTP_VERB_DELETE, "/path/to/test.txt");
- testResponseP();
+ testRequestP(service, HTTP_VERB_DELETE, "/path/to/test.txt");
+ testResponseP(service);
TEST_RESULT_VOID(storageRemoveP(storage, strNew("/path/to/test.txt")), "remove");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove missing file");
- testRequestP(HTTP_VERB_DELETE, "/path/to/missing.txt");
- testResponseP(.code = 404);
+ testRequestP(service, HTTP_VERB_DELETE, "/path/to/missing.txt");
+ testResponseP(service, .code = 404);
TEST_RESULT_VOID(storageRemoveP(storage, strNew("/path/to/missing.txt")), "remove");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove files error to check redacted sig");
- testRequestP(HTTP_VERB_GET, "?comp=list&restype=container");
- testResponseP(.code = 403);
+ testRequestP(service, HTTP_VERB_GET, "?comp=list&restype=container");
+ testResponseP(service, .code = 403);
TEST_ERROR_FMT(
storagePathRemoveP(storage, strNew("/"), .recurse = true), ProtocolError,
@@ -756,13 +768,14 @@ testRun(void)
"*** Request Headers ***:\n"
"content-length: 0\n"
"host: %s",
- strZ(hrnTlsServerHost()));
+ strZ(hrnServerHost()));
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove files from root");
- testRequestP(HTTP_VERB_GET, "?comp=list&restype=container");
+ testRequestP(service, HTTP_VERB_GET, "?comp=list&restype=container");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<EnumerationResults>"
@@ -782,19 +795,20 @@ testRun(void)
" <NextMarker/>"
"</EnumerationResults>");
- testRequestP(HTTP_VERB_DELETE, "/test1.txt");
- testResponseP();
+ testRequestP(service, HTTP_VERB_DELETE, "/test1.txt");
+ testResponseP(service);
- testRequestP(HTTP_VERB_DELETE, "/path1/xxx.zzz");
- testResponseP();
+ testRequestP(service, HTTP_VERB_DELETE, "/path1/xxx.zzz");
+ testResponseP(service);
TEST_RESULT_VOID(storagePathRemoveP(storage, strNew("/"), .recurse = true), "remove");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove files from path");
- testRequestP(HTTP_VERB_GET, "?comp=list&prefix=path%2F&restype=container");
+ testRequestP(service, HTTP_VERB_GET, "?comp=list&prefix=path%2F&restype=container");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<EnumerationResults>"
@@ -814,19 +828,20 @@ testRun(void)
" <NextMarker/>"
"</EnumerationResults>");
- testRequestP(HTTP_VERB_DELETE, "/path/test1.txt");
- testResponseP();
+ testRequestP(service, HTTP_VERB_DELETE, "/path/test1.txt");
+ testResponseP(service);
- testRequestP(HTTP_VERB_DELETE, "/path/path1/xxx.zzz");
- testResponseP();
+ testRequestP(service, HTTP_VERB_DELETE, "/path/path1/xxx.zzz");
+ testResponseP(service);
TEST_RESULT_VOID(storagePathRemoveP(storage, strNew("/path"), .recurse = true), "remove");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove files in empty subpath (nothing to do)");
- testRequestP(HTTP_VERB_GET, "?comp=list&prefix=path%2F&restype=container");
+ testRequestP(service, HTTP_VERB_GET, "?comp=list&prefix=path%2F&restype=container");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<EnumerationResults>"
@@ -838,7 +853,7 @@ testRun(void)
TEST_RESULT_VOID(storagePathRemoveP(storage, strNew("/path"), .recurse = true), "remove");
// -----------------------------------------------------------------------------------------------------------------
- hrnTlsClientEnd();
+ hrnServerScriptEnd(service);
}
HARNESS_FORK_PARENT_END();
}
diff --git a/test/src/module/storage/s3Test.c b/test/src/module/storage/s3Test.c
index 418ca979b..588e13c6f 100644
--- a/test/src/module/storage/s3Test.c
+++ b/test/src/module/storage/s3Test.c
@@ -8,8 +8,8 @@ Test S3 Storage
#include "common/harnessConfig.h"
#include "common/harnessFork.h"
+#include "common/harnessServer.h"
#include "common/harnessStorage.h"
-#include "common/harnessTls.h"
/***********************************************************************************************************************************
Constants
@@ -23,13 +23,15 @@ typedef struct TestRequestParam
{
VAR_PARAM_HEADER;
const char *content;
+ const char *accessKey;
+ const char *securityToken;
} TestRequestParam;
-#define testRequestP(s3, verb, uri, ...) \
- testRequest(s3, verb, uri, (TestRequestParam){VAR_PARAM_INIT, __VA_ARGS__})
+#define testRequestP(write, s3, verb, uri, ...) \
+ testRequest(write, s3, verb, uri, (TestRequestParam){VAR_PARAM_INIT, __VA_ARGS__})
static void
-testRequest(Storage *s3, const char *verb, const char *uri, TestRequestParam param)
+testRequest(IoWrite *write, Storage *s3, const char *verb, const char *uri, TestRequestParam param)
{
// Get S3 driver
StorageS3 *driver = (StorageS3 *)storageDriver(s3);
@@ -86,7 +88,7 @@ testRequest(Storage *s3, const char *verb, const char *uri, TestRequestParam par
if (param.content != NULL)
strCatZ(request, param.content);
- hrnTlsServerExpect(request);
+ hrnServerScriptExpect(write, request);
}
/***********************************************************************************************************************************
@@ -100,11 +102,11 @@ typedef struct TestResponseParam
const char *content;
} TestResponseParam;
-#define testResponseP(...) \
- testResponse((TestResponseParam){VAR_PARAM_INIT, __VA_ARGS__})
+#define testResponseP(write, ...) \
+ testResponse(write, (TestResponseParam){VAR_PARAM_INIT, __VA_ARGS__})
static void
-testResponse(TestResponseParam param)
+testResponse(IoWrite *write, TestResponseParam param)
{
// Set code to 200 if not specified
param.code = param.code == 0 ? 200 : param.code;
@@ -148,7 +150,7 @@ testResponse(TestResponseParam param)
else
strCatZ(response, "\r\n");
- hrnTlsServerReply(response);
+ hrnServerScriptReply(write, response);
}
/***********************************************************************************************************************************
@@ -164,8 +166,8 @@ testRun(void)
const String *bucket = strNew("bucket");
const String *region = strNew("us-east-1");
const String *endPoint = strNew("s3.amazonaws.com");
- const String *host = hrnTlsServerHost();
- const unsigned int port = hrnTlsServerPort();
+ const String *host = hrnServerHost();
+ const unsigned int port = hrnServerPort(0);
const String *accessKey = strNew("AKIAIOSFODNN7EXAMPLE");
const String *secretAccessKey = strNew("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY");
const String *securityToken = strNew(
@@ -269,7 +271,7 @@ testRun(void)
argList = strLstDup(commonArgWithoutEndpointList);
strLstAddZ(argList, "--" CFGOPT_REPO1_S3_ENDPOINT "=custom.endpoint:333");
strLstAddZ(argList, "--" CFGOPT_REPO1_S3_CA_PATH "=/path/to/cert");
- strLstAdd(argList, strNewFmt("--" CFGOPT_REPO1_S3_CA_FILE "=%s/" TEST_CERTIFICATE_PREFIX ".crt", testRepoPath()));
+ strLstAdd(argList, strNewFmt("--" CFGOPT_REPO1_S3_CA_FILE "=%s/" HRN_SERVER_CERT_PREFIX ".crt", testRepoPath()));
setenv("PGBACKREST_" CFGOPT_REPO1_S3_KEY, strZ(accessKey), true);
setenv("PGBACKREST_" CFGOPT_REPO1_S3_KEY_SECRET, strZ(secretAccessKey), true);
setenv("PGBACKREST_" CFGOPT_REPO1_S3_TOKEN, strZ(securityToken), true);
@@ -308,13 +310,16 @@ testRun(void)
HARNESS_FORK_CHILD_BEGIN(0, true)
{
TEST_RESULT_VOID(
- hrnTlsServerRun(ioFdReadNew(strNew("s3 server read"), HARNESS_FORK_CHILD_READ(), 5000)), "s3 server begin");
+ hrnServerRunP(
+ ioFdReadNew(strNew("s3 server read"), HARNESS_FORK_CHILD_READ(), 5000), hrnServerProtocolTls, .port = port),
+ "s3 server run");
}
HARNESS_FORK_CHILD_END();
HARNESS_FORK_PARENT_BEGIN()
{
- hrnTlsClientBegin(ioFdWriteNew(strNew("s3 client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000));
+ IoWrite *service = hrnServerScriptBegin(
+ ioFdWriteNew(strNew("s3 client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000));
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("config with keys, token, and host with custom port");
@@ -343,17 +348,17 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("ignore missing file");
- hrnTlsServerAccept();
- testRequestP(s3, HTTP_VERB_GET, "/fi%26le.txt");
- testResponseP(.code = 404);
+ hrnServerScriptAccept(service);
+ testRequestP(service, s3, HTTP_VERB_GET, "/fi%26le.txt");
+ testResponseP(service, .code = 404);
TEST_RESULT_PTR(storageGetP(storageNewReadP(s3, strNew("fi&le.txt"), .ignoreMissing = true)), NULL, "get file");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("error on missing file");
- testRequestP(s3, HTTP_VERB_GET, "/file.txt");
- testResponseP(.code = 404);
+ testRequestP(service, s3, HTTP_VERB_GET, "/file.txt");
+ testResponseP(service, .code = 404);
TEST_ERROR(
storageGetP(storageNewReadP(s3, strNew("file.txt"))), FileMissingError,
@@ -362,8 +367,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("get file");
- testRequestP(s3, HTTP_VERB_GET, "/file.txt");
- testResponseP(.content = "this is a sample file");
+ testRequestP(service, s3, HTTP_VERB_GET, "/file.txt");
+ testResponseP(service, .content = "this is a sample file");
TEST_RESULT_STR_Z(
strNewBuf(storageGetP(storageNewReadP(s3, strNew("file.txt")))), "this is a sample file", "get file");
@@ -371,16 +376,16 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("get zero-length file");
- testRequestP(s3, HTTP_VERB_GET, "/file0.txt");
- testResponseP();
+ testRequestP(service, s3, HTTP_VERB_GET, "/file0.txt");
+ testResponseP(service);
TEST_RESULT_STR_Z(strNewBuf(storageGetP(storageNewReadP(s3, strNew("file0.txt")))), "", "get zero-length file");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("non-404 error");
- testRequestP(s3, HTTP_VERB_GET, "/file.txt");
- testResponseP(.code = 303, .content = "CONTENT");
+ testRequestP(service, s3, HTTP_VERB_GET, "/file.txt");
+ testResponseP(service, .code = 303, .content = "CONTENT");
StorageRead *read = NULL;
TEST_ASSIGN(read, storageNewReadP(s3, strNew("file.txt"), .ignoreMissing = true), "new read file");
@@ -407,8 +412,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("write file in one part");
- testRequestP(s3, HTTP_VERB_PUT, "/file.txt", .content = "ABCD");
- testResponseP();
+ testRequestP(service, s3, HTTP_VERB_PUT, "/file.txt", .content = "ABCD");
+ testResponseP(service);
StorageWrite *write = NULL;
TEST_ASSIGN(write, storageNewWriteP(s3, strNew("file.txt")), "new write");
@@ -427,8 +432,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("write zero-length file");
- testRequestP(s3, HTTP_VERB_PUT, "/file.txt", .content = "");
- testResponseP();
+ testRequestP(service, s3, HTTP_VERB_PUT, "/file.txt", .content = "");
+ testResponseP(service);
TEST_ASSIGN(write, storageNewWriteP(s3, strNew("file.txt")), "new write");
TEST_RESULT_VOID(storagePutP(write, NULL), "write");
@@ -436,8 +441,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("write file in chunks with nothing left over on close");
- testRequestP(s3, HTTP_VERB_POST, "/file.txt?uploads=");
+ testRequestP(service, s3, HTTP_VERB_POST, "/file.txt?uploads=");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<InitiateMultipartUploadResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -446,21 +452,21 @@ testRun(void)
"<UploadId>WxRt</UploadId>"
"</InitiateMultipartUploadResult>");
- testRequestP(s3, HTTP_VERB_PUT, "/file.txt?partNumber=1&uploadId=WxRt", .content = "1234567890123456");
- testResponseP(.header = "etag:WxRt1");
+ testRequestP(service, s3, HTTP_VERB_PUT, "/file.txt?partNumber=1&uploadId=WxRt", .content = "1234567890123456");
+ testResponseP(service, .header = "etag:WxRt1");
- testRequestP(s3, HTTP_VERB_PUT, "/file.txt?partNumber=2&uploadId=WxRt", .content = "7890123456789012");
- testResponseP(.header = "eTag:WxRt2");
+ testRequestP(service, s3, HTTP_VERB_PUT, "/file.txt?partNumber=2&uploadId=WxRt", .content = "7890123456789012");
+ testResponseP(service, .header = "eTag:WxRt2");
testRequestP(
- s3, HTTP_VERB_POST, "/file.txt?uploadId=WxRt",
+ service, s3, HTTP_VERB_POST, "/file.txt?uploadId=WxRt",
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<CompleteMultipartUpload>"
"<Part><PartNumber>1</PartNumber><ETag>WxRt1</ETag></Part>"
"<Part><PartNumber>2</PartNumber><ETag>WxRt2</ETag></Part>"
"</CompleteMultipartUpload>\n");
- testResponseP();
+ testResponseP(service);
TEST_ASSIGN(write, storageNewWriteP(s3, strNew("file.txt")), "new write");
TEST_RESULT_VOID(storagePutP(write, BUFSTRDEF("12345678901234567890123456789012")), "write");
@@ -468,8 +474,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("write file in chunks with something left over on close");
- testRequestP(s3, HTTP_VERB_POST, "/file.txt?uploads=");
+ testRequestP(service, s3, HTTP_VERB_POST, "/file.txt?uploads=");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<InitiateMultipartUploadResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -478,21 +485,21 @@ testRun(void)
"<UploadId>RR55</UploadId>"
"</InitiateMultipartUploadResult>");
- testRequestP(s3, HTTP_VERB_PUT, "/file.txt?partNumber=1&uploadId=RR55", .content = "1234567890123456");
- testResponseP(.header = "etag:RR551");
+ testRequestP(service, s3, HTTP_VERB_PUT, "/file.txt?partNumber=1&uploadId=RR55", .content = "1234567890123456");
+ testResponseP(service, .header = "etag:RR551");
- testRequestP(s3, HTTP_VERB_PUT, "/file.txt?partNumber=2&uploadId=RR55", .content = "7890");
- testResponseP(.header = "eTag:RR552");
+ testRequestP(service, s3, HTTP_VERB_PUT, "/file.txt?partNumber=2&uploadId=RR55", .content = "7890");
+ testResponseP(service, .header = "eTag:RR552");
testRequestP(
- s3, HTTP_VERB_POST, "/file.txt?uploadId=RR55",
+ service, s3, HTTP_VERB_POST, "/file.txt?uploadId=RR55",
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<CompleteMultipartUpload>"
"<Part><PartNumber>1</PartNumber><ETag>RR551</ETag></Part>"
"<Part><PartNumber>2</PartNumber><ETag>RR552</ETag></Part>"
"</CompleteMultipartUpload>\n");
- testResponseP();
+ testResponseP(service);
TEST_ASSIGN(write, storageNewWriteP(s3, strNew("file.txt")), "new write");
TEST_RESULT_VOID(storagePutP(write, BUFSTRDEF("12345678901234567890")), "write");
@@ -500,8 +507,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("file missing");
- testRequestP(s3, HTTP_VERB_HEAD, "/BOGUS");
- testResponseP(.code = 404);
+ testRequestP(service, s3, HTTP_VERB_HEAD, "/BOGUS");
+ testResponseP(service, .code = 404);
TEST_RESULT_BOOL(storageExistsP(s3, strNew("BOGUS")), false, "check");
@@ -509,16 +516,16 @@ testRun(void)
TEST_TITLE("info for missing file");
// File missing
- testRequestP(s3, HTTP_VERB_HEAD, "/BOGUS");
- testResponseP(.code = 404);
+ testRequestP(service, s3, HTTP_VERB_HEAD, "/BOGUS");
+ testResponseP(service, .code = 404);
TEST_RESULT_BOOL(storageInfoP(s3, strNew("BOGUS"), .ignoreMissing = true).exists, false, "file does not exist");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("info for file");
- testRequestP(s3, HTTP_VERB_HEAD, "/subdir/file1.txt");
- testResponseP(.header = "content-length:9999\r\nLast-Modified: Wed, 21 Oct 2015 07:28:00 GMT");
+ testRequestP(service, s3, HTTP_VERB_HEAD, "/subdir/file1.txt");
+ testResponseP(service, .header = "content-length:9999\r\nLast-Modified: Wed, 21 Oct 2015 07:28:00 GMT");
StorageInfo info;
TEST_ASSIGN(info, storageInfoP(s3, strNew("subdir/file1.txt")), "file exists");
@@ -530,8 +537,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("info check existence only");
- testRequestP(s3, HTTP_VERB_HEAD, "/subdir/file2.txt");
- testResponseP(.header = "content-length:777\r\nLast-Modified: Wed, 22 Oct 2015 07:28:00 GMT");
+ testRequestP(service, s3, HTTP_VERB_HEAD, "/subdir/file2.txt");
+ testResponseP(service, .header = "content-length:777\r\nLast-Modified: Wed, 22 Oct 2015 07:28:00 GMT");
TEST_ASSIGN(info, storageInfoP(s3, strNew("subdir/file2.txt"), .level = storageInfoLevelExists), "file exists");
TEST_RESULT_BOOL(info.exists, true, " check exists");
@@ -549,8 +556,8 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("error without xml");
- testRequestP(s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2");
- testResponseP(.code = 344);
+ testRequestP(service, s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2");
+ testResponseP(service, .code = 344);
TEST_ERROR(storageListP(s3, strNew("/")), ProtocolError,
"HTTP request failed with 344:\n"
@@ -567,9 +574,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("error with xml");
- testRequestP(s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2");
+ testRequestP(service, s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2");
testResponseP(
- .code = 344,
+ service, .code = 344,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<Error>"
@@ -595,8 +602,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("list basic level");
- testRequestP(s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2&prefix=path%2Fto%2F");
+ testRequestP(service, s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2&prefix=path%2Fto%2F");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -630,8 +638,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("list exists level");
- testRequestP(s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2");
+ testRequestP(service, s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -657,8 +666,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("list a file in root with expression");
- testRequestP(s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2&prefix=test");
+ testRequestP(service, s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2&prefix=test");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -682,8 +692,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("list files with continuation");
- testRequestP(s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2&prefix=path%2Fto%2F");
+ testRequestP(service, s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2&prefix=path%2Fto%2F");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -700,10 +711,11 @@ testRun(void)
"</ListBucketResult>");
testRequestP(
- s3, HTTP_VERB_GET,
+ service, s3, HTTP_VERB_GET,
"/?continuation-token=1ueGcxLPRx1Tr%2FXYExHnhbYLgveDs2J%2Fwm36Hy4vbOwM%3D&delimiter=%2F&list-type=2"
"&prefix=path%2Fto%2F");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -733,8 +745,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("list files with expression");
- testRequestP(s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2&prefix=path%2Fto%2Ftest");
+ testRequestP(service, s3, HTTP_VERB_GET, "/?delimiter=%2F&list-type=2&prefix=path%2Fto%2Ftest");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -772,7 +785,7 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("switch to path-style URIs");
- hrnTlsServerClose();
+ hrnServerScriptClose(service);
argList = strLstDup(commonArgList);
strLstAddZ(argList, "--" CFGOPT_REPO1_S3_URI_STYLE "=" STORAGE_S3_URI_STYLE_PATH);
@@ -789,7 +802,7 @@ testRun(void)
// Set deleteMax to a small value for testing
driver->deleteMax = 2;
- hrnTlsServerAccept();
+ hrnServerScriptAccept(service);
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("error when no recurse because there are no paths");
@@ -801,8 +814,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove files from root");
- testRequestP(s3, HTTP_VERB_GET, "/bucket/?list-type=2");
+ testRequestP(service, s3, HTTP_VERB_GET, "/bucket/?list-type=2");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -815,22 +829,24 @@ testRun(void)
"</ListBucketResult>");
testRequestP(
- s3, HTTP_VERB_POST, "/bucket/?delete=",
+ service, s3, HTTP_VERB_POST, "/bucket/?delete=",
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<Delete><Quiet>true</Quiet>"
"<Object><Key>test1.txt</Key></Object>"
"<Object><Key>path1/xxx.zzz</Key></Object>"
"</Delete>\n");
- testResponseP(.content = "<DeleteResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"></DeleteResult>");
+ testResponseP(
+ service, .content = "<DeleteResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"></DeleteResult>");
TEST_RESULT_VOID(storagePathRemoveP(s3, strNew("/"), .recurse = true), "remove");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove files in empty subpath (nothing to do)");
- testRequestP(s3, HTTP_VERB_GET, "/bucket/?list-type=2&prefix=path%2F");
+ testRequestP(service, s3, HTTP_VERB_GET, "/bucket/?list-type=2&prefix=path%2F");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -841,8 +857,9 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove files with continuation");
- testRequestP(s3, HTTP_VERB_GET, "/bucket/?list-type=2&prefix=path%2Fto%2F");
+ testRequestP(service, s3, HTTP_VERB_GET, "/bucket/?list-type=2&prefix=path%2Fto%2F");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -855,8 +872,9 @@ testRun(void)
" </Contents>"
"</ListBucketResult>");
- testRequestP(s3, HTTP_VERB_GET, "/bucket/?continuation-token=continue&list-type=2&prefix=path%2Fto%2F");
+ testRequestP(service, s3, HTTP_VERB_GET, "/bucket/?continuation-token=continue&list-type=2&prefix=path%2Fto%2F");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -869,31 +887,32 @@ testRun(void)
"</ListBucketResult>");
testRequestP(
- s3, HTTP_VERB_POST, "/bucket/?delete=",
+ service, s3, HTTP_VERB_POST, "/bucket/?delete=",
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<Delete><Quiet>true</Quiet>"
"<Object><Key>path/to/test1.txt</Key></Object>"
"<Object><Key>path/to/test3.txt</Key></Object>"
"</Delete>\n");
- testResponseP();
+ testResponseP(service);
testRequestP(
- s3, HTTP_VERB_POST, "/bucket/?delete=",
+ service, s3, HTTP_VERB_POST, "/bucket/?delete=",
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<Delete><Quiet>true</Quiet>"
"<Object><Key>path/to/test2.txt</Key></Object>"
"</Delete>\n");
- testResponseP();
+ testResponseP(service);
TEST_RESULT_VOID(storagePathRemoveP(s3, strNew("/path/to"), .recurse = true), "remove");
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove error");
- testRequestP(s3, HTTP_VERB_GET, "/bucket/?list-type=2&prefix=path%2F");
+ testRequestP(service, s3, HTTP_VERB_GET, "/bucket/?list-type=2&prefix=path%2F");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<ListBucketResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -906,7 +925,7 @@ testRun(void)
"</ListBucketResult>");
testRequestP(
- s3, HTTP_VERB_POST, "/bucket/?delete=",
+ service, s3, HTTP_VERB_POST, "/bucket/?delete=",
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<Delete><Quiet>true</Quiet>"
@@ -914,6 +933,7 @@ testRun(void)
"<Object><Key>path/sample2.txt</Key></Object>"
"</Delete>\n");
testResponseP(
+ service,
.content =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<DeleteResult xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\">"
@@ -927,13 +947,13 @@ testRun(void)
// -----------------------------------------------------------------------------------------------------------------
TEST_TITLE("remove file");
- testRequestP(s3, HTTP_VERB_DELETE, "/bucket/path/to/test.txt");
- testResponseP(.code = 204);
+ testRequestP(service, s3, HTTP_VERB_DELETE, "/bucket/path/to/test.txt");
+ testResponseP(service, .code = 204);
TEST_RESULT_VOID(storageRemoveP(s3, strNew("/path/to/test.txt")), "remove");
// -----------------------------------------------------------------------------------------------------------------
- hrnTlsClientEnd();
+ hrnServerScriptEnd(service);
}
HARNESS_FORK_PARENT_END();
}
[parent: 7fdbd94e39ff]