Skip to content

Commit 118edce

Browse files
committed
Added additional tests for user search results.
nginxinc/nginx-ldap-auth@86687e2
1 parent ed8be0d commit 118edce

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

root/app/nginx-ldap-auth-daemon.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,27 @@ def do_GET(self):
253253
searchfilter, ['objectclass'], 1)
254254

255255
ctx['action'] = 'verifying search query results'
256-
if len(results) < 1:
256+
257+
nres = len(results)
258+
259+
if nres < 1:
257260
self.auth_failed(ctx, 'no objects found')
258261
return
259262

260-
ctx['action'] = 'binding as an existing user'
261-
ldap_dn = results[0][0]
262-
ctx['action'] += ' "%s"' % ldap_dn
263+
if nres > 1:
264+
self.log_message("note: filter match multiple objects: %d, using first" % nres)
265+
266+
user_entry = results[0]
267+
ldap_dn = user_entry[0]
268+
269+
if ldap_dn == None:
270+
self.auth_failed(ctx, 'matched object has no dn')
271+
return
272+
273+
self.log_message('attempting to bind using dn "%s"' % (ldap_dn))
274+
275+
ctx['action'] = 'binding as an existing user "%s"' % ldap_dn
276+
263277
ldap_obj.bind_s(ldap_dn, ctx['pass'], ldap.AUTH_SIMPLE)
264278

265279
self.log_message('Auth OK for user "%s"' % (ctx['user']))

0 commit comments

Comments
 (0)