-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathalert.mock.ts
73 lines (63 loc) · 1.6 KB
/
alert.mock.ts
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Alert, AlertSeverity } from '@/api/generated'
import { faker } from '@faker-js/faker'
const ALERT_SECRET_FIELDS = {
trigger_string: 'foo',
trigger_type: 'codegate-secrets',
} satisfies Pick<Alert, 'trigger_string' | 'trigger_type'>
const ALERT_PII_FIELDS = {
trigger_string: 'fakemail@fakedomain.mock',
trigger_type: 'codegate-pii',
} satisfies Pick<Alert, 'trigger_string' | 'trigger_type'>
const ALERT_MALICIOUS_FIELDS = {
trigger_string: {
name: 'invokehttp',
type: 'pypi',
status: 'malicious',
description: 'Python HTTP for Humans.',
},
trigger_type: 'codegate-context-retriever',
} satisfies Pick<Alert, 'trigger_string' | 'trigger_type'>
const getBaseAlert = ({
timestamp,
}: {
timestamp: string
}): Omit<Alert, 'trigger_type' | 'trigger_string'> => ({
id: faker.string.uuid(),
prompt_id: faker.string.uuid(),
code_snippet: null,
trigger_category: AlertSeverity.CRITICAL,
timestamp: timestamp,
})
export const mockAlert = ({
type,
}: {
type: 'secret' | 'malicious' | 'pii'
}): Alert => {
const timestamp = faker.date.recent().toISOString()
const base: Omit<Alert, 'trigger_type' | 'trigger_string'> = getBaseAlert({
timestamp,
})
switch (type) {
case 'malicious': {
const result: Alert = {
...base,
...ALERT_MALICIOUS_FIELDS,
}
return result
}
case 'secret': {
const result: Alert = {
...base,
...ALERT_SECRET_FIELDS,
}
return result
}
case 'pii': {
const result: Alert = {
...base,
...ALERT_PII_FIELDS,
}
return result
}
}
}