Files
wekan/tests/ldapErrorLogging.test.cjs
T
Lauri Ojansivu 5f5822f7d0 Preserve actionable redacted LDAP bind errors
LDAP errors were serialized as empty objects because their name and message are non-enumerable. Preserve diagnostic name, message, code and reason through the existing secret sanitizer. Verify certificate and credential diagnostics plus disabled logging.

Thanks to Nissulya and xet7 !

Refs #6692
2026-09-14 12:21:37 +03:00

27 lines
1.4 KiB
JavaScript

'use strict';
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const source = fs.readFileSync(path.join(__dirname, '../packages/wekan-ldap/server/logger.js'), 'utf8').replace(/^export .*;$/m, '');
function load(enabled) {
const messages = [];
const context = { Error, process: { env: { LDAP_LOG_ENABLED: String(enabled) } }, console: { log: text => messages.push(text) } };
vm.createContext(context); vm.runInContext(source, context);
return { context, messages };
}
const { context, messages } = load(true);
const error = new Error('certificate verification failed; password=secret-value');
error.code = 'CERT_HAS_EXPIRED'; error.password = 'hidden-password';
context.log_error(error);
assert.match(messages[0], /certificate verification failed/);
assert.match(messages[0], /CERT_HAS_EXPIRED/);
assert.doesNotMatch(messages[0], /secret-value|hidden-password/);
assert.doesNotMatch(messages[0], /^\[ERROR\] \{\}$/);
const invalid = new Error('Invalid credentials'); invalid.code = 49;
context.log_error(invalid);
assert.match(messages[1], /Invalid credentials/);
assert.match(messages[1], /49/);
const off = load(false); off.context.log_error(error); assert.equal(off.messages.length, 0);
console.log('ldapErrorLogging: bind/TLS errors stay actionable and redacted; disabled logging stays silent');