MM-51535 - Calls: Fix unrestricted redirect from calls widget (#2635)

* add will-redirect handler to prevent unrestricted redirect

* import ordering

* simplify onWillRedirect handler; tests

* Adding punctuation to force tests to run again.
This commit is contained in:
Christopher Poile
2023-03-28 09:53:30 -04:00
committed by GitHub
parent cc706f7a97
commit d18e3e2251
2 changed files with 52 additions and 11 deletions

View File

@@ -454,6 +454,16 @@ describe('main/windows/callsWidgetWindow', () => {
expect(widgetWindow.onPopOutOpen({url: popOutURL})).toHaveProperty('action', 'deny');
});
it('popout redirects are disabled', () => {
const widgetWindow = new CallsWidgetWindow(mainWindow, mainView, widgetConfig);
const ev = {preventDefault: jest.fn()};
const redirectURL = 'http://localhost:8065/login/sso/saml?redirect_to=https://google.com';
widgetWindow.onWillRedirect(ev, redirectURL);
expect(ev.preventDefault).toHaveBeenCalled();
});
it('onPopOutFocus', () => {
baseWindow.webContents = {
...baseWindow.webContents,
@@ -484,7 +494,6 @@ describe('main/windows/callsWidgetWindow', () => {
widgetWindow.onPopOutCreate(popOut);
expect(widgetWindow.popOut).toBe(popOut);
expect(WebContentsEventManager.addWebContentsEventListeners).toHaveBeenCalledWith(popOut.webContents);
widgetWindow.onPopOutFocus();
expect(popOut.focus).toHaveBeenCalled();
@@ -496,6 +505,32 @@ describe('main/windows/callsWidgetWindow', () => {
expect(popOut.restore).toHaveBeenCalled();
});
it('onPopOutCreate', () => {
baseWindow.webContents = {
...baseWindow.webContents,
send: jest.fn(),
};
baseWindow.restore = jest.fn();
const widgetWindow = new CallsWidgetWindow(mainWindow, mainView, widgetConfig);
expect(baseWindow.webContents.setWindowOpenHandler).toHaveBeenCalledWith(widgetWindow.onPopOutOpen);
expect(baseWindow.webContents.on).toHaveBeenCalledWith('did-create-window', widgetWindow.onPopOutCreate);
expect(widgetWindow.popOut).toBeNull();
const popOut = new EventEmitter();
popOut.webContents = {
on: jest.fn(),
id: 'webContentsId',
};
widgetWindow.onPopOutCreate(popOut);
expect(widgetWindow.popOut).toBe(popOut);
expect(WebContentsEventManager.addWebContentsEventListeners).toHaveBeenCalledWith(popOut.webContents);
expect(popOut.webContents.on).toHaveBeenCalledWith('will-redirect', widgetWindow.onWillRedirect);
});
it('getWebContentsId', () => {
baseWindow.webContents = {
...baseWindow.webContents,