23 行
872 B
TypeScript
23 行
872 B
TypeScript
import assert from 'node:assert/strict'
|
|
import test from 'node:test'
|
|
|
|
import { assertBugCollectPrivacyConsent, sanitizeDiagnostic } from '../src/privacy'
|
|
|
|
test('diagnostic sanitization removes secrets and common identity values recursively', () => {
|
|
const sanitized = sanitizeDiagnostic({
|
|
authorization: 'Bearer secret-token',
|
|
nested: {
|
|
message: 'phone=13800138000 id=110101199001011234',
|
|
token: 'secret',
|
|
},
|
|
})
|
|
const serialized = JSON.stringify(sanitized)
|
|
assert.doesNotMatch(serialized, /secret-token|13800138000|110101199001011234|"secret"/)
|
|
assert.match(serialized, /REDACTED|PHONE|ID_CARD/)
|
|
})
|
|
|
|
test('manual BugCollect test upload still requires privacy consent', () => {
|
|
assert.throws(() => assertBugCollectPrivacyConsent(false), /Privacy consent is required/)
|
|
assert.doesNotThrow(() => assertBugCollectPrivacyConsent(true))
|
|
})
|