Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import { describe, it, expect } from 'vitest'; |
| 2 | import { encodeSecret, decodeSecret } from '../src/stores/shared'; |
| 3 | |
| 4 | describe('shared encoding', () => { |
| 5 | it('roundtrips arbitrary bytes through base64 with the b64: prefix', () => { |
| 6 | const inputs: Uint8Array[] = [ |
| 7 | new Uint8Array(), |
| 8 | new Uint8Array([0]), |
| 9 | new Uint8Array([1, 2, 3, 4, 5]), |
| 10 | new Uint8Array([0xff, 0xfe, 0xfd]), |
| 11 | new Uint8Array(Buffer.from('plain string', 'utf8')), |
| 12 | new Uint8Array(Buffer.from('password with spaces\nand newline', 'utf8')), |
| 13 | // 1 KiB of pseudo-random data |
| 14 | crypto.getRandomValues(new Uint8Array(1024)), |
| 15 | ]; |
| 16 | for (const bytes of inputs) { |
| 17 | const encoded = encodeSecret(bytes); |
| 18 | expect(encoded.startsWith('b64:')).toBe(true); |
| 19 | const decoded = decodeSecret(encoded); |
| 20 | expect(Array.from(decoded)).toEqual(Array.from(bytes)); |
| 21 | } |
| 22 | }); |
| 23 | |
| 24 | it('tolerates a trailing newline from CLI stdout', () => { |
| 25 | const encoded = encodeSecret(new Uint8Array([1, 2, 3])); |
| 26 | expect(Array.from(decodeSecret(encoded + '\n'))).toEqual([1, 2, 3]); |
| 27 | }); |
| 28 | |
| 29 | it('rejects blobs without the b64: prefix', () => { |
| 30 | expect(() => decodeSecret('no-prefix-here')).toThrowError(); |
| 31 | }); |
| 32 | |
| 33 | it('rejects blobs with non-base64 characters after the prefix', () => { |
| 34 | expect(() => decodeSecret('b64:!!!not-base64!!!')).toThrowError(); |
| 35 | }); |
| 36 | }); |