|
1 | | -import { generateDockerCompose, subnetsOverlap, writeConfigs, startContainers, stopContainers, cleanup, runAgentCommand, validateIdNotInSystemRange, getSafeHostUid, getSafeHostGid, getRealUserHome, MIN_REGULAR_UID, ACT_PRESET_BASE_IMAGE } from './docker-manager'; |
| 1 | +import { generateDockerCompose, generateMavenSettings, subnetsOverlap, writeConfigs, startContainers, stopContainers, cleanup, runAgentCommand, validateIdNotInSystemRange, getSafeHostUid, getSafeHostGid, getRealUserHome, MIN_REGULAR_UID, ACT_PRESET_BASE_IMAGE } from './docker-manager'; |
2 | 2 | import { WrapperConfig } from './types'; |
3 | 3 | import * as fs from 'fs'; |
4 | 4 | import * as path from 'path'; |
@@ -509,6 +509,41 @@ describe('docker-manager', () => { |
509 | 509 | expect(env.JAVA_TOOL_OPTIONS).toContain('host.docker.internal'); |
510 | 510 | }); |
511 | 511 |
|
| 512 | + it('should not include quotes in JAVA_TOOL_OPTIONS nonProxyHosts value', () => { |
| 513 | + const configWithHostAccess = { ...mockConfig, enableHostAccess: true }; |
| 514 | + const result = generateDockerCompose(configWithHostAccess, mockNetworkConfig); |
| 515 | + const agent = result.services.agent; |
| 516 | + const env = agent.environment as Record<string, string>; |
| 517 | + |
| 518 | + // Verify no embedded quotes in nonProxyHosts value |
| 519 | + // JAVA_TOOL_OPTIONS parsing treats quotes as literal characters, not grouping |
| 520 | + expect(env.JAVA_TOOL_OPTIONS).not.toContain('"localhost'); |
| 521 | + expect(env.JAVA_TOOL_OPTIONS).not.toContain('internal"'); |
| 522 | + expect(env.JAVA_TOOL_OPTIONS).toContain('-Dhttp.nonProxyHosts=localhost|'); |
| 523 | + }); |
| 524 | + |
| 525 | + it('should mount Maven settings.xml for proxy configuration', () => { |
| 526 | + const result = generateDockerCompose(mockConfig, mockNetworkConfig); |
| 527 | + const agent = result.services.agent; |
| 528 | + const volumes = agent.volumes as string[]; |
| 529 | + |
| 530 | + const mavenMount = volumes.find((v: string) => v.includes('maven-settings.xml')); |
| 531 | + expect(mavenMount).toBeDefined(); |
| 532 | + expect(mavenMount).toContain('.m2/settings.xml:ro'); |
| 533 | + }); |
| 534 | + |
| 535 | + it('should mount Maven settings.xml under /host in chroot mode', () => { |
| 536 | + const chrootConfig = { ...mockConfig, enableChroot: true }; |
| 537 | + const result = generateDockerCompose(chrootConfig, mockNetworkConfig); |
| 538 | + const agent = result.services.agent; |
| 539 | + const volumes = agent.volumes as string[]; |
| 540 | + |
| 541 | + const mavenMount = volumes.find((v: string) => v.includes('maven-settings.xml')); |
| 542 | + expect(mavenMount).toBeDefined(); |
| 543 | + expect(mavenMount).toContain('/host'); |
| 544 | + expect(mavenMount).toContain('.m2/settings.xml:ro'); |
| 545 | + }); |
| 546 | + |
512 | 547 | it('should mount required volumes in agent container (default behavior)', () => { |
513 | 548 | const result = generateDockerCompose(mockConfig, mockNetworkConfig); |
514 | 549 | const agent = result.services.agent; |
@@ -1836,4 +1871,32 @@ describe('docker-manager', () => { |
1836 | 1871 | await expect(cleanup(nonExistentDir, false)).resolves.not.toThrow(); |
1837 | 1872 | }); |
1838 | 1873 | }); |
| 1874 | + |
| 1875 | + describe('generateMavenSettings', () => { |
| 1876 | + it('should generate valid Maven settings.xml with proxy configuration', () => { |
| 1877 | + const result = generateMavenSettings('172.30.0.10', 3128); |
| 1878 | + |
| 1879 | + expect(result).toContain('<settings'); |
| 1880 | + expect(result).toContain('<proxies>'); |
| 1881 | + expect(result).toContain('<protocol>http</protocol>'); |
| 1882 | + expect(result).toContain('<protocol>https</protocol>'); |
| 1883 | + expect(result).toContain('<host>172.30.0.10</host>'); |
| 1884 | + expect(result).toContain('<port>3128</port>'); |
| 1885 | + // Should not include nonProxyHosts when not provided |
| 1886 | + expect(result).not.toContain('<nonProxyHosts>'); |
| 1887 | + }); |
| 1888 | + |
| 1889 | + it('should include nonProxyHosts when provided', () => { |
| 1890 | + const result = generateMavenSettings('172.30.0.10', 3128, 'localhost|127.0.0.1|host.docker.internal'); |
| 1891 | + |
| 1892 | + expect(result).toContain('<nonProxyHosts>localhost|127.0.0.1|host.docker.internal</nonProxyHosts>'); |
| 1893 | + }); |
| 1894 | + |
| 1895 | + it('should have both HTTP and HTTPS proxy entries', () => { |
| 1896 | + const result = generateMavenSettings('172.30.0.10', 3128); |
| 1897 | + |
| 1898 | + expect(result).toContain('<id>awf-http</id>'); |
| 1899 | + expect(result).toContain('<id>awf-https</id>'); |
| 1900 | + }); |
| 1901 | + }); |
1839 | 1902 | }); |
0 commit comments