Skip to content
Snippets Groups Projects
Select Git revision
  • 982cefff2b8a3c697fe52fd5e023580a0678322e
  • main default protected
  • renovate/migrate-config
  • next
  • fix/36615b-branch-reuse-no-cache
  • renovate/main-redis-5.x
  • revert-31645-feat/rename-gradle-wrapper-validation-action
  • chore/punycode
  • refactor/pin-new-value
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • gh-readonly-queue/next/pr-35654-137d934242c784e0c45d4b957362214f0eade1d7
  • fix/32307-global-extends-merging
  • fix/32307-global-extends-repositories
  • gh-readonly-queue/next/pr-35009-046ebf7cb84ab859f7fefceb5fa53a54ce9736f8
  • 41.42.2
  • 41.42.1
  • 41.42.0
  • 41.41.0
  • 41.40.0
  • 41.39.0
  • 41.38.2
  • 41.38.1
  • 41.38.0
  • 41.37.12
  • 41.37.11
  • 41.37.10
  • 41.37.9
  • 41.37.8
  • 41.37.7
  • 41.37.6
  • 41.37.5
  • 41.37.4
  • 41.37.3
  • 41.37.2
41 results

util.spec.ts

Blame
  • sanitize.spec.ts 1.34 KiB
    import {
      addSecretForSanitizing,
      clearSanitizedSecretsList,
      sanitize,
    } from './sanitize';
    import { toBase64 } from './string';
    
    describe('util/sanitize', () => {
      beforeEach(() => {
        clearSanitizedSecretsList();
      });
    
      it('sanitizes empty string', () => {
        addSecretForSanitizing('');
        expect(sanitize(null as never)).toBeNull();
        expect(sanitize('')).toBe('');
      });
    
      it('sanitizes secrets from strings', () => {
        const token = '123testtoken';
        const username = 'userabc';
        const password = 'password123';
        addSecretForSanitizing(token, 'global');
        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);
      });
    
      it('sanitizes github app tokens', () => {
        addSecretForSanitizing('x-access-token:abc123');
        expect(sanitize(`hello ${toBase64('abc123')} world`)).toBe(
          'hello **redacted** world'
        );
      });
    });