|
@@ -34,8 +34,6 @@ import (
|
|
|
"google.golang.org/grpc/metadata"
|
|
"google.golang.org/grpc/metadata"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-func init() { BcryptCost = bcrypt.MinCost }
|
|
|
|
|
-
|
|
|
|
|
func dummyIndexWaiter(index uint64) <-chan struct{} {
|
|
func dummyIndexWaiter(index uint64) <-chan struct{} {
|
|
|
ch := make(chan struct{})
|
|
ch := make(chan struct{})
|
|
|
go func() {
|
|
go func() {
|
|
@@ -54,27 +52,49 @@ func TestNewAuthStoreRevision(t *testing.T) {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
|
}
|
|
}
|
|
|
- as := NewAuthStore(zap.NewExample(), b, tp)
|
|
|
|
|
|
|
+ as := NewAuthStore(zap.NewExample(), b, tp, bcrypt.MinCost)
|
|
|
err = enableAuthAndCreateRoot(as)
|
|
err = enableAuthAndCreateRoot(as)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
|
}
|
|
}
|
|
|
old := as.Revision()
|
|
old := as.Revision()
|
|
|
- b.Close()
|
|
|
|
|
as.Close()
|
|
as.Close()
|
|
|
|
|
+ b.Close()
|
|
|
|
|
|
|
|
// no changes to commit
|
|
// no changes to commit
|
|
|
b2 := backend.NewDefaultBackend(tPath)
|
|
b2 := backend.NewDefaultBackend(tPath)
|
|
|
- as = NewAuthStore(zap.NewExample(), b2, tp)
|
|
|
|
|
|
|
+ as = NewAuthStore(zap.NewExample(), b2, tp, bcrypt.MinCost)
|
|
|
new := as.Revision()
|
|
new := as.Revision()
|
|
|
- b2.Close()
|
|
|
|
|
as.Close()
|
|
as.Close()
|
|
|
|
|
+ b2.Close()
|
|
|
|
|
|
|
|
if old != new {
|
|
if old != new {
|
|
|
t.Fatalf("expected revision %d, got %d", old, new)
|
|
t.Fatalf("expected revision %d, got %d", old, new)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// TestNewAuthStoreBryptCost ensures that NewAuthStore uses default when given bcrypt-cost is invalid
|
|
|
|
|
+func TestNewAuthStoreBcryptCost(t *testing.T) {
|
|
|
|
|
+ b, tPath := backend.NewDefaultTmpBackend()
|
|
|
|
|
+ defer os.Remove(tPath)
|
|
|
|
|
+
|
|
|
|
|
+ tp, err := NewTokenProvider(zap.NewExample(), "simple", dummyIndexWaiter)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ t.Fatal(err)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ invalidCosts := [2]int{bcrypt.MinCost - 1, bcrypt.MaxCost + 1}
|
|
|
|
|
+ for _, invalidCost := range invalidCosts {
|
|
|
|
|
+ as := NewAuthStore(zap.NewExample(), b, tp, invalidCost)
|
|
|
|
|
+ if as.BcryptCost() != bcrypt.DefaultCost {
|
|
|
|
|
+ t.Fatalf("expected DefaultCost when bcryptcost is invalid")
|
|
|
|
|
+ }
|
|
|
|
|
+ as.Close()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ b.Close()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func setupAuthStore(t *testing.T) (store *authStore, teardownfunc func(t *testing.T)) {
|
|
func setupAuthStore(t *testing.T) (store *authStore, teardownfunc func(t *testing.T)) {
|
|
|
b, tPath := backend.NewDefaultTmpBackend()
|
|
b, tPath := backend.NewDefaultTmpBackend()
|
|
|
|
|
|
|
@@ -82,7 +102,7 @@ func setupAuthStore(t *testing.T) (store *authStore, teardownfunc func(t *testin
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
|
}
|
|
}
|
|
|
- as := NewAuthStore(zap.NewExample(), b, tp)
|
|
|
|
|
|
|
+ as := NewAuthStore(zap.NewExample(), b, tp, bcrypt.MinCost)
|
|
|
err = enableAuthAndCreateRoot(as)
|
|
err = enableAuthAndCreateRoot(as)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -519,7 +539,7 @@ func TestAuthInfoFromCtxRace(t *testing.T) {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
|
}
|
|
}
|
|
|
- as := NewAuthStore(zap.NewExample(), b, tp)
|
|
|
|
|
|
|
+ as := NewAuthStore(zap.NewExample(), b, tp, bcrypt.MinCost)
|
|
|
defer as.Close()
|
|
defer as.Close()
|
|
|
|
|
|
|
|
donec := make(chan struct{})
|
|
donec := make(chan struct{})
|
|
@@ -585,7 +605,7 @@ func TestRecoverFromSnapshot(t *testing.T) {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
|
}
|
|
}
|
|
|
- as2 := NewAuthStore(zap.NewExample(), as.be, tp)
|
|
|
|
|
|
|
+ as2 := NewAuthStore(zap.NewExample(), as.be, tp, bcrypt.MinCost)
|
|
|
defer func(a *authStore) {
|
|
defer func(a *authStore) {
|
|
|
a.Close()
|
|
a.Close()
|
|
|
}(as2)
|
|
}(as2)
|
|
@@ -667,7 +687,7 @@ func TestRolesOrder(t *testing.T) {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
|
}
|
|
}
|
|
|
- as := NewAuthStore(zap.NewExample(), b, tp)
|
|
|
|
|
|
|
+ as := NewAuthStore(zap.NewExample(), b, tp, bcrypt.MinCost)
|
|
|
err = enableAuthAndCreateRoot(as)
|
|
err = enableAuthAndCreateRoot(as)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
@@ -713,7 +733,7 @@ func TestAuthInfoFromCtxWithRoot(t *testing.T) {
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
|
}
|
|
}
|
|
|
- as := NewAuthStore(zap.NewExample(), b, tp)
|
|
|
|
|
|
|
+ as := NewAuthStore(zap.NewExample(), b, tp, bcrypt.MinCost)
|
|
|
defer as.Close()
|
|
defer as.Close()
|
|
|
|
|
|
|
|
if err = enableAuthAndCreateRoot(as); err != nil {
|
|
if err = enableAuthAndCreateRoot(as); err != nil {
|