test: add tls clientcertengine tests

This commit is contained in:
Rich Trott 2017-09-22 21:59:16 -07:00
parent de917f8e81
commit 829d8f1cd0
3 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,15 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const tls = require('tls');
{
assert.throws(
() => { tls.createSecureContext({ clientCertEngine: 0 }); },
common.expectsError({ code: 'ERR_INVALID_ARG_TYPE',
message: / Received type number$/ }));
}

View File

@ -0,0 +1,28 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
// Monkey-patch SecureContext
const binding = process.binding('crypto');
const NativeSecureContext = binding.SecureContext;
binding.SecureContext = function() {
const rv = new NativeSecureContext();
rv.setClientCertEngine = undefined;
return rv;
};
const assert = require('assert');
const tls = require('tls');
{
assert.throws(
() => { tls.createSecureContext({ clientCertEngine: 'Cannonmouth' }); },
common.expectsError({
code: 'ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED',
message: 'Custom engines not supported by this OpenSSL'
})
);
}

View File

@ -0,0 +1,15 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const tls = require('tls');
{
const server = tls.createServer();
assert.strictEqual(server.clientCertEngine, undefined);
server.setOptions({ clientCertEngine: 'Cannonmouth' });
assert.strictEqual(server.clientCertEngine, 'Cannonmouth');
}