veo-labs / ldap-server-mock Goto Github PK
View Code? Open in Web Editor NEWReally simple basic mock for LDAP server
License: GNU Affero General Public License v3.0
Really simple basic mock for LDAP server
License: GNU Affero General Public License v3.0
Hi, is there a way to start the mock server from the code, to use in testing suites?
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"
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
would be nice to know that you need:
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
could resolve this issue just installing with -g flag ?!
cheers
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
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?
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?
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
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
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 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
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.
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
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.