forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentryScrub.test.ts
More file actions
37 lines (32 loc) · 1.22 KB
/
Copy pathsentryScrub.test.ts
File metadata and controls
37 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { describe, it, expect } from 'vitest'
import { scrubEmails, scrubEventPii } from './sentryScrub'
describe('scrubEmails', () => {
it('replaces an email with a placeholder', () => {
expect(scrubEmails('failed for chris.demian@gmail.com while syncing')).toBe(
'failed for [email] while syncing'
)
})
it('replaces every email in the string', () => {
expect(scrubEmails('a@b.co and c.d@e-f.io')).toBe('[email] and [email]')
})
it('leaves email-free text untouched', () => {
expect(scrubEmails('database timeout after 30s')).toBe('database timeout after 30s')
})
})
describe('scrubEventPii', () => {
it('scrubs the message and exception values', () => {
const event = {
message: 'login failed for user@example.com',
exception: {
values: [{ value: 'token for admin@corp.io rejected' }, { value: 'no pii here' }]
}
}
const out = scrubEventPii(event)
expect(out.message).toBe('login failed for [email]')
expect(out.exception.values[0].value).toBe('token for [email] rejected')
expect(out.exception.values[1].value).toBe('no pii here')
})
it('handles an event with no message or exception', () => {
expect(() => scrubEventPii({})).not.toThrow()
})
})