0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-06-19 13:23:50 +02:00

fix: addressed the review comment

This commit is contained in:
puni9869 2026-06-09 10:05:18 +05:30
parent 1c7b0c8498
commit ed87ef8b69
2 changed files with 3 additions and 23 deletions

View File

@ -249,8 +249,8 @@ func (source *Source) getUserAttributeListedInGroup(entry *ldap.Entry) string {
return entry.GetAttributeValue(source.UserUID)
}
func userAttributeFilter(userFilter string, userDNFoundBySearch bool) string {
if userDNFoundBySearch {
func userAttributeFilter(userFilter string, directBind bool, userBase string) string {
if !directBind || userBase != "" {
return "(objectClass=*)"
}
return userFilter
@ -281,7 +281,6 @@ func realSearchEntry(source *Source, name, passwd string, directBind bool) *Sear
defer l.Close()
var userDN string
userDNFoundBySearch := false
if directBind {
log.Trace("LDAP will bind directly via UserDN template: %s", source.UserDN)
@ -305,7 +304,6 @@ func realSearchEntry(source *Source, name, passwd string, directBind bool) *Sear
if !ok {
return nil
}
userDNFoundBySearch = true
}
} else {
log.Trace("LDAP will use BindDN.")
@ -327,7 +325,6 @@ func realSearchEntry(source *Source, name, passwd string, directBind bool) *Sear
if !found {
return nil
}
userDNFoundBySearch = true
}
if !source.AttributesInBind {
@ -342,7 +339,7 @@ func realSearchEntry(source *Source, name, passwd string, directBind bool) *Sear
if !ok {
return nil
}
attributeFilter := userAttributeFilter(userFilter, userDNFoundBySearch)
attributeFilter := userAttributeFilter(userFilter, directBind, source.UserBase)
isAttributeSSHPublicKeySet := strings.TrimSpace(source.AttributeSSHPublicKey) != ""
isAttributeAvatarSet := strings.TrimSpace(source.AttributeAvatar) != ""

View File

@ -1,17 +0,0 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package ldap
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestUserAttributeFilter(t *testing.T) {
const userFilter = "(&(objectClass=posixAccount)(uid=user1))"
assert.Equal(t, "(objectClass=*)", userAttributeFilter(userFilter, true))
assert.Equal(t, userFilter, userAttributeFilter(userFilter, false))
}