jsumners / node-activedirectory

ActiveDirectory is an Node.js ldapjs client for authN (authentication) and authZ (authorization) for Microsoft Active Directory with range retrieval support for large Active Directory installations. Originally forked from gheeres/node-activedirectory.
MIT License
52 stars 43 forks source link

`getUsersForGroup` returns just one user when there is a group with nested groups #84

Closed SelfDevTV closed 3 years ago

SelfDevTV commented 4 years ago

Hiho,

Today I stumbled over a bug:

I have a group with 2 sub groups. Both have combined ~a bit over 1000 Users~ 640 Users:

image

The result I get ist just one random user from one of those sub groups. It's always this user.

When I turn on logging I can see this:

image

The last line where it says "1 user belong.." this is the user I receive back when I res.send those results.

If I use a group with 3000+ direct users it will work just fine.

I tried it with several groups that have subgroups. The result is always the same.

Here is the code:

app.post("/api/getGroupMembers", (req, res) => {
  const group = req.body.group;

  ad.getUsersForGroup(group, (err, users) => {
    if (err) {
      console.log("error in getUsers", err);
    }
    res.send(users);
  });
});

EDIT: it seems to work with "activedirectory" package, the one I use and it isn't working is this: "activedirectory2". Edit2: I have added this group that does not work to my test group with 5 users in it. The result is this, when I query the testgroup:

I get the 5 users in the group and again this one random user from this big group with sub groups. So 6 in total.

jsumners commented 4 years ago

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

jurjendijkstra commented 4 years ago

I am interested to know if this issue may affect me too, so I want to look into it. Are you willing to send me more logging? I mean in fact the whole log (except the first couple of lines where the authentication happens). The snippet of 3 selected lines, where names are censored, does not give any clue at all. You can send it to me in private message if you want.

SelfDevTV commented 4 years ago

Thank you very much @jurjendijkstra I will have a deeper look in a couple of days. Im on holiday right now and have no access to the company code right now.

SelfDevTV commented 4 years ago

Alrighty @jurjendijkstra

I have now enabled logging and I will send you detailed informations via pn. Thx in advance!

Spoiler: It is a huuuuge list of all the users in the group. But only the end of the log is interesting:

Scenario:

Here is the screenshot (I want to receive all members from group X):

image

The code from the route:

app.post("/api/getGroupMembers", (req, res) => {
  const group = req.body.group;

  console.log("called /api/getGroupMembers with group " + group);

  ad.getUsersForGroup(group, (err, users) => {
    if (err) {
      console.log("error in getUsers", err);
    }
    console.log("this are the results", users);
    res.send(users);
  });
});

The problem:

So at the end of the log it shows that 1 users is in group X but it should be users from group Y + group Z combined. 640 in total. But somehow it's just pulling out one random users it seems and returns this. Here is the bug somewhere, but I have no idea where to look for. Maybe you have more insights into this package and are more familiar with it.

Edit: How can I send you a pn on github? Can't find anything to send you a pn

SelfDevTV commented 4 years ago

@jurjendijkstra Any chance to solve this problem? Any ideas where I should start to look for? I'm so close to finish my webapp, just this one nasty bug ist left (which isn't in the previous version of the package) :D

jsumners commented 4 years ago

Please see the notice at the top of this module's README.

I recommend creating the smallest reproduction case possible and stepping through with the debugger to see where the problem occurs.

SelfDevTV commented 3 years ago

This has been solved. Attribute dn is required in the config. For example:

var config = {
    url: "your url",
    //....,
    attributes: {
        user: [
            // attributes you want and plus,
            "dn"
        ],
        group: [
            //attributes you want plus:
            "dn"
        ]
    }
}