39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { describe, expect, test } from 'vitest';
|
|
|
|
import { createRedactor } from '../../src/redact';
|
|
|
|
describe('createRedactor', () => {
|
|
test('redacts group-less token patterns without emitting a literal $1', () => {
|
|
const redact = createRedactor([]);
|
|
const output = redact('token ghs_ABC123 and sk-xyz789 here');
|
|
|
|
expect(output).toContain('[redacted]');
|
|
expect(output).not.toContain('$1');
|
|
expect(output).not.toContain('ghs_ABC123');
|
|
expect(output).not.toContain('sk-xyz789');
|
|
});
|
|
|
|
test('redacts github_pat_ tokens to [redacted]', () => {
|
|
const redact = createRedactor([]);
|
|
const output = redact('github_pat_ABCDEF123456');
|
|
|
|
expect(output).toBe('[redacted]');
|
|
expect(output).not.toContain('$1');
|
|
});
|
|
|
|
test('keeps the key= prefix for key=value secrets', () => {
|
|
const redact = createRedactor([]);
|
|
|
|
expect(redact('api_key=secret')).toBe('api_key=[redacted]');
|
|
expect(redact('password=hunter2')).toBe('password=[redacted]');
|
|
});
|
|
|
|
test('redacts caller-supplied secret values verbatim', () => {
|
|
const redact = createRedactor(['super-secret-value']);
|
|
|
|
expect(redact('the value is super-secret-value')).toBe(
|
|
'the value is [redacted]',
|
|
);
|
|
});
|
|
});
|