Skip to content

Commit

Permalink
Fixing setting handshake_first without setting secure in the natsOptions
Browse files Browse the repository at this point in the history
some tests seem unstable...
  • Loading branch information
thierryba committed Aug 12, 2024
1 parent 01cfb28 commit 3ac3650
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,10 @@ natsOptions_SetSecure(natsOptions *opts, bool secure)
natsStatus
natsOptions_TLSHandshakeFirst(natsOptions *opts)
{
natsStatus s = NATS_OK;

LOCK_AND_CHECK_OPTIONS(opts, 0);

opts->tlsHandshakeFirst = true;
opts->secure = true;
natsStatus s = natsOptions_SetSecure(opts, true);

UNLOCK_OPTS(opts);

Expand Down
16 changes: 16 additions & 0 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21324,6 +21324,22 @@ void test_SSLHandshakeFirst(void)
s = natsOptions_TLSHandshakeFirst(opts);
testCond(s == NATS_OK);

test("Set TLSHandshakeFirst option without setting secure: ");
{
// we start with a new natsOptions struct so that we can test
// that it does not crash with a minimal config
natsOptions *opts = NULL;
s = natsOptions_Create(&opts);
IFOK(s, natsOptions_SetURL(opts, "nats://127.0.0.1:4443"));
IFOK(s, natsOptions_SetTimeout(opts, 500));
s = natsOptions_TLSHandshakeFirst(opts);
IFOK(s, natsConnection_Connect(&nc, opts));
testCond(s == NATS_SSL_ERROR);
natsConnection_Destroy(nc);
natsOptions_Destroy(opts);
nats_clearLastError();
}

test("Check that connect succeeds: ");
s = natsConnection_Connect(&nc, opts);
testCond(s == NATS_OK);
Expand Down

0 comments on commit 3ac3650

Please sign in to comment.