test(webui): anonymised admin API fixtures with leak scan

This commit is contained in:
2026-11-25 11:52:35 +00:00
parent 4c61d19a72
commit 4d77623f5d
211 changed files with 36747 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
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 env = (globalThis as { process?: { env: Record<string, string | undefined> } }).process?.env ?? {}
function matches(text: string, term: LeakTerm): boolean {
return typeof term === 'string' ? text.toLowerCase().includes(term.toLowerCase()) : term.test(text)
}
describe('mock fixtures', () => {
it('has fixtures to scan', () => {
expect(Object.keys(fixtures).length).toBeGreaterThan(0)
})
it('committed fixtures contain no private identifiers', () => {
const hits: string[] = []
for (const [file, text] of Object.entries(fixtures)) {
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)
})
})