Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow $G to be listed in accounts option #5753

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 0 additions & 11 deletions server/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3108,12 +3108,6 @@ func parseAccounts(v any, opts *Options, errors *[]error, warnings *[]error) err
for _, n := range v.([]any) {
tk, name := unwrapValue(n, &lt)
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)
Expand Down Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion server/opts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 0 additions & 6 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down