mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Fix resetting TLS name from solicited remotes
In +Go 1.20, the x509.HostnameError changed to be wrapped in a tls.CertificateVerificationError so sometimes the name would not be reset causing tests to be extra flaky. Signed-off-by: Waldemar Quevedo <wally@nats.io>
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
@@ -33,7 +34,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/klauspost/compress/s2"
|
||||
|
||||
"github.com/nats-io/jwt/v2"
|
||||
)
|
||||
|
||||
@@ -5502,7 +5502,10 @@ func (c *client) doTLSHandshake(typ string, solicit bool, url *url.URL, tlsConfi
|
||||
if solicit {
|
||||
// Based on type of error, possibly clear the saved tlsName
|
||||
// See: https://github.com/nats-io/nats-server/issues/1256
|
||||
if _, ok := err.(x509.HostnameError); ok {
|
||||
// NOTE: As of Go 1.20, the HostnameError is wrapped so cannot
|
||||
// type assert to check directly.
|
||||
var hostnameErr x509.HostnameError
|
||||
if errors.As(err, &hostnameErr) {
|
||||
if host == tlsName {
|
||||
resetTLSName = true
|
||||
}
|
||||
|
||||
@@ -605,8 +605,13 @@ func TestGatewayTLSMixedIPAndDNS(t *testing.T) {
|
||||
server.SetGatewaysSolicitDelay(5 * time.Millisecond)
|
||||
defer server.ResetGatewaysSolicitDelay()
|
||||
|
||||
// Run this test extra times to make sure not flaky since it
|
||||
// on solicit time.
|
||||
for i := 0; i < 10; i++ {
|
||||
t.Run("", func(t *testing.T) {
|
||||
confA1 := createConfFile(t, []byte(`
|
||||
listen: 127.0.0.1:-1
|
||||
server_name: A1
|
||||
gateway {
|
||||
name: "A"
|
||||
listen: "127.0.0.1:-1"
|
||||
@@ -619,13 +624,13 @@ func TestGatewayTLSMixedIPAndDNS(t *testing.T) {
|
||||
}
|
||||
cluster {
|
||||
listen: "127.0.0.1:-1"
|
||||
}
|
||||
`))
|
||||
}`))
|
||||
srvA1, optsA1 := RunServerWithConfig(confA1)
|
||||
defer srvA1.Shutdown()
|
||||
|
||||
confA2Template := `
|
||||
listen: 127.0.0.1:-1
|
||||
server_name: A2
|
||||
gateway {
|
||||
name: "A"
|
||||
listen: "localhost:-1"
|
||||
@@ -641,8 +646,7 @@ func TestGatewayTLSMixedIPAndDNS(t *testing.T) {
|
||||
routes [
|
||||
"nats://%s:%d"
|
||||
]
|
||||
}
|
||||
`
|
||||
}`
|
||||
confA2 := createConfFile(t, []byte(fmt.Sprintf(confA2Template,
|
||||
optsA1.Cluster.Host, optsA1.Cluster.Port)))
|
||||
srvA2, optsA2 := RunServerWithConfig(confA2)
|
||||
@@ -653,6 +657,7 @@ func TestGatewayTLSMixedIPAndDNS(t *testing.T) {
|
||||
// Create a GW connection to cluster "A". Don't use the helper since we need verification etc.
|
||||
o := DefaultTestOptions
|
||||
o.Port = -1
|
||||
o.ServerName = "B1"
|
||||
o.Gateway.Name = "B"
|
||||
o.Gateway.Host = "127.0.0.1"
|
||||
o.Gateway.Port = -1
|
||||
@@ -687,7 +692,9 @@ func TestGatewayTLSMixedIPAndDNS(t *testing.T) {
|
||||
srvA2.Shutdown()
|
||||
|
||||
// Make sure this works.
|
||||
waitForOutboundGateways(t, srvB, 1, 10*time.Second)
|
||||
waitForOutboundGateways(t, srvB, 1, 30*time.Second)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatewayAdvertiseInCluster(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user