I'm working in the Ubuntu 20.04 and openLDAP 2.4.49 environment.
How can I retrieve detailed error information from ldapjs? (ldapjs version is 3.0.5)
For example, if I change the password immediately after changing it once, and then execute the following command:
ldappasswd -H ldapi:/// -x -D <myDN> -W -S
The result displays detailed information like:
Result: Constraint violation (19)
Additional info: Password is too young to change
However, when I perform the following code using ldapjs, the result only shows the ConstraintViolationError value without detailed information.
'use strict';
const ldap = require('ldapjs');
const client = ldap.createClient({
socketPath: '/run/ldapi',
});
function changePassword() {
const userDN = <user_DN>;
const userPassword = <userPassword>;
return new Promise((resolve, reject) => {
client.bind(userDN, userPassword, (err) => {
if (err) {
return reject(err);
} else {
const change = new ldap.Change({
operation: 'replace',
modification: {
type: 'userPassword',
values: ['NewPassword'],
}
});
client.modify(userDN, change, err => {
if (err) {
return reject(err);
}
return resolve();
});
}
})
});
}
(async () => {
try {
await changePassword();
} catch (e) {
console.log(`${JSON.stringify(e)}`);
}
client.unbind();
})();
What is the method to obtain detailed information, such as "Password is too young to change," when using ldapjs?
There is an open issue on the repository complaining that, starting from version 3, the errors are not detailed as the previous major version.
At the moment, I have to stick to version 2 in order to be able to get detailed error messages.