Skip to content

Commit

Permalink
Fixing setting handshake_first without setting secure in the natsOpti…
Browse files Browse the repository at this point in the history
…ons (nats-io#789)

* Fixing setting handshake_first without setting secure in the natsOptions

some tests seem unstable...

* code review + rebuild

* more code review

unstable tests...

---------

Co-authored-by: Lev <1187448+levb@users.noreply.github.com>
  • Loading branch information
thierryba and levb authored Aug 12, 2024
1 parent c4a26a5 commit e7d767e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,11 @@ natsOptions_TLSHandshakeFirst(natsOptions *opts)

LOCK_AND_CHECK_OPTIONS(opts, 0);

opts->tlsHandshakeFirst = true;
opts->secure = true;
s = natsOptions_SetSecure(opts, true);
if (s == NATS_OK)
{
opts->tlsHandshakeFirst = 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 *no_secure_opts = NULL;
s = natsOptions_Create(&no_secure_opts);
IFOK(s, natsOptions_SetURL(no_secure_opts, "nats://127.0.0.1:4443"));
IFOK(s, natsOptions_SetTimeout(no_secure_opts, 500));
IFOK(s, natsOptions_TLSHandshakeFirst(no_secure_opts));
IFOK(s, natsConnection_Connect(&nc, no_secure_opts));
// expecting an error because cert valiation will fail; the goal here is to avoid a crash
testCond(s == NATS_SSL_ERROR);
natsOptions_Destroy(no_secure_opts);
nats_clearLastError();
}

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

0 comments on commit e7d767e

Please sign in to comment.