Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
ldap-server-mock
Advanced tools
Really simple basic mock for LDAP server based on ldaps. Use it to mock an LDAP server and authenticate a user without further verifications, it simply searches for the user in the database and returns it. It does not implement LDAP SASL authentication. This should not be used in production environment, it is just for test purpose, nothing more.
npm install ldap-server-mock
ldap-server-mock
exposes the LdapServerMock
class:
constructor(users: LdapUser[], serverConfiguration: LdapServerMockConfiguration, certificatePublicKey?: Buffer, certificatePrivateKey?: Buffer, logger?: LdapServerMockLogger)
Argument | Required | Default | Details |
---|---|---|---|
users | yes | - | The list of LDAP users as JavaScript objects (see below) |
serverConfiguration | yes | { port: 3004, searchBase: 'dc=test'} | The LDAP server mock configuration (see below) |
certificatePublicKey | no | - | The public key of the certificate to use for creating an LDAP server over TLS |
certificatePrivateKey | no | - | The private key corresponding to the public key defined by certificatePublicKey |
logger | no | console | A custom logger to use instead of console |
start(): Promise<void>
stop(): Promise<void>
{
import * as fs from 'node:fs/promises';
import { LdapServerMock } from 'ldap-server-mock';
async function main() {
const ldapUsers = [
{
dn: 'cn=user,dc=test',
attributes: {
objectClass: 'person',
cn: 'user-login',
attribute1: 'value1',
attribute2: 'value2'
}
}
];
const serverConfiguration = {
port: 3004,
searchBase: 'dc=test'
};
const customLogger = {
info: (...args) => {
console.info(...args);
}
}
const certificatePublicKey = await fs.readFile('/path/to/certificate/public/key.pem');
const certificatePrivateKey = await fs.readFile('/path/to/certificate/private/key.pem');
const ldapServer = new LdapServerMock(ldapUsers, serverConfiguration, certificatePublicKey, certificatePrivateKey, customLogger);
await ldapServer.start();
await ldapServer.stop();
}
main();
LDAP server mock can be started with command:
npx ldap-server-mock --conf=/tmp/ldap-server-mock-conf.json --database=/tmp/users.json
With:
Nb: If process is launched as a sub process it will send a message to its parent process when started:
{
status: 'started';
}
/tmp/ldap-server-mock-conf.json
The server's configuration file must be a simple JSON file:
{
"certPath": "/path/to/certificate/public/key.pem",
"certKeyPath": "/path/to/certificate/private/key.pem",
"port": 3004,
"searchBase": "dc=test"
}
/tmp/users.json
The database's configuration file must be a simple JSON file containing an array of users:
[
{
dn: 'cn=user,dc=test',
attributes: {
objectClass: 'person',
cn: 'user-login',
attribute1: 'value1',
attribute2: 'value2'
}
}
];
npx ldap-server-mock --conf=/tmp/ldap-server-mock-conf.json --database=/tmp/users.json
Property | Type | Required | Default | Details |
---|---|---|---|---|
certPath | string | no | - | The path of the certificate's public key to use for creating an LDAP server over TLS |
certKeyPath | string | no | - | The path of the certificate's private key corresponding to the public key defined by certPath |
port | number | no | 3004 | The port the LDAP server will listen to |
searchBase | string | no | "dc=test" | The search base to use when searching for the user who is trying to connect |
{
certPath: '/path/to/certificate/public/key.pem',
certKeyPath: '/path/to/certificate/private/key.pem',
port: 3004,
searchBase: 'dc=test'
}
An LDAP user must have a valid Dinstinguished Name and any number of other attributes:
Property | Type | Required | Default | Details |
---|---|---|---|---|
dn | string | yes | - | Dinstinguish Name |
attributes | Object | yes | - | Any key / value pairs of attributes |
{
dn: 'cn=user,dc=test",
attributes: {
objectClass: 'person',
cn: 'user-login',
attribute1: 'value1',
attribute2: 'value2'
}
Here is an example using the ldapsearch
client from OpenLDAP with the configuration used in examples:
ldapsearch -x -H ldaps://127.0.0.1:3004 -b "dc=test" "(&(objectclass=person)(cn=user-login))" attribute1 attribute2
With:
Nb: Don't forget to change protocol to ldap
if you haven't configured a certificate.
This mock supports running an LDAP server over TLS which is the non-standard LDAPS. However STARTTLS
(the standard way to run an LDAP server over TLS) is not supported as the underlying ldapjs module has not support for it on the server side. See issue STARTTLS support for the Server API for more information.
Maintainer: Veo-Labs
FAQs
Simple mock for LDAP server
We found that ldap-server-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.