Skip to content

Commit

Permalink
auth: return incorrect result 'ErrUserNotFound' when client request w…
Browse files Browse the repository at this point in the history
…ithout username or username was empty. (#12005)

Fiexs #12004 .
  • Loading branch information
cfc4n authored Jun 12, 2020
1 parent b0d2edf commit b6d1987
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion auth/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ func (as *authStore) IsAdminPermitted(authInfo *AuthInfo) error {
if !as.IsAuthEnabled() {
return nil
}
if authInfo == nil {
if authInfo == nil || authInfo.Username == "" {
return ErrUserEmpty
}

Expand Down
6 changes: 6 additions & 0 deletions auth/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ func TestIsAdminPermitted(t *testing.T) {
t.Errorf("expected %v, got %v", ErrUserNotFound, err)
}

// empty user
err = as.IsAdminPermitted(&AuthInfo{Username: "", Revision: 1})
if err != ErrUserEmpty {
t.Errorf("expected %v, got %v", ErrUserEmpty, err)
}

// non-admin user
err = as.IsAdminPermitted(&AuthInfo{Username: "foo", Revision: 1})
if err != ErrPermissionDenied {
Expand Down
4 changes: 2 additions & 2 deletions clientv3/integration/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func TestUserErrorAuth(t *testing.T) {
authSetupRoot(t, authapi.Auth)

// unauthenticated client
if _, err := authapi.UserAdd(context.TODO(), "foo", "bar"); err != rpctypes.ErrUserNotFound {
t.Fatalf("expected %v, got %v", rpctypes.ErrUserNotFound, err)
if _, err := authapi.UserAdd(context.TODO(), "foo", "bar"); err != rpctypes.ErrUserEmpty {
t.Fatalf("expected %v, got %v", rpctypes.ErrUserEmpty, err)
}

// wrong id or password
Expand Down

0 comments on commit b6d1987

Please sign in to comment.