lock users access

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2018-06-03 20:41:59 -07:00
parent cc07d500dd
commit 4dd4d2bd9d
4 changed files with 13 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
language: go
go:
- 1.9.x
- 1.10.x
- 1.9.6
- 1.10.2
install:
- go get github.com/nats-io/go-nats
- go get github.com/mattn/goveralls

View File

@@ -122,6 +122,14 @@ func (s *Server) checkAuthorization(c *client) bool {
}
}
// hasUsers leyt's us know if we have a users array.
func (s *Server) hasUsers() bool {
s.mu.Lock()
hu := s.users != nil
s.mu.Unlock()
return hu
}
// isClientAuthorized will check the client against the proper authorization method and data.
// This could be token or username/password based.
func (s *Server) isClientAuthorized(c *client) bool {
@@ -131,7 +139,7 @@ func (s *Server) isClientAuthorized(c *client) bool {
// Check custom auth first, then multiple users, then token, then single user/pass.
if opts.CustomClientAuthentication != nil {
return opts.CustomClientAuthentication.Check(c)
} else if s.users != nil {
} else if s.hasUsers() {
user, ok := s.users[c.opts.Username]
if !ok {
return false

View File

@@ -943,7 +943,7 @@ func TestRoutedQueueAutoUnsubscribe(t *testing.T) {
c.Flush()
}
wait := time.Now().Add(5 * time.Second)
wait := time.Now().Add(10 * time.Second)
for time.Now().Before(wait) {
nbar := atomic.LoadInt32(&rbar)
nbaz := atomic.LoadInt32(&rbaz)
@@ -962,7 +962,7 @@ func TestRoutedQueueAutoUnsubscribe(t *testing.T) {
}
return
}
time.Sleep(10 * time.Millisecond)
time.Sleep(100 * time.Millisecond)
}
t.Fatalf("Did not receive all %d queue messages, received %d for 'bar' and %d for 'baz'\n",
expected, atomic.LoadInt32(&rbar), atomic.LoadInt32(&rbaz))

View File

@@ -515,23 +515,9 @@ func TestRouteFormTimeWithHighSubscriptions(t *testing.T) {
checkClusterFormed(t, srvA, srvB)
// Now wait for all subscriptions to be processed.
if err := checkExpectedSubs(subsTotal, srvB); err != nil {
t.Fatalf("%v", err)
}
/*
maxTime := time.Now().Add(5 * time.Second)
for time.Now().Before(maxTime) {
if srvB.NumSubscriptions() == subsTotal {
break
}
time.Sleep(10 * time.Millisecond)
}
if srvB.NumSubscriptions() != subsTotal {
t.Fatalf("srvB did not receive all subscriptions in allocated time: %d",
srvB.NumSubscriptions())
}
*/
fmt.Printf("Cluster formed after %v\n", time.Since(now))
}