GithubHelp home page GithubHelp logo

veo-labs / ldap-server-mock Goto Github PK

View Code? Open in Web Editor NEW
67.0 67.0 24.0 161 KB

Really simple basic mock for LDAP server

License: GNU Affero General Public License v3.0

JavaScript 34.26% TypeScript 65.74%

ldap-server-mock's People

Contributors

claudiochimera avatar maxime-beguin avatar stevenhair avatar tommymorgan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ldap-server-mock's Issues

Start programatically

Hi, is there a way to start the mock server from the code, to use in testing suites?

File path is relative to the executable directory instead of the directory node executes from...

Windows 10.
NPM 6.5.0

Directory Structure:
C:\Code\LDAPMock\node_modules
C:\Code\LDAPMock\users.json
C:\Code\LDAPMock\config.json

Open Terminal
cd to C:\Code\LDAPMock

When I run with the full path it works fine:
node node_modules/ldap-server-mock/server.js --conf="C:\Code\LDAPMock\config.json" --database="C:\Code\LDAPMock\users.json"

When I run with relative path(current directory is LDAPMock), it doesn't work:
node node_modules/ldap-server-mock/server.js --conf=".\config.json" --database=".\users.json"

If I put my two json files in the node_modules/ldap-server-mock/ directory instead, the relative pathing works fine. It seems like weird usability that it would be relative to the executable instead of the directory your terminal is in though. So the command below will work, but is not ideal.

node node_modules/ldap-server-mock/server.js --conf=".\..\..\config.json" --database=".\..\..\users.json"

throw new Error(`Invalid arguments: ${error.message}`);

Hey i get this error when i will start ldap-server ...

$ node node_modules/ldap-server-mock/server.js --conf=/tmp/ldap-server-mock-conf.json --database=/tmp/users.json

/tmp/ldap/node_modules/ldap-server-mock/server.js:26
throw new Error(Invalid arguments: ${error.message});
^

Error: Invalid arguments: /tmp/users.json: Unexpected token [ in JSON at position 119
at Object. (/tmp/ldap/node_modules/ldap-server-mock/server.js:26:9)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:387:7)
at startup (bootstrap_node.js:153:9)
at bootstrap_node.js:500:3

Do you have any idea why i get this error ?

Thank you

installation instructions

would be nice to know that you need:

  • python installed (2.x as 3 isnt supported by npm)

If you haven't got python installed along with all the node-gyp dependencies, simply open Powershell > or Git Bash with administrator privileges and execute:

npm install --global --production windows-build-tools
and then to install the package:

npm install --global node-gyp
once installed, you will have all the node-gyp dependencies downloaded, but you still need the environment variable. Validate Python is indeed found in the correct folder:
C:\Users\ben.windows-build-tools\python27\python.exe
Note - it uses python 2.7 not 3.x as it is not supported

  • windows needs some .net 2.0 framework installation which i cannot install as i have some never version present

could resolve this issue just installing with -g flag ?!

cheers

Manipulate LDAP search filter

Here is what I am trying to do
I send an LDAP search with filter uid=1234,
The backend JSON file only has one entry uid=abcd

The server should just take the uid=1234 (or any thing that I pass in that filter value, should not matter, it can change with every query) - the response that will be returned is the one for uid=abcd that is in the JSON file

Throws an error moments after listening on port 3004

I just followed the documentation and tried to implement it. It throws the following error moments after listening on port 3004:

โžœ  ldap-tester node node_modules/ldap-server-mock/server.js --conf=/tmp/ldap-server-mock-conf.json --database=/tmp/users.json

LDAP server listening on port 3004

events.js:183
      throw er; // Unhandled 'error' event
      ^
VError: Parser error for 127.0.0.1:64280: Expected 0x2: got 0x54
    at Parser.<anonymous> (/Users/raj/Desktop/ldap-tester/node_modules/ldapjs/lib/server.js:442:26)
    at emitTwo (events.js:126:13)
    at Parser.emit (events.js:214:7)
    at Parser.write (/Users/raj/Desktop/ldap-tester/node_modules/ldapjs/lib/messages/parser.js:107:10)
    at Socket.<anonymous> (/Users/raj/Desktop/ldap-tester/node_modules/ldapjs/lib/server.js:460:16)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)

Can you possibly help me with this?

Mock returns data that it should not when searching by dn

I start the mock with the command line:

npx ldap-server-mock --conf=ldap-server-config.json --database=ldap-server-data.json

ldap-server-config.json:

{
    "port": 389,
    "searchBase": "dc=test"
}

ldap-server-data.json (just added another user):

[
    {
        "dn": "cn=user,dc=test",
        "attributes": {
            "objectClass": "person",
            "cn": "user-login",
            "attribute1": "value1",
            "attribute2": "value2"
        }
    },
    {
        "dn": "cn=user2,dc=test",
        "attributes": {
            "objectClass": "person",
            "cn": "user2-login",
            "attribute1": "value1",
            "attribute2": "value2"
        }
    }
]

When requesting the first user by its dn, I am getting both users instead:

ldapsearch -x -H ldap://127.0.0.1:389 -b "cn=user,dc=test"

# user, test
dn: cn=user,dc=test
objectClass: person
cn: user-login
attribute1: value1
attribute2: value2

# user2, test
dn: cn=user2,dc=test
objectClass: person
cn: user2-login
attribute1: value1
attribute2: value2

I can get the entry I want by using a filter instead, however the mock should not return entries that are not in the scope.
Am I missing something?

Need help with some examples of searching a user

This is really great, I am trying to set this up for my internal testing.
I am using an LDAP Admin tool, When trying to Fetch the DNs, it says "LDAP error! No such object: No tree found for: ."
Able to do test connection successfully but on fetching the DNs it gives me an error.
Using this as username as per the users.json "cn=user,dc=test".

Please let me know if I am missing something.
Thanks,
Akram

Please add basic authentication support to LDAP mock server

Hi,

Nice little project!! I've set up my LDAP mock server without issue and it works with no problems using ldapsearch, however, I've realised now that when I use my Java client to test against my mock ldap. It is always trying to authenticate and consequently fails.

I can't change my app not to authenticate and I suspect no one is really using LDAP without authentication, so I was wondering if you could add a simple enhancement to support this. Looking at ldapjs, it wouldn't be too hard I think?:

Maybe in the start method something like this:

this.app.bind('cn=root', (req, res, next) => {
  if (req.dn.toString() !== 'cn=root' || req.credentials !== 'secret')
    return next(new ldap.InvalidCredentialsError());

  res.end();
  return next();
});

It seems a shame to have to fork and duplicate all the code, just to add this functionality.

Many Thanks,
Jonathan

file json

hi, this is awesome. but i don't understand how to setting of 2 json file. can you explain more example for me?

thanks

I want to authenticate user/pass for client

I get it working but i need to authenticate user/Password of the client not the Query user. like the user gives his own username/password and I want to Authenticate it from the LDAP how would i do this?
how can i create a username and password in users file and than match it

Add example command using common ldap client

I think it would be very useful to new users to have an example search using a common tool like ldapsearch.

Something like

$ ldapsearch -x -h localhost -p 3004 -b "dc=test" "(&(objectclass=person)(cn=user-login))"

I think adding this to the README would help clear up confusion for new users.

Error: Invalid arguments: /data/ldap-server-mock-conf.json: Unexpected token / in JSON at position 18

Hey i get this error when i will start ldap-server ...

node node_modules/ldap-server-mock/server.js --conf=/data/ldap-server-mock-conf.json --database=/data/users.json
/data/node_modules/ldap-server-mock/server.js:23
  throw new Error(`Invalid arguments: ${error.message}`);
  ^

Error: Invalid arguments: /data/ldap-server-mock-conf.json: Unexpected token / in JSON at position 18
    at Object.<anonymous> (/data/node_modules/ldap-server-mock/server.js:23:9)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
    at startup (internal/bootstrap/node.js:201:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)

you have any idea why?

greetings
sam

Can we search by multiple criteria

We are using the mock server for a few months now and everything is great. The system we test used to use the attribute "sAMAccountName" to search for users so our config looked like that:
{ "port": 3004, "userLoginAttribute": "sAMAccountName", "searchBase": "DC=hedgeservtest,DC=com", "searchFilter": "(sAMAccountName={{user}})" }
The problem is that due to recent changes we now have to search by email in some cases. So we changed the config
{ "port": 3004, "userLoginAttribute": "mail", "searchBase": "DC=hedgeservtest,DC=com", "searchFilter": "(mail={{user}})" }
But I am not sure how to combine both of those so we can search by both. I tried to change the filter like that "|("(mail={{user}})"(mail={{user}}))" but I've no idea what to do with "userLoginAttribute".
Is this use case even possible with this server?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.