mirror of
https://github.com/UNITRONIX/BetterDesk.git
synced 2026-09-10 17:45:42 +00:00
648a8d4f8a
Commit web-nodejs lockfile with tar override; CI uses npm ci and moderate npm audit. Add LOG_LEVEL filtering and log redaction in Node console and Go server. Validate WS tokens on bd-signal; require single-use token for remote-agent relay. Limit active relay sessions per IP and block open enrollment without TLS.
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
describe('logger', () => {
|
|
const originalEnv = process.env;
|
|
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
process.env = { ...originalEnv };
|
|
});
|
|
|
|
afterAll(() => {
|
|
process.env = originalEnv;
|
|
});
|
|
|
|
test('production defaults to warn — info is suppressed', () => {
|
|
process.env.NODE_ENV = 'production';
|
|
delete process.env.LOG_LEVEL;
|
|
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
|
|
const logger = require('../lib/logger');
|
|
expect(logger.level).toBe('warn');
|
|
logger.info('hidden info');
|
|
logger.warn('visible warn');
|
|
|
|
expect(logSpy).not.toHaveBeenCalled();
|
|
expect(warnSpy).toHaveBeenCalled();
|
|
logSpy.mockRestore();
|
|
warnSpy.mockRestore();
|
|
});
|
|
|
|
test('child logger redacts quoted usernames in info messages', () => {
|
|
process.env.NODE_ENV = 'development';
|
|
process.env.LOG_LEVEL = 'info';
|
|
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {});
|
|
|
|
const logger = require('../lib/logger').child('AUTH');
|
|
logger.info("Login failed: user 'administrator' not found");
|
|
|
|
expect(logSpy).toHaveBeenCalled();
|
|
const line = logSpy.mock.calls[0].join(' ');
|
|
expect(line).toContain('a***r');
|
|
expect(line).not.toContain('administrator');
|
|
logSpy.mockRestore();
|
|
});
|
|
});
|