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.3 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
  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. });
  20. });
  21. it('should handle uppercase and lowercase letters', () => {
  22. const testCase: TestCase = {
  23. vars: { text: 'HELLO hello' },
  24. assert: [{ type: 'equals', value: 'Test', metric: 'Test' }],
  25. };
  26. const result = addRot13([testCase], 'text');
  27. expect(result[0].vars?.text).toBe('URYYB uryyb');
  28. });
  29. it('should not change non-alphabetic characters', () => {
  30. const testCase: TestCase = {
  31. vars: { text: 'Hello, World! 123' },
  32. assert: [{ type: 'equals', value: 'Test', metric: 'Test' }],
  33. };
  34. const result = addRot13([testCase], 'text');
  35. expect(result[0].vars?.text).toBe('Uryyb, Jbeyq! 123');
  36. });
  37. });
Tip!

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

Comments

Loading...