Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test gateway tlsConfig.ServerName #943

Merged
merged 1 commit into from
Apr 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions server/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,41 @@ func TestGatewayTLSErrors(t *testing.T) {
waitForGatewayFailedConnect(t, s1, "B", true, 2*time.Second)
}

func TestGatewayServerNameInTLSConfig(t *testing.T) {
o2 := testDefaultOptionsForGateway("B")
var (
tc = &TLSConfigOpts{}
err error
)
tc.CertFile = "../test/configs/certs/server-noip.pem"
tc.KeyFile = "../test/configs/certs/server-key-noip.pem"
tc.CaFile = "../test/configs/certs/ca.pem"
o2.Gateway.TLSConfig, err = GenTLSConfig(tc)
if err != nil {
t.Fatalf("Error generating TLS config: %v", err)
}
o2.Gateway.TLSConfig.ClientAuth = tls.RequireAndVerifyClientCert
o2.Gateway.TLSConfig.RootCAs = o2.Gateway.TLSConfig.ClientCAs
o2.Gateway.TLSTimeout = 2.0
s2 := runGatewayServer(o2)
defer s2.Shutdown()

o1 := testGatewayOptionsFromToWithTLS(t, "A", "B", []string{fmt.Sprintf("nats://127.0.0.1:%d", s2.GatewayAddr().Port)})
s1 := runGatewayServer(o1)
defer s1.Shutdown()

// s1 should fail to connect since we don't have proper expected hostname.
waitForGatewayFailedConnect(t, s1, "B", true, 2*time.Second)

// Now set server name, and it should work.
s1.Shutdown()
o1.Gateway.TLSConfig.ServerName = "localhost"
s1 = runGatewayServer(o1)
defer s1.Shutdown()

waitForOutboundGateways(t, s1, 1, 2*time.Second)
}

func TestGatewayWrongDestination(t *testing.T) {
// Start a server with a gateway named "C"
o2 := testDefaultOptionsForGateway("C")
Expand Down