ldapjs / node-ldapjs

LDAP Client and Server API for node.js
http://ldapjs.org
MIT License
1.61k stars 448 forks source link

Client event routing issue #945

Open Yug-Damon opened 1 year ago

Yug-Damon commented 1 year ago

EDIT: My environment osixia/openldap + ldapjs:3.0.5 the error is happening on a LDAP SEARCH query


File ./lib/client/client.js Line 1260

let event = msg.constructor.name
// Generate the event name for the event emitter, i.e. "searchEntry"
// and "searchReference".
event = (event[0].toLowerCase() + event.slice(1)).replaceAll('Result', '')
return sendResult(event, msg)

For some reason event[0] is undefined and therefore my app crashes on the toLowerCase call

I suggest to replace the if block with:

if(msg instanceof SearchEntry) {
      return sendResult('searchEntry', msg)
} else if(msg instanceof SearchReference) {
      return sendResult('searchReference', msg)
} else {
    ...
}

I think it's a terrible idea to base decision on constructor.name value. I've struggled 2.5 days to figure it out.

jsumners commented 1 year ago

Please provide a minimal reproducible example. Doing so will help us diagnose your issue. It should be the bare minimum code needed to trigger the issue, and easily runnable without any changes or extra code.

You may use a GitHub repository to host the code if it is too much to fit in a code block (or two).

melissakintz commented 1 year ago

Hello, same error for me and here

Yug-Damon commented 1 year ago

@melissakintz yes that's actually a post of mine, I'm gonna mark it as resolved and link the post to this ticket

DukeVenator commented 11 months ago

We had the same problem and applied the patch mentioned above using a nifty NPM module called patch-package to persist it across our development team.

if(msg instanceof SearchEntry) { return sendResult('searchEntry', msg) } else if(msg instanceof SearchReference) { return sendResult('searchReference', msg)

This package unmodified works on Node18 on Windows but when we deploy to our node image running on ocp 3.11 on a container the issue the OP occurs.

By applying the fix our NextAuth works flawlessly. I suggest perhaps taking a closer look at this issue.