RTC-13399 only resolve proxy if passed (#1709)

* only add proxy arguments if passed to SDA

* tests
This commit is contained in:
Swapna Sundar Biswal 2023-02-20 14:07:51 +05:30 committed by GitHub
parent 0bc2618ba0
commit 9a0697c094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 81 additions and 5 deletions

View File

@ -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');

View File

@ -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<ChildProcess | undefined> {
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(