fix unit test

This commit is contained in:
Bruno Windels 2022-05-09 14:50:52 +02:00
parent cd8fac2872
commit a2a17dbf7a

View file

@ -323,24 +323,22 @@ import {LogItem} from "../../logging/LogItem";
export function tests() { export function tests() {
return { return {
"loginToken should not be in logs": (assert) => { "loginToken should not be in logs": (assert) => {
const transformer = (item) => { const logPersister = Object.create(IDBLogPersister.prototype);
if (item.e?.stack) { logPersister._queuedItems = [];
item.e.stack = item.e.stack.replace(/(?<=\/\?loginToken=).+/, "<snip>"); logPersister.options = {
serializedTransformer: (item) => {
if (item.e?.stack) {
item.e.stack = item.e.stack.replace(/(?<=\/\?loginToken=).+/, "<snip>");
}
return item;
} }
return item;
}; };
const logger = { const logger = { _now() {return 5;} };
_queuedItems: [],
_serializedTransformer: transformer,
_now: () => {}
};
logger.persist = IDBLogger.prototype._persistItem.bind(logger);
const logItem = new LogItem("test", 1, logger); const logItem = new LogItem("test", 1, logger);
logItem.error = new Error(); logItem.error = new Error();
logItem.error.stack = "main http://localhost:3000/src/main.js:55\n<anonymous> http://localhost:3000/?loginToken=secret:26" logItem.error.stack = "main http://localhost:3000/src/main.js:55\n<anonymous> http://localhost:3000/?loginToken=secret:26"
logger.persist(logItem, null, false); logPersister.reportItem(logItem, null, false);
const item = logger._queuedItems.pop(); const item = logPersister._queuedItems.pop();
console.log(item);
assert.strictEqual(item.json.search("secret"), -1); assert.strictEqual(item.json.search("secret"), -1);
} }
}; };