veo-labs / ldap-server-mock

Really simple basic mock for LDAP server
GNU Affero General Public License v3.0
66 stars 26 forks source link

file json #1

Closed irulvam closed 5 years ago

irulvam commented 6 years ago

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

thanks

maxime-beguin commented 6 years ago

Hi @irulvam.

This project aims to replace an LDAP server for authentication purpose when executing tests. Actually it can't be used for more complex search requests.

Here is a complete functional example to configure the LDAP server mock and interrogate it to authenticate a user.

First create a file containing the LDAP server mock configuration:

server-conf.json:

{
  "port": 3004,
  "userLoginAttribute": "cn",
  "searchBase": "dc=test",
  "searchFilter": "(&(objectclass=person)(cn={{username}}))"
}

With:

Then create a file containing the users you want to have inside your LDAP server:

users.json:

[
  {
    "dn": "cn=user1,dc=test",
    "cn": "user1-login",
    "attribute1": "value1",
    "attribute2": "value2"
  },
  {
    "dn": "cn=user2,dc=test",
    "cn": "user2-login",
    "attribute1": "value3",
    "attribute2": "value4"
  }
]

With for each user:

You can now launch your LDAP server using:

node node_modules/ldap-server-mock/server.js --conf="/path/to/the/server-conf.json" --database="path/to/the/users.json"

Now that your server is running on port 3004 and listens to the search base "dc=test" you can authenticate your user with your client. The following example, with the ldapsearch command, authenticates the user with login user1-login:

ldapsearch -x -H ldap://127.0.0.1:3004 -b dc=test '(&(objectclass=person)(cn=user1-login))'

dn: cn=user1, dc=test cn: user1-login attribute1: value1 attribute2: value