test(webui): widen leak scan to mock sources and e2e

This commit is contained in:
2026-11-25 12:11:20 +00:00
parent 34c2bb8dbf
commit dccf04f840
+20 -5
View File
@@ -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<string, string>
const LEAK_TERMS_FILE = 'mock/leak-terms.ts'
const fixtures = import.meta.glob('../../mock/fixtures/*.json', { query: '?raw', import: 'default', eager: true }) as Record<string, string>
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<string, string>).filter(([file]) => !file.endsWith(LEAK_TERMS_FILE)),
)
const env = (globalThis as { process?: { env: Record<string, string | undefined> } }).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":"[email protected]"}', t))
expect(planted.length).toBe(3)