diff --git a/webui/src/lib/mock-leak-scan.spec.ts b/webui/src/lib/mock-leak-scan.spec.ts index 1e18409..fee3a61 100644 --- a/webui/src/lib/mock-leak-scan.spec.ts +++ b/webui/src/lib/mock-leak-scan.spec.ts @@ -2,11 +2,15 @@ import { describe, expect, it } from 'vitest' import { leakTerms, type LeakTerm } from '../../mock/leak-terms' -const fixtures = import.meta.glob('../../mock/fixtures/*.json', { - query: '?raw', - import: 'default', - eager: true, -}) as Record +const LEAK_TERMS_FILE = 'mock/leak-terms.ts' + +const fixtures = import.meta.glob('../../mock/fixtures/*.json', { query: '?raw', import: 'default', eager: true }) as Record +const sources = Object.fromEntries( + Object.entries({ + ...import.meta.glob('../../mock/*.ts', { query: '?raw', import: 'default', eager: true }), + ...import.meta.glob('../../e2e/**', { query: '?raw', import: 'default', eager: true }), + } as Record).filter(([file]) => !file.endsWith(LEAK_TERMS_FILE)), +) const env = (globalThis as { process?: { env: Record } }).process?.env ?? {} @@ -29,6 +33,17 @@ describe('mock fixtures', () => { expect(hits).toEqual([]) }) + it('mock sources and e2e specs contain no private identifiers', () => { + expect(Object.keys(sources).length).toBeGreaterThan(0) + const hits: string[] = [] + for (const [file, text] of Object.entries(sources)) { + for (const term of leakTerms(env.LEAK_SCAN_EXTRA_TERMS)) { + if (matches(text, term)) hits.push(`${file}: ${String(term)}`) + } + } + expect(hits).toEqual([]) + }) + it('detects a planted leak', () => { const planted = leakTerms('zz-extra-name').filter((t) => matches('{"u":"zz-extra-name","h":"10.1.2.3","e":"a@b.co"}', t)) expect(planted.length).toBe(3)