|
1 | 1 | import { Cluster } from 'src/otomi-models' |
2 | | -import { getServiceUrl } from 'src/utils' |
| 2 | +import { getSanitizedErrorMessage, getServiceUrl, sanitizeGitPassword } from 'src/utils' |
| 3 | +import { cleanEnv, GIT_PASSWORD } from './validators' |
3 | 4 |
|
4 | 5 | describe('Utils', () => { |
5 | 6 | const cluster: Cluster = { |
@@ -57,4 +58,28 @@ describe('Utils', () => { |
57 | 58 | expect(service.subdomain).toEqual('aa') |
58 | 59 | expect(service.domain).toEqual('bb.cc.dd.ee') |
59 | 60 | }) |
| 61 | + |
| 62 | + describe('sanitizeGitPassword should remove git credentials', () => { |
| 63 | + const env = cleanEnv({ |
| 64 | + GIT_PASSWORD, |
| 65 | + }) |
| 66 | + test('from strings', () => { |
| 67 | + expect(sanitizeGitPassword('test string')).toBe('test string') |
| 68 | + expect(sanitizeGitPassword(`${env.GIT_PASSWORD} test string ${env.GIT_PASSWORD}`)).toBe('**** test string ****') |
| 69 | + }) |
| 70 | + test('from objects', () => { |
| 71 | + expect(sanitizeGitPassword(JSON.stringify({ test: 'some string' }))).toEqual('{"test":"some string"}') |
| 72 | + expect(sanitizeGitPassword(JSON.stringify({ test: `some string ${env.GIT_PASSWORD}` }))).toEqual( |
| 73 | + '{"test":"some string ****"}', |
| 74 | + ) |
| 75 | + }) |
| 76 | + test('return empty string on empty or undefined input', () => { |
| 77 | + expect(sanitizeGitPassword('')).toEqual('') |
| 78 | + expect(sanitizeGitPassword(undefined)).toEqual('') |
| 79 | + }) |
| 80 | + test('extract message from exception', () => { |
| 81 | + expect(getSanitizedErrorMessage(new Error('test error'))).toEqual('test error') |
| 82 | + expect(getSanitizedErrorMessage(new Error(`test error ${env.GIT_PASSWORD}`))).toEqual('test error ****') |
| 83 | + }) |
| 84 | + }) |
60 | 85 | }) |
0 commit comments