[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 <build@mattermost.com>
This commit is contained in:
Devin Binnie 2023-02-01 14:32:22 -05:00 committed by GitHub
parent d5838a4fa8
commit f62944c5a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View file

@ -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}`);

View file

@ -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: [
{

View file

@ -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;
}