diff --git a/src/docker-manager.test.ts b/src/docker-manager.test.ts index 7b1150217..7b05b7467 100644 --- a/src/docker-manager.test.ts +++ b/src/docker-manager.test.ts @@ -1854,6 +1854,57 @@ describe('docker-manager', () => { process.env.SUDO_USER = originalSudoUser; } }); + + it('should include api-proxy in allowed domains when enableApiProxy is true', async () => { + const config: WrapperConfig = { + allowedDomains: ['github.com'], + agentCommand: 'echo test', + logLevel: 'info', + keepContainers: false, + workDir: testDir, + enableApiProxy: true, + openaiApiKey: 'sk-test-key', + }; + + try { + await writeConfigs(config); + } catch { + // May fail after writing configs + } + + // Verify squid.conf includes api-proxy in allowed domains + const squidConfPath = path.join(testDir, 'squid.conf'); + if (fs.existsSync(squidConfPath)) { + const content = fs.readFileSync(squidConfPath, 'utf-8'); + expect(content).toContain('github.com'); + expect(content).toContain('api-proxy'); + } + }); + + it('should not include api-proxy in allowed domains when enableApiProxy is false', async () => { + const config: WrapperConfig = { + allowedDomains: ['github.com'], + agentCommand: 'echo test', + logLevel: 'info', + keepContainers: false, + workDir: testDir, + enableApiProxy: false, + }; + + try { + await writeConfigs(config); + } catch { + // May fail after writing configs + } + + // Verify squid.conf does not include api-proxy when disabled + const squidConfPath = path.join(testDir, 'squid.conf'); + if (fs.existsSync(squidConfPath)) { + const content = fs.readFileSync(squidConfPath, 'utf-8'); + expect(content).toContain('github.com'); + expect(content).not.toContain('api-proxy'); + } + }); }); describe('startContainers', () => { diff --git a/src/docker-manager.ts b/src/docker-manager.ts index ffb3b1100..53aaffc59 100644 --- a/src/docker-manager.ts +++ b/src/docker-manager.ts @@ -1112,8 +1112,13 @@ export async function writeConfigs(config: WrapperConfig): Promise { // Write Squid config // Note: Use container path for SSL database since it's mounted at /var/spool/squid_ssl_db + // When API proxy is enabled, add api-proxy to allowed domains so agent can communicate with it + const domainsForSquid = config.enableApiProxy && networkConfig.proxyIp + ? [...config.allowedDomains, 'api-proxy'] + : config.allowedDomains; + const squidConfig = generateSquidConfig({ - domains: config.allowedDomains, + domains: domainsForSquid, blockedDomains: config.blockedDomains, port: SQUID_PORT, sslBump: config.sslBump,