renovate/lib/util/sanitize.spec.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

import {
addSecretForSanitizing,
clearSanitizedSecretsList,
sanitize,
} from './sanitize';
import { toBase64 } from './string';
2019-09-12 10:48:31 +00:00
describe('util/sanitize', () => {
2019-09-12 10:48:31 +00:00
beforeEach(() => {
clearSanitizedSecretsList();
2019-09-12 10:48:31 +00:00
});
it('sanitizes empty string', () => {
expect(sanitize(null as never)).toBeNull();
expect(sanitize('')).toBe('');
2019-09-12 10:48:31 +00:00
});
it('sanitizes secrets from strings', () => {
const token = '123testtoken';
2019-09-12 10:48:31 +00:00
const username = 'userabc';
const password = 'password123';
addSecretForSanitizing(token);
const hashed = toBase64(`${username}:${password}`);
addSecretForSanitizing(hashed);
addSecretForSanitizing(password);
const input = `My token is ${token}, username is "${username}" and password is "${password}" (hashed: ${hashed})`;
const output =
'My token is **redacted**, username is "userabc" and password is "**redacted**" (hashed: **redacted**)';
expect(sanitize(input)).toBe(output);
const inputX2 = [input, input].join('\n');
const outputX2 = [output, output].join('\n');
expect(sanitize(inputX2)).toBe(outputX2);
2019-09-12 10:48:31 +00:00
});
});