Skip to content

Commit

Permalink
Merge pull request #14649 from mitake/test-authrecover-3.4
Browse files Browse the repository at this point in the history
[3.4] server: add a unit test case for authStore.Reocver() with empty rangePermCache
  • Loading branch information
ahrtr authored Oct 29, 2022
2 parents ce1630f + b7a2331 commit 7c1499d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions auth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ func (as *authStore) Recover(be backend.Backend) {
}

as.setRevision(getRevision(tx))
as.refreshRangePermCache(tx)

tx.Unlock()

Expand Down
24 changes: 24 additions & 0 deletions auth/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,30 @@ func TestRecover(t *testing.T) {
}
}

func TestRecoverWithEmptyRangePermCache(t *testing.T) {
as, tearDown := setupAuthStore(t)
defer as.Close()
defer tearDown(t)

as.enabled = false
as.rangePermCache = map[string]*unifiedRangePermissions{}
as.Recover(as.be)

if !as.IsAuthEnabled() {
t.Fatalf("expected auth enabled got disabled")
}

if len(as.rangePermCache) != 2 {
t.Fatalf("rangePermCache should have permission information for 2 users (\"root\" and \"foo\"), but has %d information", len(as.rangePermCache))
}
if _, ok := as.rangePermCache["root"]; !ok {
t.Fatal("user \"root\" should be created by setupAuthStore() but doesn't exist in rangePermCache")
}
if _, ok := as.rangePermCache["foo"]; !ok {
t.Fatal("user \"foo\" should be created by setupAuthStore() but doesn't exist in rangePermCache")
}
}

func TestCheckPassword(t *testing.T) {
as, tearDown := setupAuthStore(t)
defer tearDown(t)
Expand Down

0 comments on commit 7c1499d

Please sign in to comment.