@@ -147,7 +147,7 @@ func bindUser(l *ldap.Conn, userDN, passwd string) error {
147147}
148148
149149func checkAdmin (l * ldap.Conn , ls * Source , userDN string ) bool {
150- if len ( ls .AdminFilter ) == 0 {
150+ if ls .AdminFilter == "" {
151151 return false
152152 }
153153 log .Trace ("Checking admin with filter %s and base %s" , ls .AdminFilter , userDN )
@@ -169,7 +169,7 @@ func checkAdmin(l *ldap.Conn, ls *Source, userDN string) bool {
169169}
170170
171171func checkRestricted (l * ldap.Conn , ls * Source , userDN string ) bool {
172- if len ( ls .RestrictedFilter ) == 0 {
172+ if ls .RestrictedFilter == "" {
173173 return false
174174 }
175175 if ls .RestrictedFilter == "*" {
@@ -250,8 +250,17 @@ func (source *Source) getUserAttributeListedInGroup(entry *ldap.Entry) string {
250250
251251// SearchEntry : search an LDAP source if an entry (name, passwd) is valid and in the specific filter
252252func (source * Source ) SearchEntry (name , passwd string , directBind bool ) * SearchResult {
253+ if MockedSearchEntry != nil {
254+ return MockedSearchEntry (source , name , passwd , directBind )
255+ }
256+ return realSearchEntry (source , name , passwd , directBind )
257+ }
258+
259+ var MockedSearchEntry func (source * Source , name , passwd string , directBind bool ) * SearchResult
260+
261+ func realSearchEntry (source * Source , name , passwd string , directBind bool ) * SearchResult {
253262 // See https://tools.ietf.org/search/rfc4513#section-5.1.2
254- if len ( passwd ) == 0 {
263+ if passwd == "" {
255264 log .Debug ("Auth. failed for %s, password cannot be empty" , name )
256265 return nil
257266 }
@@ -323,17 +332,17 @@ func (source *Source) SearchEntry(name, passwd string, directBind bool) *SearchR
323332 return nil
324333 }
325334
326- isAttributeSSHPublicKeySet := len ( strings .TrimSpace (source .AttributeSSHPublicKey )) > 0
327- isAtributeAvatarSet := len ( strings .TrimSpace (source .AttributeAvatar )) > 0
335+ isAttributeSSHPublicKeySet := strings .TrimSpace (source .AttributeSSHPublicKey ) != ""
336+ isAttributeAvatarSet := strings .TrimSpace (source .AttributeAvatar ) != ""
328337
329338 attribs := []string {source .AttributeUsername , source .AttributeName , source .AttributeSurname , source .AttributeMail }
330- if len ( strings .TrimSpace (source .UserUID )) > 0 {
339+ if strings .TrimSpace (source .UserUID ) != "" {
331340 attribs = append (attribs , source .UserUID )
332341 }
333342 if isAttributeSSHPublicKeySet {
334343 attribs = append (attribs , source .AttributeSSHPublicKey )
335344 }
336- if isAtributeAvatarSet {
345+ if isAttributeAvatarSet {
337346 attribs = append (attribs , source .AttributeAvatar )
338347 }
339348
@@ -375,7 +384,7 @@ func (source *Source) SearchEntry(name, passwd string, directBind bool) *SearchR
375384 isRestricted = checkRestricted (l , source , userDN )
376385 }
377386
378- if isAtributeAvatarSet {
387+ if isAttributeAvatarSet {
379388 Avatar = sr .Entries [0 ].GetRawAttributeValue (source .AttributeAvatar )
380389 }
381390
@@ -440,14 +449,14 @@ func (source *Source) SearchEntries() ([]*SearchResult, error) {
440449
441450 userFilter := fmt .Sprintf (source .Filter , "*" )
442451
443- isAttributeSSHPublicKeySet := len ( strings .TrimSpace (source .AttributeSSHPublicKey )) > 0
444- isAtributeAvatarSet := len ( strings .TrimSpace (source .AttributeAvatar )) > 0
452+ isAttributeSSHPublicKeySet := strings .TrimSpace (source .AttributeSSHPublicKey ) != ""
453+ isAttributeAvatarSet := strings .TrimSpace (source .AttributeAvatar ) != ""
445454
446455 attribs := []string {source .AttributeUsername , source .AttributeName , source .AttributeSurname , source .AttributeMail , source .UserUID }
447456 if isAttributeSSHPublicKeySet {
448457 attribs = append (attribs , source .AttributeSSHPublicKey )
449458 }
450- if isAtributeAvatarSet {
459+ if isAttributeAvatarSet {
451460 attribs = append (attribs , source .AttributeAvatar )
452461 }
453462
@@ -503,7 +512,7 @@ func (source *Source) SearchEntries() ([]*SearchResult, error) {
503512 user .SSHPublicKey = v .GetAttributeValues (source .AttributeSSHPublicKey )
504513 }
505514
506- if isAtributeAvatarSet {
515+ if isAttributeAvatarSet {
507516 user .Avatar = v .GetRawAttributeValue (source .AttributeAvatar )
508517 }
509518
0 commit comments