|
| 1 | +import { DESKTOP_IMPORT_TOKEN_HEADER } from '@sim/desktop-bridge' |
1 | 2 | import { describe, expect, it } from 'vitest' |
2 | 3 | import { createDesktopExecutorClient, UnsendableRequestError } from '@/main/desktop-executor/client' |
3 | 4 |
|
@@ -48,4 +49,38 @@ describe('desktop executor client', () => { |
48 | 49 | const loneSurrogate = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/ |
49 | 50 | expect(loneSurrogate.test(sentMessage)).toBe(false) |
50 | 51 | }) |
| 52 | + |
| 53 | + it('sends an import entry with its execution token in a header, never in the URL', async () => { |
| 54 | + const received: Array<{ url: string; token: string | null }> = [] |
| 55 | + const client = createDesktopExecutorClient({ |
| 56 | + origin: () => 'https://sim.test', |
| 57 | + fetch: async (url, init) => { |
| 58 | + received.push({ url, token: new Headers(init.headers).get(DESKTOP_IMPORT_TOKEN_HEADER) }) |
| 59 | + return Response.json({ id: 'file-1', name: 'notes.txt' }) |
| 60 | + }, |
| 61 | + deviceId: '00000000-0000-4000-8000-000000000000', |
| 62 | + }) |
| 63 | + |
| 64 | + await client.importEntry( |
| 65 | + { |
| 66 | + call: { |
| 67 | + toolCallId: 'call-1', |
| 68 | + toolName: 'import_local_files', |
| 69 | + args: {}, |
| 70 | + chatId: 'chat-1', |
| 71 | + workspaceId: 'ws-1', |
| 72 | + executionToken: 'secret-token-1', |
| 73 | + }, |
| 74 | + kind: 'file', |
| 75 | + sourceName: 'notes.txt', |
| 76 | + relativePath: '', |
| 77 | + content: new Blob(['hello']), |
| 78 | + }, |
| 79 | + new AbortController().signal |
| 80 | + ) |
| 81 | + |
| 82 | + expect(received).toHaveLength(1) |
| 83 | + expect(received[0]?.token).toBe('secret-token-1') |
| 84 | + expect(decodeURIComponent(received[0]?.url ?? '')).not.toContain('secret-token-1') |
| 85 | + }) |
51 | 86 | }) |
0 commit comments