Skip to content

Commit a997d8f

Browse files
committed
test(pii): check PII on both sides of the long run is masked in place
1 parent 3cb353b commit a997d8f

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

‎apps/sim/scripts/test-pii-redaction-e2e.ts‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import { getErrorMessage } from '@sim/utils/errors'
1515
* Checks, each recorded in the report:
1616
* - Presidio masks a text over spaCy's limit: a name straddling an NER window edge,
1717
* a name at the very end, and a custom pattern that spans whitespace.
18-
* - Presidio masks a name beside a long unbroken run of brackets within seconds;
19-
* spaCy's own tokenizer needs time quadratic in such a run's length.
18+
* - Presidio masks names and an email on both sides of a long unbroken run of
19+
* brackets in place, within seconds; spaCy's own tokenizer needs time quadratic
20+
* in such a run's length.
2021
* - A persisted log holding a 5M-character base64 PDF and a 3M-character text that
2122
* names a person at the end: the PDF becomes the binary marker without reaching
2223
* Presidio, the name is masked by real NER, and no request fails.
@@ -179,12 +180,18 @@ async function main(): Promise<void> {
179180
return { textChars: text.length }
180181
})
181182

182-
await check('Presidio masks a name beside a long unbroken run within seconds', async () => {
183-
const text = `${NAME_SENTENCE} ${'['.repeat(20_000)}${']'.repeat(20_000)}`
183+
await check('Presidio masks PII around a long unbroken run within seconds', async () => {
184+
const run = `${'['.repeat(20_000)}${']'.repeat(20_000)}`
185+
const after = '   Write to ada@example.com today.\n'
186+
const text = `${NAME_SENTENCE} ${run}${after}${NAME_SENTENCE}`
184187
const response = await realFetch(new URL('/redact_batch', presidioUrl), {
185188
method: 'POST',
186189
headers: { 'content-type': 'application/json' },
187-
body: JSON.stringify({ texts: [text], language: 'en', entities: ['PERSON'] }),
190+
body: JSON.stringify({
191+
texts: [text],
192+
language: 'en',
193+
entities: ['PERSON', 'EMAIL_ADDRESS'],
194+
}),
188195
signal: AbortSignal.timeout(30_000),
189196
})
190197
const body = await response.text()
@@ -194,9 +201,11 @@ async function main(): Promise<void> {
194201
`Presidio answered ${response.status}: ${body.slice(0, 200)}`
195202
)
196203
const [masked] = (JSON.parse(body) as { texts: string[] }).texts
197-
assert(
198-
masked.startsWith('Please send questions to <PERSON> before Friday. ['),
199-
'The name beside the run was not masked'
204+
const maskedSentence = 'Please send questions to <PERSON> before Friday.'
205+
assert.equal(
206+
masked,
207+
`${maskedSentence} ${run}${after.replace('ada@example.com', '<EMAIL_ADDRESS>')}${maskedSentence}`,
208+
'PII around the run was not masked in place'
200209
)
201210
return { textChars: text.length }
202211
})

0 commit comments

Comments
 (0)