audit.test.ts26 lines · main
| 1 | import { describe, expect, test } from 'bun:test'; |
| 2 | |
| 3 | import { auditIpHashHint } from './audit.js'; |
| 4 | |
| 5 | describe('briven-engine audit (privacy)', () => { |
| 6 | test('ip hint is 8 hex chars, never the raw IP', () => { |
| 7 | const hint = auditIpHashHint('203.0.113.42'); |
| 8 | expect(hint).toMatch(/^[0-9a-f]{8}$/); |
| 9 | expect(hint).not.toContain('203'); |
| 10 | expect(hint).not.toContain('113'); |
| 11 | }); |
| 12 | |
| 13 | test('same IP always same hint', () => { |
| 14 | expect(auditIpHashHint('198.51.100.7')).toBe(auditIpHashHint('198.51.100.7')); |
| 15 | }); |
| 16 | |
| 17 | test('different IPs get different hints', () => { |
| 18 | expect(auditIpHashHint('198.51.100.7')).not.toBe(auditIpHashHint('198.51.100.8')); |
| 19 | }); |
| 20 | |
| 21 | test('empty / null IP → null hint', () => { |
| 22 | expect(auditIpHashHint(null)).toBeNull(); |
| 23 | expect(auditIpHashHint(undefined)).toBeNull(); |
| 24 | expect(auditIpHashHint('')).toBeNull(); |
| 25 | }); |
| 26 | }); |