[MM-45031] Don't use infinite background retry logic when the certificate is invalid (#2153)
This commit is contained in:
@@ -97,6 +97,17 @@ describe('main/views/MattermostView', () => {
|
||||
expect(mattermostView.view.webContents.loadURL).toBeCalledWith('http://server-1.com/', expect.any(Object));
|
||||
expect(mattermostView.loadRetry).toBeCalledWith('http://server-1.com/', error);
|
||||
});
|
||||
|
||||
it('should not retry when failing to load due to cert error', async () => {
|
||||
const error = new Error('test');
|
||||
error.code = 'ERR_CERT_ERROR';
|
||||
const promise = Promise.reject(error);
|
||||
mattermostView.view.webContents.loadURL.mockImplementation(() => promise);
|
||||
mattermostView.load('a-bad<url');
|
||||
await expect(promise).rejects.toThrow(error);
|
||||
expect(mattermostView.view.webContents.loadURL).toBeCalledWith('http://server-1.com/', expect.any(Object));
|
||||
expect(mattermostView.loadRetry).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('retry', () => {
|
||||
|
@@ -174,6 +174,13 @@ export class MattermostView extends EventEmitter {
|
||||
log.info(`[${Util.shorten(this.tab.name)}] Loading ${loadURL}`);
|
||||
const loading = this.view.webContents.loadURL(loadURL, {userAgent: composeUserAgent()});
|
||||
loading.then(this.loadSuccess(loadURL)).catch((err) => {
|
||||
if (err.code && err.code.startsWith('ERR_CERT')) {
|
||||
WindowManager.sendToRenderer(LOAD_FAILED, this.tab.name, err.toString(), loadURL.toString());
|
||||
this.emit(LOAD_FAILED, this.tab.name, err.toString(), loadURL.toString());
|
||||
log.info(`[${Util.shorten(this.tab.name)}] Invalid certificate, stop retrying until the user decides what to do: ${err}.`);
|
||||
this.status = Status.ERROR;
|
||||
return;
|
||||
}
|
||||
this.loadRetry(loadURL, err);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user