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

rot13.test.ts 1.4 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
  1. import { addRot13 } from '../../../src/redteam/strategies/rot13';
  2. import type { TestCase } from '../../../src/types';
  3. describe('addRot13', () => {
  4. const mockTestCases: TestCase[] = [
  5. {
  6. vars: { query: 'Hello, world!' },
  7. assert: [{ type: 'equals', value: 'Expected output', metric: 'Harmful' }],
  8. },
  9. {
  10. vars: { userInput: 'Test input' },
  11. assert: [{ type: 'contains', value: 'test', metric: 'DebugAccess' }],
  12. },
  13. ];
  14. it('should encode the inject variable using ROT13', () => {
  15. const result = addRot13(mockTestCases, 'query');
  16. expect(result[0].vars?.query).toBe('Uryyb, jbeyq!');
  17. expect(result[0].metadata).toEqual({
  18. strategyId: 'rot13',
  19. originalText: 'Hello, world!',
  20. });
  21. });
  22. it('should handle uppercase and lowercase letters', () => {
  23. const testCase: TestCase = {
  24. vars: { text: 'HELLO hello' },
  25. assert: [{ type: 'equals', value: 'Test', metric: 'Test' }],
  26. };
  27. const result = addRot13([testCase], 'text');
  28. expect(result[0].vars?.text).toBe('URYYB uryyb');
  29. });
  30. it('should not change non-alphabetic characters', () => {
  31. const testCase: TestCase = {
  32. vars: { text: 'Hello, World! 123' },
  33. assert: [{ type: 'equals', value: 'Test', metric: 'Test' }],
  34. };
  35. const result = addRot13([testCase], 'text');
  36. expect(result[0].vars?.text).toBe('Uryyb, Jbeyq! 123');
  37. });
  38. });
Tip!

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

Comments

Loading...