62
expect(fetchMock).toHaveBeenCalledOnce();
63
});
64
65
+ it('[Given] a proxy binary URL targets cloud metadata [Then] it blocks the download', async () => {
66
+ const fetchMock = vi
67
+ .fn()
68
+ .mockResolvedValueOnce(
69
+ new Response(JSON.stringify({ session_id: 'session-1' }), {
70
+ status: 200,
71
+ headers: { 'content-type': 'application/json' },
72
+ })
73
+ )
74
+ .mockResolvedValueOnce(
75
+ new Response(
76
+ JSON.stringify({
77
+ binary_data: {
78
+ url: 'http://169.254.169.254/latest/meta-data/iam/security-credentials/',
79
+ },
80
+ status: 200,
81
+ }),
82
+ {
83
+ status: 200,
84
+ headers: { 'content-type': 'application/json' },
85
+ }
86
+ )
87
+ )
88
+ .mockResolvedValueOnce(new Response('stolen cloud credentials', { status: 200 }));
89
+ vi.stubGlobal('fetch', fetchMock);
90
+
91
+ await installRunHelpers({
92
+ cliPrefix: ['composio'],
93
+ helperContext: {
94
+ apiKey: 'test-key',
95
+ orgId: 'test-org',
96
+ consumerProjectId: 'test-project',
97
+ consumerUserId: 'test-user',
98
+ },
99
+ });
100
+
101
+ const installedGlobals: unknown = globalThis;
102
+ expect(Predicate.hasProperty(installedGlobals, 'proxy')).toBe(true);
103
+ if (
104
+ !Predicate.hasProperty(installedGlobals, 'proxy') ||
105
+ typeof installedGlobals.proxy !== 'function'
106
+ ) {
107
+ throw new Error('installRunHelpers() did not install proxy().');
108
+ }
109
+
110
+ const proxyFetch = await installedGlobals.proxy('github');
111
+ await expect(proxyFetch('https://api.github.com/user')).rejects.toMatchObject({
112
+ code: 'TS-SDK::BLOCKED_INTERNAL_URL',
113
+ name: 'ComposioBlockedInternalUrlError',
114
+ });
115
+ expect(fetchMock).toHaveBeenCalledTimes(2);
116
+ });
117
+
118
+ it('[Given] a configured proxy prevents pinning [Then] it blocks the binary download', async () => {
119
+ vi.stubEnv('NODE_USE_ENV_PROXY', '1');
120
+ vi.stubEnv('HTTPS_PROXY', 'http://proxy.example:3128');
121
+ vi.stubEnv('NO_PROXY', '');
122
+ const fetchMock = vi
123
+ .fn()
124
+ .mockResolvedValueOnce(
125
+ new Response(JSON.stringify({ session_id: 'session-1' }), {
126
+ status: 200,
127
+ headers: { 'content-type': 'application/json' },
128
+ })
129
+ )
130
+ .mockResolvedValueOnce(
131
+ new Response(
132
+ JSON.stringify({
133
+ binary_data: { url: 'https://1.1.1.1/proxy-response.bin' },
134
+ status: 200,
135
+ }),
136
+ {
137
+ status: 200,
138
+ headers: { 'content-type': 'application/json' },
139
+ }
140
+ )
141
+ )
142
+ .mockResolvedValueOnce(new Response('untrusted proxied response', { status: 200 }));
143
+ vi.stubGlobal('fetch', fetchMock);
144
+
145
+ await installRunHelpers({
146
+ cliPrefix: ['composio'],
147
+ helperContext: {
148
+ apiKey: 'test-key',
149
+ orgId: 'test-org',
150
+ consumerProjectId: 'test-project',
151
+ consumerUserId: 'test-user',
152
+ },
153
+ });
154
+
155
+ const installedGlobals: unknown = globalThis;
156
+ expect(Predicate.hasProperty(installedGlobals, 'proxy')).toBe(true);
157
+ if (
158
+ !Predicate.hasProperty(installedGlobals, 'proxy') ||
159
+ typeof installedGlobals.proxy !== 'function'
160
+ ) {
161
+ throw new Error('installRunHelpers() did not install proxy().');
162
+ }
163
+
164
+ const proxyFetch = await installedGlobals.proxy('github');
165
+ await expect(proxyFetch('https://api.github.com/user')).rejects.toMatchObject({
166
+ code: 'TS-SDK::BLOCKED_INTERNAL_URL',
167
+ name: 'ComposioBlockedInternalUrlError',
168
+ });
169
+ expect(fetchMock).toHaveBeenCalledTimes(2);
170
+ });
171
+
172
it('[Given] normalized false flags [Then] nested CLI children receive false explicitly', async () => {
173
vi.stubEnv('COMPOSIO_RUN_ENV_SENTINEL', 'forwarded');
174
vi.stubEnv('COMPOSIO_PERF_DEBUG', '1');