Files
stack/packages/queue/tests/refusal-redaction.test.mjs

25 lines
1.1 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
const secret = 'sk-test-NOT-A-SECRET-1234';
// JSON.parse quotes a prefix near this fault on Node 26; check partial leaks too.
const malformed = secret;
function safe(label, ErrorType, properties = {}) {
return error => {
assert.ok(error instanceof ErrorType);
for (const [key, value] of Object.entries(properties)) assert.equal(error[key], value);
assert.ok(error.message.includes(label), error.message);
assert.doesNotMatch(error.message, /sk-test|Unexpected token/);
assert.doesNotMatch(error.stack, /sk-test/);
assert.equal(error.cause, undefined);
return true;
};
}
import { loadDoc, parseMigrationMap } from '../src/queue.mjs';
import { QueueError } from '../src/errors.mjs';
for (const [label, parse] of [
['queue.json', () => loadDoc(Buffer.from(malformed))],
["migration map's queue-map block", () => parseMigrationMap('```json queue-map\n' + malformed + '\n```')],
]) test(`${label} refusal omits parser bytes`, () => {
assert.throws(parse, safe(label, QueueError, { code: 2 }));
});