mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
RTC:13399 Forward proxy returned by electron to Cloud9 shell on launch (#1706)
* forward proxyServer received from session.resolveProxy to Cloud9 app on launch * return proxy as we get it only replacing PROXY
This commit is contained in:
parent
0c594fc46b
commit
5d305e3eea
@ -1,5 +1,11 @@
|
||||
describe('C9 shell handler', () => {
|
||||
const webContentsMocked = { send: jest.fn() };
|
||||
const webContentsMocked = {
|
||||
send: jest.fn(),
|
||||
session: {
|
||||
resolveProxy: jest.fn(),
|
||||
},
|
||||
getURL: jest.fn(),
|
||||
};
|
||||
const mockSpawnEvents = new Map<String, any>();
|
||||
const mockSpawn = jest.fn();
|
||||
const mockGetCommandLineArgs = jest.fn();
|
||||
@ -44,13 +50,16 @@ describe('C9 shell handler', () => {
|
||||
kill: mockKill,
|
||||
};
|
||||
});
|
||||
webContentsMocked.session.resolveProxy = jest
|
||||
.fn()
|
||||
.mockImplementation(() => Promise.resolve(''));
|
||||
mockIsWindows = true;
|
||||
});
|
||||
|
||||
describe('launch', () => {
|
||||
it('success', () => {
|
||||
it('success', async () => {
|
||||
const { loadC9Shell } = require('../src/app/c9-shell-handler');
|
||||
loadC9Shell(webContentsMocked as any);
|
||||
await loadC9Shell(webContentsMocked as any);
|
||||
expect(webContentsMocked.send).lastCalledWith('c9-status-event', {
|
||||
status: { status: 'starting' },
|
||||
});
|
||||
@ -61,9 +70,9 @@ describe('C9 shell handler', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('failure', () => {
|
||||
it('failure', async () => {
|
||||
const { loadC9Shell } = require('../src/app/c9-shell-handler');
|
||||
loadC9Shell(webContentsMocked as any);
|
||||
await loadC9Shell(webContentsMocked as any);
|
||||
expect(webContentsMocked.send).lastCalledWith('c9-status-event', {
|
||||
status: { status: 'starting' },
|
||||
});
|
||||
@ -74,19 +83,19 @@ describe('C9 shell handler', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('with attach', () => {
|
||||
it('with attach', async () => {
|
||||
mockGetCommandLineArgs.mockReturnValue('--c9pipe=custompipe');
|
||||
|
||||
const { loadC9Shell } = require('../src/app/c9-shell-handler');
|
||||
loadC9Shell(webContentsMocked as any);
|
||||
await loadC9Shell(webContentsMocked as any);
|
||||
expect(webContentsMocked.send).lastCalledWith('c9-status-event', {
|
||||
status: { status: 'active', pipeName: 'symphony-c9-custompipe' },
|
||||
});
|
||||
});
|
||||
|
||||
it('cached status on relaunch', () => {
|
||||
it('cached status on relaunch', async () => {
|
||||
const { loadC9Shell } = require('../src/app/c9-shell-handler');
|
||||
loadC9Shell(webContentsMocked as any);
|
||||
await loadC9Shell(webContentsMocked as any);
|
||||
expect(webContentsMocked.send).lastCalledWith('c9-status-event', {
|
||||
status: { status: 'starting' },
|
||||
});
|
||||
@ -102,34 +111,70 @@ describe('C9 shell handler', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('args', () => {
|
||||
it('args', async () => {
|
||||
mockGetGuid.mockReturnValue('just-another-guid');
|
||||
|
||||
const { loadC9Shell } = require('../src/app/c9-shell-handler');
|
||||
loadC9Shell(webContentsMocked as any);
|
||||
await loadC9Shell(webContentsMocked as any);
|
||||
expect(mockSpawn).toBeCalledWith(
|
||||
expect.stringContaining('c9shell.exe'),
|
||||
['--symphonyHost', 'just-another-guid'],
|
||||
['--symphonyHost', 'just-another-guid', '--proxyServer', ''],
|
||||
{ stdio: 'pipe' },
|
||||
);
|
||||
});
|
||||
|
||||
it('non-windows', () => {
|
||||
mockIsWindows = false;
|
||||
|
||||
it('args, when resolveProxy returns DIRECT', async () => {
|
||||
webContentsMocked.session.resolveProxy = jest
|
||||
.fn()
|
||||
.mockImplementation(() => Promise.resolve('DIRECT'));
|
||||
mockGetGuid.mockReturnValue('just-another-guid');
|
||||
const { loadC9Shell } = require('../src/app/c9-shell-handler');
|
||||
loadC9Shell(webContentsMocked as any);
|
||||
|
||||
await loadC9Shell(webContentsMocked as any);
|
||||
|
||||
expect(mockSpawn).toBeCalledWith(
|
||||
expect.stringContaining('c9shell.exe'),
|
||||
['--symphonyHost', 'just-another-guid', '--proxyServer', 'DIRECT'],
|
||||
{ stdio: 'pipe' },
|
||||
);
|
||||
});
|
||||
|
||||
it('args, when resolveProxy returns string starting with PROXY ', async () => {
|
||||
webContentsMocked.session.resolveProxy = jest
|
||||
.fn()
|
||||
.mockImplementation(() => Promise.resolve('PROXY 52.207.140.132:8443'));
|
||||
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',
|
||||
'52.207.140.132:8443',
|
||||
],
|
||||
{ stdio: 'pipe' },
|
||||
);
|
||||
});
|
||||
|
||||
it('non-windows', async () => {
|
||||
mockIsWindows = false;
|
||||
const { loadC9Shell } = require('../src/app/c9-shell-handler');
|
||||
await loadC9Shell(webContentsMocked as any);
|
||||
expect(mockSpawn).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('terminate', () => {
|
||||
it('success', () => {
|
||||
it('success', async () => {
|
||||
const {
|
||||
loadC9Shell,
|
||||
terminateC9Shell,
|
||||
} = require('../src/app/c9-shell-handler');
|
||||
loadC9Shell(webContentsMocked as any);
|
||||
await loadC9Shell(webContentsMocked as any);
|
||||
expect(webContentsMocked.send).lastCalledWith('c9-status-event', {
|
||||
status: { status: 'starting' },
|
||||
});
|
||||
@ -144,12 +189,12 @@ describe('C9 shell handler', () => {
|
||||
expect(mockKill).toBeCalledTimes(0);
|
||||
});
|
||||
|
||||
it('no terminate if already exited', () => {
|
||||
it('no terminate if already exited', async () => {
|
||||
const {
|
||||
loadC9Shell,
|
||||
terminateC9Shell,
|
||||
} = require('../src/app/c9-shell-handler');
|
||||
loadC9Shell(webContentsMocked as any);
|
||||
await loadC9Shell(webContentsMocked as any);
|
||||
expect(webContentsMocked.send).lastCalledWith('c9-status-event', {
|
||||
status: { status: 'starting' },
|
||||
});
|
||||
|
@ -24,13 +24,13 @@ class C9ShellHandler {
|
||||
/**
|
||||
* Starts the c9shell process
|
||||
*/
|
||||
public startShell() {
|
||||
public async startShell(sender: WebContents) {
|
||||
if (this._attachExistingC9Shell()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._c9shell) {
|
||||
this._c9shell = this._launchC9Shell();
|
||||
this._c9shell = await this._launchC9Shell(sender);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,9 +89,14 @@ class C9ShellHandler {
|
||||
/**
|
||||
* Launches the correct c9shell process
|
||||
*/
|
||||
private _launchC9Shell(): ChildProcess | undefined {
|
||||
private async _launchC9Shell(
|
||||
webContents: WebContents,
|
||||
): Promise<ChildProcess | undefined> {
|
||||
this._curStatus = undefined;
|
||||
const uniquePipeName = getGuid();
|
||||
const proxy = (
|
||||
await webContents.session.resolveProxy(webContents.getURL() ?? '')
|
||||
).replace('PROXY ', '');
|
||||
|
||||
const c9ShellPath = isDevEnv
|
||||
? path.join(
|
||||
@ -109,16 +114,20 @@ class C9ShellHandler {
|
||||
? customC9ShellArgs.substring(9).split(' ')
|
||||
: [];
|
||||
|
||||
logger.info('c9-shell: launching shell', c9ShellPath, customC9ShellArgList);
|
||||
customC9ShellArgList.push(
|
||||
...['--symphonyHost', uniquePipeName, '--proxyServer', proxy],
|
||||
);
|
||||
|
||||
logger.info(
|
||||
'c9-shell: launching shell with path',
|
||||
c9ShellPath,
|
||||
customC9ShellArgList,
|
||||
);
|
||||
this._updateStatus({ status: 'starting' });
|
||||
|
||||
const c9Shell = spawn(
|
||||
c9ShellPath,
|
||||
['--symphonyHost', uniquePipeName, ...customC9ShellArgList],
|
||||
{
|
||||
stdio: 'pipe',
|
||||
},
|
||||
);
|
||||
const c9Shell = spawn(c9ShellPath, customC9ShellArgList, {
|
||||
stdio: 'pipe',
|
||||
});
|
||||
c9Shell.on('close', (code) => {
|
||||
logger.info('c9-shell: closed with code', code);
|
||||
this._c9shell = undefined;
|
||||
@ -147,7 +156,7 @@ let c9ShellHandler: C9ShellHandler | undefined;
|
||||
/**
|
||||
* Starts the C9 shell process asynchronously, if not already started.
|
||||
*/
|
||||
export const loadC9Shell = (sender: WebContents) => {
|
||||
export const loadC9Shell = async (sender: WebContents) => {
|
||||
if (!isWindowsOS) {
|
||||
logger.error("c9-shell: can't load shell on non-Windows OS");
|
||||
return;
|
||||
@ -159,7 +168,7 @@ export const loadC9Shell = (sender: WebContents) => {
|
||||
logger.info('c9-shell: sending status', status);
|
||||
sender.send('c9-status-event', { status });
|
||||
});
|
||||
c9ShellHandler.startShell();
|
||||
await c9ShellHandler.startShell(sender);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -423,7 +423,7 @@ ipcMain.on(
|
||||
closeC9Pipe();
|
||||
break;
|
||||
case apiCmds.launchCloud9:
|
||||
loadC9Shell(event.sender);
|
||||
await loadC9Shell(event.sender);
|
||||
break;
|
||||
case apiCmds.terminateCloud9:
|
||||
terminateC9Shell(event.sender);
|
||||
|
Loading…
Reference in New Issue
Block a user