auth: return incorrect result 'ErrUserNotFound' when client request without username or username was empty.

Fiexs https://github.com/etcd-io/etcd/issues/12004 .
This commit is contained in:
cfc4n
2020-06-12 22:43:07 +08:00
committed by CFC4N
parent 31e49a4df3
commit 490c6139ac
3 changed files with 9 additions and 3 deletions

View File

@@ -995,7 +995,7 @@ func (as *authStore) IsAdminPermitted(authInfo *AuthInfo) error {
if !as.IsAuthEnabled() {
return nil
}
if authInfo == nil {
if authInfo == nil || authInfo.Username == "" {
return ErrUserEmpty
}

View File

@@ -658,6 +658,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 {