auth0 / passport-windowsauth

Windows Authentication strategy for Passport.js
MIT License
178 stars 54 forks source link

Uncaught exception in version 0.2.0 #23

Open aaronbloom opened 9 years ago

aaronbloom commented 9 years ago

Hi,

It seems that when unable to communicate with an Active Directory server I get the following uncaught exception.

Cannot call method 'on' of undefined

column=11,
file=/mnt/Gateway/api/node_modules/passport-windowsauth/lib/LdapLookup.js, function=null, line=38, method=null, native=false, column=14,
file=/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/lib/client/pool.js, function=onAcquire, line=203, method=null, native=false, column=25,
file=/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/node_modules/pooling/node_modules/once/once.js, function=f, line=16, method=null, native=false, column=25,
file=/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/node_modules/pooling/lib/pool.js, function=onCreatedClient, line=260, method=null, native=false, column=25,
file=/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/node_modules/pooling/lib/pool.js, function=createCallback, line=426, method=null, native=false, column=16,
file=/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/lib/client/pool.js, function=, line=53, method=null, native=false, column=17, file=events.js, function=Client.EventEmitter.emit, line=95, method=EventEmitter.emit, native=false, column=12,
file=/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/lib/client/client.js, function=Socket.onError, line=176, method=onError, native=false, column=17, file=events.js, function=Socket.EventEmitter.emit, line=95, method=EventEmitter.emit, native=false, column=16,
file=net.js, function=null, line=830, method=null, native=false],

TypeError: Cannot call method 'on' of undefined,
     at /mnt/Gateway/api/node_modules/passport-windowsauth/lib/LdapLookup.js:38:11,
     at onAcquire (/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/lib/client/pool.js:203:14),
     at f (/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/node_modules/pooling/node_modules/once/once.js:16:25),
     at onCreatedClient (/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/node_modules/pooling/lib/pool.js:260:25),
     at createCallback (/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/node_modules/pooling/lib/pool.js:426:25),
     at Client.<anonymous> (/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/lib/client/pool.js:53:16),
     at Client.EventEmitter.emit (events.js:95:17),
     at Socket.onError (/mnt/Gateway/api/node_modules/passport-windowsauth/node_modules/ldapjs/lib/client/client.js:176:12),
     at Socket.EventEmitter.emit (events.js:95:17),
     at net.js:830:16

Many thanks, Aaron

Update:

Only seems to be thrown in the circumstances where the active directory server can be found on application start-up, but then during the applications runtime the server becomes unreachable, upon which a user login triggers the uncaught exception.

aaronbloom commented 9 years ago

Upon a further look at the the source of LdapLookup.js in version 0.4.1 it seems that the callback function on line 44 is not handling the error argument when the function is run.

An appropriate patch? snippet line 44 to 56

self._client.search(self._options.base, opts, function(err, res){
      if(err) return callback(err);        // handle the error - inserted into line 45
      var entries = [];
      res.on('searchEntry', function(entry) {
        entries.push(entry);
      });
      res.on('error', function(err) {
        callback(err);
      });
      res.on('end', function() {
        if(entries.length === 0) return callback(null, null);
        callback(null, entries[0].object);
      });
    });