Skip to content

Commit

Permalink
Merge eab4af0 into e78828c
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlovic committed Oct 3, 2018
2 parents e78828c + eab4af0 commit 200d002
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/opts.go
Expand Up @@ -338,11 +338,13 @@ func (o *Options) ProcessConfigFile(configFile string) error {
if auth.token != "" {
return fmt.Errorf("Can not have a token and a users array")
}
o.Users = auth.users
// Users may have been added from Accounts parsing, so do an append here
o.Users = append(o.Users, auth.users...)
}
// Check for nkeys
if auth.nkeys != nil {
o.Nkeys = auth.nkeys
// NKeys may have been added from Accounts parsing, so do an append here
o.Nkeys = append(o.Nkeys, auth.nkeys...)
}
case "http":
hp, err := parseListen(v)
Expand Down
37 changes: 37 additions & 0 deletions server/opts_test.go
Expand Up @@ -1408,3 +1408,40 @@ func TestClusterPermissionsConfig(t *testing.T) {
}
}
}

func TestAccountUsersLoadedProperly(t *testing.T) {
conf := createConfFile(t, []byte(`
listen: "127.0.0.1:-1"
authorization {
users [
{user: ivan, password: bar}
{nkey : UC6NLCN7AS34YOJVCYD4PJ3QB7QGLYG5B5IMBT25VW5K4TNUJODM7BOX}
]
}
accounts {
synadia {
users [
{user: derek, password: foo}
{nkey : UBAAQWTW6CG2G6ANGNKB5U2B7HRWHSGMZEZX3AQSAJOQDAUGJD46LD2E}
]
}
}
`))
check := func(t *testing.T) {
t.Helper()
s, _ := RunServerWithConfig(conf)
defer s.Shutdown()
opts := s.getOpts()
if n := len(opts.Users); n != 2 {
t.Fatalf("Should have 2 users, got %v", n)
}
if n := len(opts.Nkeys); n != 2 {
t.Fatalf("Should have 2 nkeys, got %v", n)
}
}
// Repeat test since issue was with ordering of processing
// of authorization vs accounts that depends on range of a map (after actual parsing)
for i := 0; i < 20; i++ {
check(t)
}
}

0 comments on commit 200d002

Please sign in to comment.