From f62944c5a4c92688ca0b5991db7627b825a3f83e Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Wed, 1 Feb 2023 14:32:22 -0500 Subject: [PATCH] [MM-43656] Flush cookies to disk on finishing custom login (#2076) * [MM-43656] Flush cookies to disk on finishing custom login * Fixed a test --------- Co-authored-by: Mattermost Build --- src/main/app/utils.ts | 2 +- src/main/views/webContentEvents.test.js | 5 +++++ src/main/views/webContentEvents.ts | 4 +++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/app/utils.ts b/src/main/app/utils.ts index 22b3723e..514766b0 100644 --- a/src/main/app/utils.ts +++ b/src/main/app/utils.ts @@ -212,7 +212,7 @@ export function resizeScreen(browserWindow: BrowserWindow) { handle(); } -function flushCookiesStore(session: Session) { +export function flushCookiesStore(session: Session) { log.debug('Utils.flushCookiesStore'); session.cookies.flushStore().catch((err) => { log.error(`There was a problem flushing cookies:\n${err}`); diff --git a/src/main/views/webContentEvents.test.js b/src/main/views/webContentEvents.test.js index 7fc2a385..5be66d60 100644 --- a/src/main/views/webContentEvents.test.js +++ b/src/main/views/webContentEvents.test.js @@ -25,6 +25,7 @@ jest.mock('electron', () => ({ setWindowOpenHandler: jest.fn(), }, })), + session: {}, })); jest.mock('../allowProtocolDialog', () => ({})); @@ -57,6 +58,10 @@ jest.mock('common/utils/url', () => ({ isChannelExportUrl: jest.fn(), })); +jest.mock('main/app/utils', () => ({ + flushCookiesStore: jest.fn(), +})); + jest.mock('../../../electron-builder.json', () => ({ protocols: [ { diff --git a/src/main/views/webContentEvents.ts b/src/main/views/webContentEvents.ts index 22ec4cd5..12a96516 100644 --- a/src/main/views/webContentEvents.ts +++ b/src/main/views/webContentEvents.ts @@ -1,7 +1,7 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {BrowserWindow, shell, WebContents} from 'electron'; +import {BrowserWindow, session, shell, WebContents} from 'electron'; import log from 'electron-log'; import {TeamWithTabs} from 'types/config'; @@ -9,6 +9,7 @@ import {TeamWithTabs} from 'types/config'; import Config from 'common/config'; import urlUtils from 'common/utils/url'; +import {flushCookiesStore} from 'main/app/utils'; import ContextMenu from 'main/contextMenu'; import WindowManager from '../windows/windowManager'; @@ -70,6 +71,7 @@ export class WebContentsEventManager { return; } if (this.customLogins[contentID]?.inProgress) { + flushCookiesStore(session.defaultSession); return; }