diff --git a/spec/c9ShellHandler.spec.ts b/spec/c9ShellHandler.spec.ts index 3c27028b..19c1b076 100644 --- a/spec/c9ShellHandler.spec.ts +++ b/spec/c9ShellHandler.spec.ts @@ -112,10 +112,17 @@ describe('C9 shell handler', () => { }); it('args', async () => { + mockGetCommandLineArgs.mockImplementation((_, name) => + name === '--proxy-server=' ? '--proxy-server=512' : null, + ); + webContentsMocked.session.resolveProxy = jest + .fn() + .mockImplementation(() => Promise.resolve('')); mockGetGuid.mockReturnValue('just-another-guid'); - const { loadC9Shell } = require('../src/app/c9-shell-handler'); + await loadC9Shell(webContentsMocked as any); + expect(mockSpawn).toBeCalledWith( expect.stringContaining('c9shell.exe'), ['--symphonyHost', 'just-another-guid', '--proxyServer', ''], @@ -124,6 +131,9 @@ describe('C9 shell handler', () => { }); it('args, when resolveProxy returns DIRECT', async () => { + mockGetCommandLineArgs.mockImplementation((_, name) => + name === '--proxy-server=' ? '--proxy-server=512' : null, + ); webContentsMocked.session.resolveProxy = jest .fn() .mockImplementation(() => Promise.resolve('DIRECT')); @@ -140,6 +150,9 @@ describe('C9 shell handler', () => { }); it('args, when resolveProxy returns string starting with PROXY ', async () => { + mockGetCommandLineArgs.mockImplementation((_, name) => + name === '--proxy-server=' ? '--proxy-server=512' : null, + ); webContentsMocked.session.resolveProxy = jest .fn() .mockImplementation(() => Promise.resolve('PROXY 52.207.140.132:8443')); @@ -160,6 +173,40 @@ describe('C9 shell handler', () => { ); }); + it('args, when --proxy-server= is not passed as argument, do not pass resolved proxy to cloud9', async () => { + mockGetCommandLineArgs.mockReturnValue(''); + webContentsMocked.session.resolveProxy = jest + .fn() + .mockImplementation(() => Promise.resolve('DIRECT')); + mockGetGuid.mockReturnValue('just-another-guid'); + const { loadC9Shell } = require('../src/app/c9-shell-handler'); + + await loadC9Shell(webContentsMocked as any); + + expect(mockSpawn).toBeCalledWith( + expect.stringContaining('c9shell.exe'), + ['--symphonyHost', 'just-another-guid'], + { stdio: 'pipe' }, + ); + }); + + it('args, when --proxy-pac-url= is not passed as argument, do not pass resolved proxy to cloud9', async () => { + mockGetCommandLineArgs.mockReturnValue(''); + webContentsMocked.session.resolveProxy = jest + .fn() + .mockImplementation(() => Promise.resolve('DIRECT')); + mockGetGuid.mockReturnValue('just-another-guid'); + const { loadC9Shell } = require('../src/app/c9-shell-handler'); + + await loadC9Shell(webContentsMocked as any); + + expect(mockSpawn).toBeCalledWith( + expect.stringContaining('c9shell.exe'), + ['--symphonyHost', 'just-another-guid'], + { stdio: 'pipe' }, + ); + }); + it('non-windows', async () => { mockIsWindows = false; const { loadC9Shell } = require('../src/app/c9-shell-handler'); diff --git a/src/app/c9-shell-handler.ts b/src/app/c9-shell-handler.ts index 3a79a624..90073655 100644 --- a/src/app/c9-shell-handler.ts +++ b/src/app/c9-shell-handler.ts @@ -99,15 +99,40 @@ class C9ShellHandler { } } + /** + * only return resolved proxy from Electron, if proxy-server or proxy-pac-url + * was passed as arguments + */ + private async _getCloud9ProxyArgs() { + const hasProxyServerArgs = getCommandLineArgs( + process.argv, + '--proxy-server=', + false, + ); + const hasProxyPacFileArgs = getCommandLineArgs( + process.argv, + '--proxy-pac-url=', + false, + ); + + if (hasProxyPacFileArgs || hasProxyServerArgs) { + const proxy = ( + await this._sender.session.resolveProxy(this._sender.getURL() ?? '') + ) + .split(';')[0] + .replace('PROXY ', ''); + + return ['--proxyServer', proxy]; + } + return []; + } + /** * Launches the correct c9shell process */ private async _launchC9Shell(): Promise { this._curStatus = undefined; const uniquePipeName = getGuid(); - const proxy = ( - await this._sender.session.resolveProxy(this._sender.getURL() ?? '') - ).replace('PROXY ', ''); const c9ShellPath = isDevEnv ? path.join( @@ -126,7 +151,11 @@ class C9ShellHandler { : []; customC9ShellArgList.push( - ...['--symphonyHost', uniquePipeName, '--proxyServer', proxy], + ...[ + '--symphonyHost', + uniquePipeName, + ...(await this._getCloud9ProxyArgs()), + ], ); logger.info(