Skip to content

Commit

Permalink
Add unit test to prove connection works
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Twigg <neil@nats.io>
  • Loading branch information
neilalexander committed Jul 20, 2023
1 parent 7993547 commit b7d6b7e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/tls_test.go
Expand Up @@ -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()
Expand Down

0 comments on commit b7d6b7e

Please sign in to comment.