node/test/parallel/test-tls-env-bad-extra-ca.js
Beth Griggs c879c9a5c6 test: preserve env in test cases
Allows env vars to be passed through to child processes. This is needed
for things like NODE_TEST_DIR or LD_LIBRARY_PATH if testing the shared
library.

PR-URL: https://github.com/nodejs/node/pull/14822
Refs: https://github.com/nodejs/node/pull/13390
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2017-08-16 17:16:27 +02:00

40 lines
1.0 KiB
JavaScript

// Setting NODE_EXTRA_CA_CERTS to non-existent file emits a warning
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const tls = require('tls');
const fork = require('child_process').fork;
if (process.env.CHILD) {
// This will try to load the extra CA certs, and emit a warning when it fails.
return tls.createServer({});
}
const env = Object.assign({}, process.env, {
CHILD: 'yes',
NODE_EXTRA_CA_CERTS: `${common.fixturesDir}/no-such-file-exists`,
});
const opts = {
env: env,
silent: true,
};
let stderr = '';
fork(__filename, opts)
.on('exit', common.mustCall(function(status) {
assert.strictEqual(status, 0, 'client did not succeed in connecting');
}))
.on('close', common.mustCall(function() {
const re = /Warning: Ignoring extra certs from.*no-such-file-exists.* load failed:.*No such file or directory/;
assert(re.test(stderr), stderr);
}))
.stderr.setEncoding('utf8').on('data', function(str) {
stderr += str;
});