redaction.test.ts37 lines · main
| 1 | import assert from 'node:assert/strict'; |
| 2 | import { test } from 'node:test'; |
| 3 | |
| 4 | import { containsForbiddenContent, redactValue } from './redaction.js'; |
| 5 | |
| 6 | test('containsForbiddenContent flags emails', () => { |
| 7 | assert.equal(containsForbiddenContent('user@example.com'), true); |
| 8 | assert.equal(containsForbiddenContent('contact j.flandriendev@hotmail.com today'), true); |
| 9 | }); |
| 10 | |
| 11 | test('containsForbiddenContent flags IPv4 addresses', () => { |
| 12 | assert.equal(containsForbiddenContent('client at 192.168.1.5 logged in'), true); |
| 13 | assert.equal(containsForbiddenContent('peer 10.0.0.1'), true); |
| 14 | }); |
| 15 | |
| 16 | test('containsForbiddenContent allows harmless content', () => { |
| 17 | assert.equal(containsForbiddenContent('deploy succeeded'), false); |
| 18 | assert.equal(containsForbiddenContent('user_id=u_abc123'), false); |
| 19 | }); |
| 20 | |
| 21 | test('redactValue replaces emails with [REDACTED:email]', () => { |
| 22 | assert.equal(redactValue('contact user@example.com'), 'contact [REDACTED:email]'); |
| 23 | }); |
| 24 | |
| 25 | test('redactValue replaces IPv4 with [REDACTED:ip]', () => { |
| 26 | assert.equal(redactValue('peer 10.0.0.1 connected'), 'peer [REDACTED:ip] connected'); |
| 27 | }); |
| 28 | |
| 29 | test('redactValue leaves harmless strings unchanged', () => { |
| 30 | assert.equal(redactValue('hello world'), 'hello world'); |
| 31 | }); |
| 32 | |
| 33 | test('redactValue passes non-string values through unchanged', () => { |
| 34 | assert.equal(redactValue(42), 42); |
| 35 | assert.equal(redactValue(null), null); |
| 36 | assert.deepEqual(redactValue({ key: 'value' }), { key: 'value' }); |
| 37 | }); |