Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

constants.test.ts 8.5 KB

You have to be logged in to leave a comment. Sign In
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
  1. import {
  2. ADDITIONAL_PLUGINS,
  3. ADDITIONAL_STRATEGIES,
  4. AGENTIC_EXEMPT_PLUGINS,
  5. AGENTIC_PLUGINS,
  6. ALL_PLUGINS,
  7. ALL_STRATEGIES,
  8. BASE_PLUGINS,
  9. COLLECTIONS,
  10. CONFIG_REQUIRED_PLUGINS,
  11. categoryAliases,
  12. categoryDescriptions,
  13. DATASET_EXEMPT_PLUGINS,
  14. DATASET_PLUGINS,
  15. DEFAULT_NUM_TESTS_PER_PLUGIN,
  16. DEFAULT_PLUGINS,
  17. displayNameOverrides,
  18. HARM_PLUGINS,
  19. LLAMA_GUARD_ENABLED_CATEGORIES,
  20. LLAMA_GUARD_REPLICATE_PROVIDER,
  21. PII_PLUGINS,
  22. pluginDescriptions,
  23. REDTEAM_MODEL,
  24. REDTEAM_PROVIDER_HARM_PLUGINS,
  25. riskCategories,
  26. riskCategorySeverityMap,
  27. Severity,
  28. STRATEGY_COLLECTION_MAPPINGS,
  29. STRATEGY_COLLECTIONS,
  30. STRATEGY_EXEMPT_PLUGINS,
  31. severityDisplayNames,
  32. strategyDescriptions,
  33. strategyDisplayNames,
  34. subCategoryDescriptions,
  35. UNALIGNED_PROVIDER_HARM_PLUGINS,
  36. } from '../../src/redteam/constants';
  37. describe('constants', () => {
  38. it('DEFAULT_NUM_TESTS_PER_PLUGIN should be defined', () => {
  39. expect(DEFAULT_NUM_TESTS_PER_PLUGIN).toBeDefined();
  40. expect(DEFAULT_NUM_TESTS_PER_PLUGIN).toBe(5);
  41. });
  42. it('REDTEAM_MODEL should be defined', () => {
  43. expect(REDTEAM_MODEL).toBeDefined();
  44. expect(REDTEAM_MODEL).toBe('openai:chat:gpt-4.1-2025-04-14');
  45. });
  46. it('LLAMA_GUARD_REPLICATE_PROVIDER should be defined', () => {
  47. expect(LLAMA_GUARD_REPLICATE_PROVIDER).toBeDefined();
  48. expect(LLAMA_GUARD_REPLICATE_PROVIDER).toBe('replicate:moderation:meta/llama-guard-4-12b');
  49. });
  50. it('LLAMA_GUARD_ENABLED_CATEGORIES should contain expected categories', () => {
  51. expect(LLAMA_GUARD_ENABLED_CATEGORIES).toContain('S1');
  52. expect(LLAMA_GUARD_ENABLED_CATEGORIES).toContain('S2');
  53. expect(LLAMA_GUARD_ENABLED_CATEGORIES).not.toContain('S7');
  54. });
  55. it('COLLECTIONS should contain expected values', () => {
  56. expect(COLLECTIONS).toEqual([
  57. 'default',
  58. 'foundation',
  59. 'harmful',
  60. 'pii',
  61. 'bias',
  62. 'medical',
  63. 'guardrails-eval',
  64. ]);
  65. });
  66. it('UNALIGNED_PROVIDER_HARM_PLUGINS should contain expected plugins', () => {
  67. expect(UNALIGNED_PROVIDER_HARM_PLUGINS['harmful:child-exploitation']).toBe(
  68. 'Child Exploitation',
  69. );
  70. expect(UNALIGNED_PROVIDER_HARM_PLUGINS['harmful:hate']).toBe('Hate');
  71. });
  72. it('REDTEAM_PROVIDER_HARM_PLUGINS should contain expected plugins', () => {
  73. expect(REDTEAM_PROVIDER_HARM_PLUGINS['harmful:intellectual-property']).toBe(
  74. 'Intellectual Property violation',
  75. );
  76. expect(REDTEAM_PROVIDER_HARM_PLUGINS['harmful:privacy']).toBe('Privacy violations');
  77. });
  78. it('HARM_PLUGINS should combine plugins from other harm plugin objects', () => {
  79. expect(HARM_PLUGINS).toMatchObject({
  80. ...UNALIGNED_PROVIDER_HARM_PLUGINS,
  81. ...REDTEAM_PROVIDER_HARM_PLUGINS,
  82. 'harmful:misinformation-disinformation':
  83. 'Misinformation & Disinformation - Harmful lies and propaganda',
  84. 'harmful:specialized-advice': 'Specialized Advice - Financial',
  85. });
  86. });
  87. it('PII_PLUGINS should contain expected plugins', () => {
  88. expect(PII_PLUGINS).toEqual(['pii:api-db', 'pii:direct', 'pii:session', 'pii:social']);
  89. });
  90. it('BASE_PLUGINS should contain expected plugins', () => {
  91. expect(BASE_PLUGINS).toContain('contracts');
  92. expect(BASE_PLUGINS).toContain('excessive-agency');
  93. expect(BASE_PLUGINS).toContain('hallucination');
  94. });
  95. it('ADDITIONAL_PLUGINS should contain MCP plugin', () => {
  96. expect(ADDITIONAL_PLUGINS).toContain('mcp');
  97. });
  98. it('DEFAULT_PLUGINS should be a Set containing base plugins, harm plugins and PII plugins', () => {
  99. expect(DEFAULT_PLUGINS).toBeInstanceOf(Set);
  100. expect(DEFAULT_PLUGINS.has('contracts')).toBe(true);
  101. expect(DEFAULT_PLUGINS.has('pii:api-db')).toBe(true);
  102. });
  103. it('ALL_PLUGINS should contain all plugins sorted', () => {
  104. expect(ALL_PLUGINS).toEqual(
  105. [
  106. ...new Set([
  107. ...DEFAULT_PLUGINS,
  108. ...ADDITIONAL_PLUGINS,
  109. ...CONFIG_REQUIRED_PLUGINS,
  110. ...AGENTIC_PLUGINS,
  111. ]),
  112. ].sort(),
  113. );
  114. });
  115. it('DATASET_PLUGINS should contain expected plugins', () => {
  116. const expectedPlugins = [
  117. 'beavertails',
  118. 'cyberseceval',
  119. 'donotanswer',
  120. 'harmbench',
  121. 'toxic-chat',
  122. 'aegis',
  123. 'pliny',
  124. 'unsafebench',
  125. 'xstest',
  126. ];
  127. expect(DATASET_PLUGINS).toEqual(expectedPlugins);
  128. expect(DATASET_PLUGINS).toHaveLength(9);
  129. expectedPlugins.forEach((plugin) => {
  130. expect(DATASET_PLUGINS).toContain(plugin);
  131. });
  132. });
  133. it('AGENTIC_EXEMPT_PLUGINS should contain expected plugins', () => {
  134. expect(AGENTIC_EXEMPT_PLUGINS).toEqual(['system-prompt-override', 'agentic:memory-poisoning']);
  135. });
  136. it('DATASET_EXEMPT_PLUGINS should contain expected plugins', () => {
  137. expect(DATASET_EXEMPT_PLUGINS).toEqual(['pliny', 'unsafebench']);
  138. });
  139. it('STRATEGY_EXEMPT_PLUGINS should combine agentic and dataset exempt plugins', () => {
  140. const expectedPlugins = [
  141. 'system-prompt-override',
  142. 'agentic:memory-poisoning',
  143. 'pliny',
  144. 'unsafebench',
  145. ];
  146. expect(STRATEGY_EXEMPT_PLUGINS).toEqual(expectedPlugins);
  147. expect(STRATEGY_EXEMPT_PLUGINS).toEqual([...AGENTIC_EXEMPT_PLUGINS, ...DATASET_EXEMPT_PLUGINS]);
  148. });
  149. it('Severity enum should have expected values', () => {
  150. expect(Severity.Critical).toBe('critical');
  151. expect(Severity.High).toBe('high');
  152. expect(Severity.Medium).toBe('medium');
  153. expect(Severity.Low).toBe('low');
  154. });
  155. it('severityDisplayNames should have display names for all severities', () => {
  156. expect(severityDisplayNames[Severity.Critical]).toBe('Critical');
  157. expect(severityDisplayNames[Severity.High]).toBe('High');
  158. expect(severityDisplayNames[Severity.Medium]).toBe('Medium');
  159. expect(severityDisplayNames[Severity.Low]).toBe('Low');
  160. });
  161. it('should have agentic:memory-poisoning in Security & Access Control category', () => {
  162. expect(riskCategories['Security & Access Control']).toBeDefined();
  163. expect(riskCategories['Security & Access Control']).toContain('agentic:memory-poisoning');
  164. });
  165. it('should have descriptions for all risk categories', () => {
  166. const categories = Object.keys(riskCategories) as (keyof typeof categoryDescriptions)[];
  167. categories.forEach((category) => {
  168. expect(categoryDescriptions[category]).toBeDefined();
  169. expect(typeof categoryDescriptions[category]).toBe('string');
  170. });
  171. });
  172. it('should have correct display name for MCP plugin', () => {
  173. expect(displayNameOverrides['mcp']).toBe('Model Context Protocol');
  174. });
  175. it('should have correct severity for MCP plugin', () => {
  176. expect(riskCategorySeverityMap['mcp']).toBe(Severity.High);
  177. });
  178. it('should have correct alias for MCP plugin', () => {
  179. expect(categoryAliases['mcp']).toBe('MCP');
  180. });
  181. it('should have correct plugin description for MCP plugin', () => {
  182. expect(pluginDescriptions['mcp']).toBe(
  183. 'Tests for vulnerabilities to Model Context Protocol (MCP) attacks',
  184. );
  185. });
  186. it('should have correct subcategory description for MCP plugin', () => {
  187. expect(subCategoryDescriptions['mcp']).toBe(
  188. 'Tests for vulnerabilities to Model Context Protocol (MCP) attacks',
  189. );
  190. });
  191. it('STRATEGY_COLLECTIONS should contain expected collections', () => {
  192. expect(STRATEGY_COLLECTIONS).toEqual(['other-encodings']);
  193. });
  194. it('STRATEGY_COLLECTION_MAPPINGS should have correct mappings', () => {
  195. expect(STRATEGY_COLLECTION_MAPPINGS['other-encodings']).toEqual([
  196. 'camelcase',
  197. 'morse',
  198. 'piglatin',
  199. 'emoji',
  200. ]);
  201. });
  202. it('ALL_STRATEGIES should include strategy collections', () => {
  203. expect(ALL_STRATEGIES).toContain('other-encodings');
  204. });
  205. it('strategy collections should have proper display names', () => {
  206. expect(strategyDisplayNames['other-encodings']).toBe('Collection of Text Encodings');
  207. });
  208. it('ADDITIONAL_STRATEGIES should include emoji strategy', () => {
  209. expect(ADDITIONAL_STRATEGIES).toContain('emoji');
  210. });
  211. it('should have correct display name for emoji strategy', () => {
  212. expect(strategyDisplayNames['emoji']).toBe('Emoji Smuggling');
  213. });
  214. it('should have correct strategy description for emoji strategy', () => {
  215. expect(strategyDescriptions['emoji']).toBe(
  216. 'Tests detection and handling of UTF-8 payloads hidden inside emoji variation selectors',
  217. );
  218. });
  219. it('should include emoji in other-encodings strategy collection', () => {
  220. expect(STRATEGY_COLLECTION_MAPPINGS['other-encodings']).toContain('emoji');
  221. });
  222. it('should have correct subcategory description for emoji strategy', () => {
  223. expect(subCategoryDescriptions['emoji']).toBe(
  224. 'Tests handling of text hidden using emoji variation selectors',
  225. );
  226. });
  227. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...