From 9af731d0ddced54cf585e14a6d95ac663f4b7cfd Mon Sep 17 00:00:00 2001 From: Byron Ruth Date: Mon, 5 Aug 2024 15:31:59 -0400 Subject: [PATCH] Allow $G to be listed in `accounts` option Signed-off-by: Byron Ruth --- server/accounts_test.go | 2 +- server/opts.go | 11 ----------- server/opts_test.go | 22 +++++++++++++++++++++- server/server.go | 6 ------ 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/server/accounts_test.go b/server/accounts_test.go index eca0374a78a..1502223f974 100644 --- a/server/accounts_test.go +++ b/server/accounts_test.go @@ -388,7 +388,7 @@ func TestAccountFromOptions(t *testing.T) { s := New(&opts) defer s.Shutdown() - ta := s.numReservedAccounts() + 2 + ta := 2 if la := s.numAccounts(); la != ta { t.Fatalf("Expected to have a server with %d active accounts, got %v", ta, la) } diff --git a/server/opts.go b/server/opts.go index ab5f6c60b17..ebb9bb1c88b 100644 --- a/server/opts.go +++ b/server/opts.go @@ -3108,12 +3108,6 @@ func parseAccounts(v any, opts *Options, errors *[]error, warnings *[]error) err for _, n := range v.([]any) { tk, name := unwrapValue(n, <) ns := name.(string) - // Check for reserved names. - if isReservedAccount(ns) { - err := &configErr{tk, fmt.Sprintf("%q is a Reserved Account", ns)} - *errors = append(*errors, err) - continue - } if _, ok := m[ns]; ok { err := &configErr{tk, fmt.Sprintf("Duplicate Account Entry: %s", ns)} *errors = append(*errors, err) @@ -3145,11 +3139,6 @@ func parseAccounts(v any, opts *Options, errors *[]error, warnings *[]error) err *errors = append(*errors, err) continue } - if isReservedAccount(aname) { - err := &configErr{tk, fmt.Sprintf("%q is a Reserved Account", aname)} - *errors = append(*errors, err) - continue - } var ( users []*User nkeyUsr []*NkeyUser diff --git a/server/opts_test.go b/server/opts_test.go index 41a36ee9c53..c83a00992ae 100644 --- a/server/opts_test.go +++ b/server/opts_test.go @@ -2646,7 +2646,7 @@ func TestSublistNoCacheConfigOnAccounts(t *testing.T) { defer s.Shutdown() // Check that all account sublists do not have caching enabled. - ta := s.numReservedAccounts() + 2 + ta := 2 if la := s.numAccounts(); la != ta { t.Fatalf("Expected to have a server with %d active accounts, got %v", ta, la) } @@ -3228,7 +3228,27 @@ func TestGetStorageSize(t *testing.T) { t.Errorf("Got: %v, want %v with error: %v", got, v.want, testErr) } } +} +func TestGlobalAccountInAccounts(t *testing.T) { + conf := ` + accounts { + $G: { + users: [{ user: default, password: default }] + } + SYS: { + users: [{ user: sys, password: sys }] + } + } + no_auth_user: default + system_account: SYS + ` + + confFile := createConfFile(t, []byte(conf)) + _, err := ProcessConfigFile(confFile) + if err != nil { + t.Fatal(err) + } } func TestAuthorizationAndAccountsMisconfigurations(t *testing.T) { diff --git a/server/server.go b/server/server.go index fb40f43f15e..ad1a67c46da 100644 --- a/server/server.go +++ b/server/server.go @@ -1595,12 +1595,6 @@ func (s *Server) logPid() error { return os.WriteFile(s.getOpts().PidFile, []byte(pidStr), 0660) } -// numReservedAccounts will return the number of reserved accounts configured in the server. -// Currently this is 1, one for the global default account. -func (s *Server) numReservedAccounts() int { - return 1 -} - // NumActiveAccounts reports number of active accounts on this server. func (s *Server) NumActiveAccounts() int32 { return atomic.LoadInt32(&s.activeAccounts)