mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Merge pull request #2696 from ripienaar/always_nonce
support always presenting a nonce to clients
This commit is contained in:
@@ -33,7 +33,7 @@ func (s *Server) NonceRequired() bool {
|
||||
// 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 || s.trustedKeys != nil
|
||||
return s.opts.AlwaysEnableNonce || len(s.nkeys) > 0 || s.trustedKeys != nil
|
||||
}
|
||||
|
||||
// Generate a nonce for INFO challenge.
|
||||
|
||||
@@ -54,6 +54,28 @@ func mixedSetup() (*Server, *testAsyncClient, *bufio.Reader, string) {
|
||||
return rawSetup(opts)
|
||||
}
|
||||
|
||||
func TestServerInfoNonceAlwaysEnabled(t *testing.T) {
|
||||
opts := defaultServerOptions
|
||||
opts.AlwaysEnableNonce = true
|
||||
s, c, _, l := rawSetup(opts)
|
||||
defer s.WaitForShutdown()
|
||||
defer s.Shutdown()
|
||||
defer c.close()
|
||||
|
||||
if !strings.HasPrefix(l, "INFO ") {
|
||||
t.Fatalf("INFO response incorrect: %s\n", l)
|
||||
}
|
||||
|
||||
var info nonceInfo
|
||||
err := json.Unmarshal([]byte(l[5:]), &info)
|
||||
if err != nil {
|
||||
t.Fatalf("Could not parse INFO json: %v\n", err)
|
||||
}
|
||||
if info.Nonce == "" {
|
||||
t.Fatalf("Expected a non-empty nonce with AlwaysEnableNonce set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerInfoNonce(t *testing.T) {
|
||||
c, l := setUpClientWithResponse()
|
||||
defer c.close()
|
||||
|
||||
@@ -262,6 +262,11 @@ type Options struct {
|
||||
AccountResolver AccountResolver `json:"-"`
|
||||
AccountResolverTLSConfig *tls.Config `json:"-"`
|
||||
|
||||
// AlwaysEnableNonce will always present a nonce to new connections
|
||||
// typically used by custom Authentication implementations who embeds
|
||||
// the server and so not presented as a configuration option
|
||||
AlwaysEnableNonce bool
|
||||
|
||||
CustomClientAuthentication Authentication `json:"-"`
|
||||
CustomRouterAuthentication Authentication `json:"-"`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user