Here is an online LDPA test server, http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/
So I did some simple script to test it but I am always getting unwanted response.
Here is my code:
const ldap = require('ldapjs');
const assert = require('assert');
// LDAP Connection Settings
const server = "ldap.forumsys.com";
const uid = "tesla"
const password = "password"; // User password
// Create client and bind to AD
const client = ldap.createClient({
url: `ldap://${server}`
});
// Search AD for user
const searchOptions = {
filter: '(uid=${uid})'
};
// client.bind(`uid=tesla,dc=example,dc=com`,password,err => {
// assert.ifError(err);
// });
client.search(`cn=read-only-admin,dc=example,dc=com`,searchOptions,(err,res) => {
assert.ifError(err);
res.on('searchEntry', entry => {
console.log(entry.object.name);
});
res.on('searchReference', referral => {
console.log('referral: ' + referral.uris.join());
});
res.on('error', err => {
console.error('error: ' + err.message);
});
res.on('end', result => {
console.log(result);
});
});
// Wrap up
client.unbind( err => {
assert.ifError(err);
});
And I am getting this back by running the app.js
SearchResponse {
messageID: 1,
protocolOp: 101,
controls: [],
log:
Logger {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
_isSimpleChild: true,
_level: 30,
streams: [ [Object] ],
serializers: { req: [Function], res: [Function], err: [Function] },
src: false,
fields:
{ name: 'ldapjs',
component: 'client',
hostname: 'will-ThinkPad-T440p',
pid: 17485,
clazz: 'Client' } },
status: 0,
matchedDN: '',
errorMessage: '',
referrals: [],
connection:
Socket {
connecting: false,
_hadError: false,
_handle:
TCP {
reading: true,
owner: [Circular],
onread: [Function: onread],
onconnection: null,
writeQueueSize: 0 },
_parent: null,
_host: 'ldap.forumsys.com',
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: [Object],
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: false,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events:
{ finish: [Function: onSocketFinish],
_socketEnd: [Function: onSocketEnd],
data: [Function: onData],
close: [Object],
end: [Function: onEnd],
error: [Function: onSocketError],
timeout: [Function: onTimeout] },
_eventsCount: 7,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
finalCalled: false,
needDrain: false,
ending: false,
ended: false,
finished: false,
destroyed: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function: bound onwrite],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: true,
allowHalfOpen: false,
_bytesDispatched: 79,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: null,
_server: null,
[Symbol(asyncId)]: 8,
[Symbol(bytesRead)]: 0 },
attributes: [],
notAttributes: [],
sentEntries: 0 }
which does not contain any information around "Tesla"......
The above section is incorrect. Should be
I see Gustav as already given the correct answer. But adding to that the reason is when using
'the variable replacement does not happen as you have expected. to build the string like this you need to use `Anyway since you have written an LDAP test server, there are already written test servers to achieve that, for example, you can use
https://hub.docker.com/r/upekshejay/simple-ldap-test-server