@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 04:45 UTC

next
ts 33 lines 1.33 KB
Raw
1 import { afterEach, describe, expect, it, vi } from 'vitest';
2 import { ComposioBlockedInternalUrlError } from '../../src/errors/SsrfErrors';
3 import { ssrfSafeFetch, ssrfSafeFetchWhereSupported } from '../../src/utils/ssrfGuard.workerd';
4
5 describe('ssrfSafeFetch (workerd)', () => {
6 afterEach(() => vi.unstubAllGlobals());
7
8 it('fails closed without attempting a fetch', async () => {
9 const fetchMock = vi.fn();
10 vi.stubGlobal('fetch', fetchMock);
11
12 await expect(ssrfSafeFetch('https://example.com/file.pdf')).rejects.toBeInstanceOf(
13 ComposioBlockedInternalUrlError
14 );
15 expect(fetchMock).not.toHaveBeenCalled();
16 });
17
18 it('lets session file transfers through, since the guard cannot run here', async () => {
19 // Failing closed would remove a working feature from Workers rather than
20 // close a hole reachable there: an edge worker has no DNS API to validate
21 // with, and its fetch does not originate inside the caller's network.
22 const response = new Response('ok');
23 const fetchMock = vi.fn().mockResolvedValue(response);
24 vi.stubGlobal('fetch', fetchMock);
25
26 await expect(
27 ssrfSafeFetchWhereSupported('https://s3.example.com/presigned', { method: 'PUT' })
28 ).resolves.toBe(response);
29 expect(fetchMock).toHaveBeenCalledWith('https://s3.example.com/presigned', {
30 method: 'PUT',
31 });
32 });
33 });