Fail authentication when username is empty (#2300) (#2303)

This commit is contained in:
Daniel Jiang 2017-05-15 14:35:38 -07:00 committed by GitHub
parent eb9497abd1
commit 4f66279c33
2 changed files with 13 additions and 0 deletions

View File

@ -36,6 +36,10 @@ const metaChars = "&|!=~*<>()"
func (l *Auth) Authenticate(m models.AuthModel) (*models.User, error) {
p := m.Principal
if len(strings.TrimSpace(p)) == 0 {
log.Debugf("LDAP authentication failed for empty user id.")
return nil, nil
}
for _, c := range metaChars {
if strings.ContainsRune(p, c) {
return nil, fmt.Errorf("the principal contains meta char: %q", c)

View File

@ -131,4 +131,13 @@ func TestAuthenticate(t *testing.T) {
if user != nil {
t.Errorf("Nil user expected for wrong password")
}
person.Principal = ""
person.Password = ""
user, err = auth.Authenticate(person)
if err != nil {
t.Errorf("unexpected ldap error: %v", err)
}
if user != nil {
t.Errorf("Nil user for empty credentials")
}
}