From b7d6b7e7a92612947b2c00be6165c81116db531a Mon Sep 17 00:00:00 2001 From: Neil Twigg Date: Thu, 20 Jul 2023 11:01:32 +0100 Subject: [PATCH] Add unit test to prove connection works Signed-off-by: Neil Twigg --- test/tls_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/tls_test.go b/test/tls_test.go index 19fb800e..2c4111aa 100644 --- a/test/tls_test.go +++ b/test/tls_test.go @@ -72,6 +72,26 @@ func TestTLSConnection(t *testing.T) { } } +// TestTLSInProcessConnection checks that even if TLS is enabled on the server, +// that an in-process connection that does *not* use TLS still connects successfully. +func TestTLSInProcessConnection(t *testing.T) { + srv, opts := RunServerWithConfig("./configs/tls.conf") + defer srv.Shutdown() + + nc, err := nats.Connect("", nats.InProcessServer(srv), nats.UserInfo(opts.Username, opts.Password)) + if err != nil { + t.Fatal(err) + } + + if nc.TLSRequired() { + t.Fatalf("Shouldn't have required TLS for in-process connection") + } + + if _, err = nc.TLSConnectionState(); err == nil { + t.Fatal("Should have got an error retrieving TLS connection state") + } +} + func TestTLSClientCertificate(t *testing.T) { srv, opts := RunServerWithConfig("./configs/tlsverify.conf") defer srv.Shutdown()