[FIXED] allow_non_tls is lost after server reload

The server would reset its INFO's TLSRequired to the presence
of a TLS configuration without checking for the allow_non_tls
option.

Resolves #3581

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
Ivan Kozlovic
2022-10-27 09:49:44 -06:00
parent 8cc87c988f
commit b3e0431959
2 changed files with 38 additions and 1 deletions

View File

@@ -206,7 +206,7 @@ type tlsOption struct {
func (t *tlsOption) Apply(server *Server) {
server.mu.Lock()
tlsRequired := t.newValue != nil
server.info.TLSRequired = tlsRequired
server.info.TLSRequired = tlsRequired && !server.getOpts().AllowNonTLS
message := "disabled"
if tlsRequired {
server.info.TLSVerify = (t.newValue.ClientAuth == tls.RequireAndVerifyClientCert)

View File

@@ -1973,3 +1973,40 @@ func TestTLSPinnedCertsRoute(t *testing.T) {
checkNumRoutes(t, srvSeed, 0)
checkNumRoutes(t, srv, 0)
}
func TestAllowNonTLSReload(t *testing.T) {
tmpl := `
listen: "127.0.0.1:-1"
ping_interval: "%s"
tls {
ca_file: "configs/certs/ca.pem"
cert_file: "configs/certs/server-cert.pem"
key_file: "configs/certs/server-key.pem"
}
allow_non_tls: true
`
conf := createConfFile(t, []byte(fmt.Sprintf(tmpl, "10s")))
defer removeFile(t, conf)
s, o := RunServerWithConfig(conf)
defer s.Shutdown()
check := func() {
t.Helper()
nc := createClientConn(t, "127.0.0.1", o.Port)
defer nc.Close()
info := checkInfoMsg(t, nc)
if !info.TLSAvailable {
t.Fatal("TLSAvailable should be true, was false")
}
if info.TLSRequired {
t.Fatal("TLSRequired should be false, was true")
}
}
check()
os.WriteFile(conf, []byte(fmt.Sprintf(tmpl, "20s")), 0660)
if err := s.Reload(); err != nil {
t.Fatalf("Error on reload: %v", err)
}
check()
}