mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-02 15:10:43 +02:00
fix: addressed the review comment
This commit is contained in:
1 parent
1c7b0c8498
commit
ed87ef8b69
2 files changed
+3
-23
No files matched your search
@@ -249,8 +249,8 @@ func (source *Source) getUserAttributeListedInGroup(entry *ldap.Entry) string {
|
|||||||
return entry.GetAttributeValue(source.UserUID)
|
return entry.GetAttributeValue(source.UserUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func userAttributeFilter(userFilter string, userDNFoundBySearch bool) string {
|
func userAttributeFilter(userFilter string, directBind bool, userBase string) string {
|
||||||
if userDNFoundBySearch {
|
if !directBind || userBase != "" {
|
||||||
return "(objectClass=*)"
|
return "(objectClass=*)"
|
||||||
}
|
}
|
||||||
return userFilter
|
return userFilter
|
||||||
@@ -281,7 +281,6 @@ func realSearchEntry(source *Source, name, passwd string, directBind bool) *Sear
|
|||||||
defer l.Close()
|
defer l.Close()
|
||||||
|
|
||||||
var userDN string
|
var userDN string
|
||||||
userDNFoundBySearch := false
|
|
||||||
if directBind {
|
if directBind {
|
||||||
log.Trace("LDAP will bind directly via UserDN template: %s", source.UserDN)
|
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 {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
userDNFoundBySearch = true
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Trace("LDAP will use BindDN.")
|
log.Trace("LDAP will use BindDN.")
|
||||||
@@ -327,7 +325,6 @@ func realSearchEntry(source *Source, name, passwd string, directBind bool) *Sear
|
|||||||
if !found {
|
if !found {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
userDNFoundBySearch = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !source.AttributesInBind {
|
if !source.AttributesInBind {
|
||||||
@@ -342,7 +339,7 @@ func realSearchEntry(source *Source, name, passwd string, directBind bool) *Sear
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
attributeFilter := userAttributeFilter(userFilter, userDNFoundBySearch)
|
attributeFilter := userAttributeFilter(userFilter, directBind, source.UserBase)
|
||||||
|
|
||||||
isAttributeSSHPublicKeySet := strings.TrimSpace(source.AttributeSSHPublicKey) != ""
|
isAttributeSSHPublicKeySet := strings.TrimSpace(source.AttributeSSHPublicKey) != ""
|
||||||
isAttributeAvatarSet := strings.TrimSpace(source.AttributeAvatar) != ""
|
isAttributeAvatarSet := strings.TrimSpace(source.AttributeAvatar) != ""
|
||||||
|
|||||||
@@ -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))
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user