diff --git a/server/events_test.go b/server/events_test.go index b7f30eee..e4149a00 100644 --- a/server/events_test.go +++ b/server/events_test.go @@ -1041,7 +1041,7 @@ func TestServerEventStatsZ(t *testing.T) { if m.Stats.ActiveAccounts != 2 { t.Fatalf("Did not match active accounts of 2, got %d", m.Stats.ActiveAccounts) } - if m.Stats.Sent.Msgs != 2 { + if m.Stats.Sent.Msgs != 1 { t.Fatalf("Did not match sent msgs of 1, got %d", m.Stats.Sent.Msgs) } if m.Stats.Received.Msgs != 1 { diff --git a/server/nkey.go b/server/nkey.go index de671a01..a792c6e0 100644 --- a/server/nkey.go +++ b/server/nkey.go @@ -23,13 +23,17 @@ const ( nonceLen = 15 // base64.RawURLEncoding.EncodedLen(nonceRawLen) ) -// nonceRequired tells us if we should send a nonce. -// Assumes server lock is held -func (s *Server) nonceRequired() bool { - s.optsMu.RLock() - defer s.optsMu.RUnlock() +// NonceRequired tells us if we should send a nonce. +func (s *Server) NonceRequired() bool { + s.mu.Lock() + defer s.mu.Unlock() + return s.nonceRequired() +} - return len(s.opts.Nkeys) > 0 || len(s.opts.TrustedKeys) > 0 +// nonceRequired tells us if we should send a nonce. +// Lock should be held on entry. +func (s *Server) nonceRequired() bool { + return len(s.nkeys) > 0 || len(s.trustedKeys) > 0 } // Generate a nonce for INFO challenge. diff --git a/test/operator_test.go b/test/operator_test.go index e692b41c..a639ce7f 100644 --- a/test/operator_test.go +++ b/test/operator_test.go @@ -240,6 +240,7 @@ func TestOperatorSigningKeys(t *testing.T) { func TestOperatorMemResolverPreload(t *testing.T) { s, opts := RunServerWithConfig("./configs/resolver_preload.conf") + defer s.Shutdown() // Make sure we can look up the account. acc, _ := s.LookupAccount("ADM2CIIL3RWXBA6T2HW3FODNCQQOUJEHHQD6FKCPVAMHDNTTSMO73ROX") @@ -254,3 +255,20 @@ func TestOperatorMemResolverPreload(t *testing.T) { t.Fatalf("System account does not match, wanted %q, got %q", opts.SystemAccount, sacc.Name) } } + +func TestOperatorConfigReloadDoesntKillNonce(t *testing.T) { + s, _ := runOperatorServer(t) + defer s.Shutdown() + + if !s.NonceRequired() { + t.Fatalf("Error nonce should be required") + } + + if err := s.Reload(); err != nil { + t.Fatalf("Error on reload: %v", err) + } + + if !s.NonceRequired() { + t.Fatalf("Error nonce should still be required after reload") + } +}