Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test for recent tls_available fix #697

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ SSLMultithreads
SSLConnectVerboseOption
SSLSocketLeakEventLoop
SSLReconnectWithAuthError
SSLAvailable
ServersOption
AuthServers
AuthFailToReconnect
Expand Down
53 changes: 53 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -32949,6 +32997,7 @@ test_MicroBasics(void)
.Name = "do",
.Subject = "svc.do",
.Handler = _microHandleRequestNoisy42,
.State = NULL,
};
microEndpointConfig ep2_cfg = {
.Name = "unused",
Expand All @@ -32958,6 +33007,7 @@ test_MicroBasics(void)
.List = (const char *[]){"key1", "value1", "key2", "value2", "key3", "value3"},
.Count = 3,
},
.State = NULL,
};
microEndpointConfig *eps[] = {
&ep1_cfg,
Expand All @@ -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;
Expand Down Expand Up @@ -35952,6 +36004,7 @@ static testInfo allTests[] =
{"SSLConnectVerboseOption", test_SSLConnectVerboseOption},
{"SSLSocketLeakEventLoop", test_SSLSocketLeakWithEventLoop},
{"SSLReconnectWithAuthError", test_SSLReconnectWithAuthError},
{"SSLAvailable", test_SSLAvailable},

// Clusters Tests

Expand Down