mirror of
https://github.com/goharbor/harbor.git
synced 2024-09-18 08:41:10 +02:00
parent
eb9497abd1
commit
4f66279c33
@ -36,6 +36,10 @@ const metaChars = "&|!=~*<>()"
|
|||||||
func (l *Auth) Authenticate(m models.AuthModel) (*models.User, error) {
|
func (l *Auth) Authenticate(m models.AuthModel) (*models.User, error) {
|
||||||
|
|
||||||
p := m.Principal
|
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 {
|
for _, c := range metaChars {
|
||||||
if strings.ContainsRune(p, c) {
|
if strings.ContainsRune(p, c) {
|
||||||
return nil, fmt.Errorf("the principal contains meta char: %q", c)
|
return nil, fmt.Errorf("the principal contains meta char: %q", c)
|
||||||
|
@ -131,4 +131,13 @@ func TestAuthenticate(t *testing.T) {
|
|||||||
if user != nil {
|
if user != nil {
|
||||||
t.Errorf("Nil user expected for wrong password")
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user