From 3ec96cdb38955e8f1d983ad710354ec28cab218f Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Thu, 16 Nov 2023 16:19:12 -0700 Subject: [PATCH] Added test for recent tls_available fix There was an external contribution that fixed tls_available, but test was missing. Also fixed some warnings in test.c. Signed-off-by: Ivan Kozlovic --- test/list.txt | 1 + test/test.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/test/list.txt b/test/list.txt index 4c78d876d..af5eb0c9e 100644 --- a/test/list.txt +++ b/test/list.txt @@ -191,6 +191,7 @@ SSLMultithreads SSLConnectVerboseOption SSLSocketLeakEventLoop SSLReconnectWithAuthError +SSLAvailable ServersOption AuthServers AuthFailToReconnect diff --git a/test/test.c b/test/test.c index 1e9ab7dfa..4509e7014 100644 --- a/test/test.c +++ b/test/test.c @@ -93,6 +93,7 @@ static const char *clientName = "client"; // Forward declaration static void _startMockupServerThread(void *closure); +static void _createConfFile(char *buf, int bufLen, const char *content); typedef natsStatus (*testCheckInfoCB)(char *buffer); @@ -21602,6 +21603,53 @@ test_SSLReconnectWithAuthError(void) #endif } +static void +test_SSLAvailable(void) +{ +#if defined(NATS_HAS_TLS) + natsStatus s; + natsConnection *nc = NULL; + natsOptions *opts = NULL; + natsPid serverPid = NATS_INVALID_PID; + char conf[256]; + char cmdLine[1024]; + + _createConfFile(conf, sizeof(conf), "allow_non_tls: true\n"); + test("Start server: "); + snprintf(cmdLine, sizeof(cmdLine), "-tls -tlscert certs/server-cert.pem -tlskey certs/server-key.pem -tlscacert certs/ca.pem -c %s", conf); + serverPid = _startServer("nats://127.0.0.1:4222", cmdLine, true); + CHECK_SERVER_STARTED(serverPid); + testCond(true); + + test("Create options: "); + s = natsOptions_Create(&opts); + IFOK(s, natsOptions_SetSecure(opts, true)); + IFOK(s, natsOptions_SkipServerVerification(opts, true)); + IFOK(s, natsOptions_SetURL(opts, "tls://localhost:4222")); + testCond(s == NATS_OK); + + test("Connect with TLS: "); + s = natsConnection_Connect(&nc, opts); + testCond(s == NATS_OK); + + natsConnection_Destroy(nc); + nc = NULL; + natsOptions_Destroy(opts); + opts = NULL; + + test("Connection without: "); + s = natsConnection_ConnectTo(&nc, "nats://localhost:4222"); + testCond(s == NATS_OK); + natsConnection_Destroy(nc); + + _stopServer(serverPid); + remove(conf); +#else + test("Skipped when built with no SSL support: "); + testCond(true); +#endif +} + static void rmtree(const char *path) { @@ -32949,6 +32997,7 @@ test_MicroBasics(void) .Name = "do", .Subject = "svc.do", .Handler = _microHandleRequestNoisy42, + .State = NULL, }; microEndpointConfig ep2_cfg = { .Name = "unused", @@ -32958,6 +33007,7 @@ test_MicroBasics(void) .List = (const char *[]){"key1", "value1", "key2", "value2", "key3", "value3"}, .Count = 3, }, + .State = NULL, }; microEndpointConfig *eps[] = { &ep1_cfg, @@ -32971,6 +33021,8 @@ test_MicroBasics(void) .List = (const char *[]){"skey1", "svalue1", "skey2", "svalue2"}, .Count = 2, }, + .Endpoint = NULL, + .State = NULL, }; natsMsg *reply = NULL; microServiceInfo *info = NULL; @@ -35952,6 +36004,7 @@ static testInfo allTests[] = {"SSLConnectVerboseOption", test_SSLConnectVerboseOption}, {"SSLSocketLeakEventLoop", test_SSLSocketLeakWithEventLoop}, {"SSLReconnectWithAuthError", test_SSLReconnectWithAuthError}, + {"SSLAvailable", test_SSLAvailable}, // Clusters Tests