SymphonyElectron/js/dialogs/showCertError.js
Lynn f97a13c382 add logging and unit tests (#117)
* add logging and unit tests

* fix logging msg spell for notification
2017-05-31 21:39:08 -07:00

48 lines
1.3 KiB
JavaScript

'use strict';
const electron = require('electron');
const log = require('../log.js');
const logLevels = require('../enums/logLevels.js');
let ignoreAllCertErrors = false;
/**
* If certificate error occurs allow user to deny or allow particular certificate
* error. If user selects 'Ignore All', then all subsequent certificate errors
* will ignored during this session.
*
* Note: the dialog is synchronous so further processing is blocked until
* user provides a response.
*/
electron.app.on('certificate-error', function(event, webContents, url, error,
certificate, callback) {
if (ignoreAllCertErrors) {
event.preventDefault();
callback(true);
return;
}
log.send(logLevels.WARNING, 'Certificate error: ' + error + ' for url: ' + url);
const browserWin = electron.BrowserWindow.fromWebContents(webContents);
const buttonId = electron.dialog.showMessageBox(browserWin, {
type: 'warning',
buttons: [ 'Allow', 'Deny', 'Ignore All' ],
defaultId: 1,
cancelId: 1,
noLink: true,
title: 'Certificate Error',
message: 'Certificate Error: ' + error + '\nURL: ' + url,
});
event.preventDefault();
if (buttonId === 2) {
ignoreAllCertErrors = true;
}
callback(buttonId !== 1);
});