ldap-server-mock provides a streamlined, in-memory mock LDAP server designed for testing and development purposes. It is built upon the `ldapjs` library and simplifies the process of simulating LDAP authentication without the overhead of a full-fledged LDAP instance. The package's current stable version is 6.0.1, released in November 2022, with a release cadence that addresses breaking changes and feature enhancements (e.g., v6.0.0 and v6.0.1 in November 2022, v5.0.0 in February 2022). It specifically focuses on basic user search and retrieval for authentication, not full SASL authentication or complex LDAP operations. Key differentiators include its ease of setup via API or command-line using simple JSON configuration files for users and server settings, making it an ideal choice for unit and integration testing where minimal LDAP functionality is required.
npm install ldap-server-mockVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically start and stop an `LdapServerMock` instance, configure its users and server settings, and optionally enable TLS with dummy certificates. It defines two mock users and sets up a server on port 3004, then starts and stops it after a short delay.
Ensure all command-line options containing file paths are correctly quoted, like `npx ldap-server-mock --conf="/path/to/conf.json" --database="/path/to/users.json"`.
Update your `users.json` or `LdapUser[]` array to move all non-DN attributes into an `attributes` object. For example, `{ dn: 'cn=user', cn: 'value' }` becomes `{ dn: 'cn=user', attributes: { cn: 'value' } }`.Review your `searchFilter` configurations and ensure that the attributes of your mock users in the database (`users.json` or `LdapUser[]`) accurately reflect all criteria specified in your search queries.
Upgrade your Node.js installation to version 16.3.0 or higher, and ensure NPM is at version 7.15.1 or higher.
When using relative paths with `--conf` or `--database`, ensure they are correct with respect to the directory from which you are running the `npx ldap-server-mock` command.
Use quoted values for file paths: `npx ldap-server-mock --conf="./conf.json" --database="./users.json"`.
Verify that your mock user objects conform to the v6.0.0 structure (all non-DN attributes under an `attributes` object) and that their attributes satisfy all conditions in your LDAP search filter.
Ensure every user object in your `users.json` file or `LdapUser[]` array has a `dn` property with a valid LDAP distinguished name string.