Skip to content

Commit

Permalink
RTC-13399 only resolve proxy if passed (finos#1709)
Browse files Browse the repository at this point in the history
* only add proxy arguments if passed to SDA

* tests
  • Loading branch information
swasunb authored and sbenmoussati committed Mar 27, 2023
1 parent d0ad2c3 commit 5a5fb85
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 5 deletions.
49 changes: 48 additions & 1 deletion spec/c9ShellHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', ''],
Expand All @@ -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'));
Expand All @@ -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'));
Expand All @@ -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');
Expand Down
37 changes: 33 additions & 4 deletions src/app/c9-shell-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -126,7 +151,11 @@ class C9ShellHandler {
: [];

customC9ShellArgList.push(
...['--symphonyHost', uniquePipeName, '--proxyServer', proxy],
...[
'--symphonyHost',
uniquePipeName,
...(await this._getCloud9ProxyArgs()),
],
);

logger.info(
Expand Down

0 comments on commit 5a5fb85

Please sign in to comment.