diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 313e0367918..9624301abec 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -378,12 +378,24 @@ void OnClientCertificateSelected( v8::Isolate* isolate, std::shared_ptr delegate, mate::Arguments* args) { - mate::Dictionary cert_data; - if (!args->GetNext(&cert_data)) { + if (args->Length() == 2) { delegate->ContinueWithCertificate(nullptr); return; } + v8::Local val; + args->GetNext(&val); + if (val->IsNull()) { + delegate->ContinueWithCertificate(nullptr); + return; + } + + mate::Dictionary cert_data; + if (!mate::ConvertFromV8(isolate, val, &cert_data)) { + args->ThrowError("Must pass valid certificate object."); + return; + } + std::string data; if (!cert_data.Get("data", &data)) return; diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index e3e1e1d80d0..cf25dde6e55 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -220,6 +220,16 @@ describe('app module', function () { done() }) + ipcRenderer.once('select-client-certificate', function (event, webContentsId, list) { + assert.equal(webContentsId, w.webContents.id) + assert.equal(list.length, 1) + assert.equal(list[0].issuerName, 'Intermediate CA') + assert.equal(list[0].subjectName, 'Client Cert') + assert.equal(list[0].issuer.commonName, 'Intermediate CA') + assert.equal(list[0].subject.commonName, 'Client Cert') + event.sender.send('client-certificate-response', list[0]) + }) + app.importCertificate(options, function (result) { assert(!result) ipcRenderer.sendSync('set-client-certificate-option', false) diff --git a/spec/static/main.js b/spec/static/main.js index c49ce07e876..55d7de814e6 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -11,7 +11,6 @@ const protocol = electron.protocol const v8 = require('v8') const Coverage = require('electabul').Coverage -const assert = require('assert') const fs = require('fs') const path = require('path') const url = require('url') @@ -192,12 +191,10 @@ ipcMain.on('set-client-certificate-option', function (event, skip) { if (skip) { callback() } else { - assert.equal(list.length, 1) - assert.equal(list[0].issuerName, 'Intermediate CA') - assert.equal(list[0].subjectName, 'Client Cert') - assert.equal(list[0].issuer.commonName, 'Intermediate CA') - assert.equal(list[0].subject.commonName, 'Client Cert') - callback(list[0]) + ipcMain.on('client-certificate-response', function (event, certificate) { + callback(certificate) + }) + window.webContents.send('select-client-certificate', webContents.id, list) } }) event.returnValue = 'done'