Skip to content

Commit

Permalink
code review + rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
thierryba committed Aug 12, 2024
1 parent 3ac3650 commit b0c17e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,12 @@ natsOptions_SetSecure(natsOptions *opts, bool secure)
natsStatus
natsOptions_TLSHandshakeFirst(natsOptions *opts)
{
natsStatus s = NATS_OK;

LOCK_AND_CHECK_OPTIONS(opts, 0);

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

UNLOCK_OPTS(opts);

Expand Down
16 changes: 8 additions & 8 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -21328,15 +21328,15 @@ void test_SSLHandshakeFirst(void)
{
// 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));
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);
natsConnection_Destroy(nc);
natsOptions_Destroy(opts);
natsOptions_Destroy(no_secure_opts);
nats_clearLastError();
}

Expand Down

0 comments on commit b0c17e9

Please sign in to comment.