shaozi / ldap-authentication

🔐🔐🔐 A simple Nodejs Async LDAP authentication library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing promise rejections.

psmitty7373 opened this issue · comments

Need additional promise rejections for:

Error: connect EHOSTUNREACH
Error: getaddrinfo ENOTFOUND

In the event the ldap is outright down or unresolvable.

By default, connection timeout is 5 seconds. You can change that with connectTimeout option. When server is not reachable or not found, bind will be rejected.

Please elaborate more what else do you expect?

It doesn't seem to be catchable, so when it timeouts it's unhandled, in my cases it causes the server that uses it to crash.

As @Zerowalker said, the errors are unhandled, and will simply crash the instance.

hmm... When a server is unreachable, or it is reachable but does not have ldap enabled, the library call will be rejected. You need a try and catch to catch that error. See the last test case in test:

try {
  await authenticate(options)
} catch (error) {
  e = error
}

The library will not know ahead how to handle such errors. The best it can do is to reject the error. Which means it will crash the instance. You will need to provide logic to catch the crash and handle it (retry after a few seconds, for example, though if a server is not reachable, it may not help) in you own code.

This is probably fixed by merge #19

It isn't fixed in the merge, tried it, but adding the next code found at ldapjs/node-ldapjs#486 (comment) fixes this issue by inserting the events in index.js in the _ldapBind function. Just add the extra event listeners for 'timeout', 'connectTimeout' and 'error' as ldapjs emits them if one of these events happens. Worked for me.

client.on('timeout', (err) => {
      reject(err);
 });

client.on('connectTimeout', (err) => {
      reject(err);
});

client.on('error', (err) => {
      reject(err);
});

2021-03-17 (2)
2021-03-17 (3)

Looks reasonably right! Do you want to create a pull request?

Sure, it's done. Awaiting merge.

Thanks! Merged!