node/test/addons/openssl-client-cert-engine/test.js
Antoine du Hamel 4f20c882ec
test: add trailing commas in addons test (#45548)
PR-URL: https://github.com/nodejs/node/pull/45548
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2022-11-21 18:40:12 +01:00

61 lines
1.6 KiB
JavaScript

'use strict';
const common = require('../../common');
const fixture = require('../../common/fixtures');
if (!common.hasCrypto)
common.skip('missing crypto');
const fs = require('fs');
const path = require('path');
const engine = path.join(__dirname,
`/build/${common.buildType}/testengine.engine`);
if (!fs.existsSync(engine))
common.skip('no client cert engine');
const assert = require('assert');
const https = require('https');
const agentKey = fs.readFileSync(fixture.path('/keys/agent1-key.pem'));
const agentCert = fs.readFileSync(fixture.path('/keys/agent1-cert.pem'));
const agentCa = fs.readFileSync(fixture.path('/keys/ca1-cert.pem'));
const serverOptions = {
key: agentKey,
cert: agentCert,
ca: agentCa,
requestCert: true,
rejectUnauthorized: true,
};
const server = https.createServer(serverOptions, common.mustCall((req, res) => {
res.writeHead(200);
res.end('hello world');
})).listen(0, common.localhostIPv4, common.mustCall(() => {
const clientOptions = {
method: 'GET',
host: common.localhostIPv4,
port: server.address().port,
path: '/test',
clientCertEngine: engine, // `engine` will provide key+cert
rejectUnauthorized: false, // Prevent failing on self-signed certificates
headers: {},
};
const req = https.request(clientOptions, common.mustCall((response) => {
let body = '';
response.setEncoding('utf8');
response.on('data', (chunk) => {
body += chunk;
});
response.on('end', common.mustCall(() => {
assert.strictEqual(body, 'hello world');
server.close();
}));
}));
req.end();
}));