mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
test: simplify test-https-simple.js
It had an unused `Agent` option (no such option exists), and some code that common.must(Not)Call makes redundant. PR-URL: https://github.com/nodejs/node/pull/31584 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
99c8c6d80f
commit
dbaa4ca166
@ -37,16 +37,6 @@ const options = {
|
||||
cert: fixtures.readKey('agent1-cert.pem')
|
||||
};
|
||||
|
||||
const tests = 2;
|
||||
let successful = 0;
|
||||
|
||||
const testSucceeded = () => {
|
||||
successful = successful + 1;
|
||||
if (successful === tests) {
|
||||
server.close();
|
||||
}
|
||||
};
|
||||
|
||||
const body = 'hello world\n';
|
||||
|
||||
const serverCallback = common.mustCall(function(req, res) {
|
||||
@ -57,20 +47,25 @@ const serverCallback = common.mustCall(function(req, res) {
|
||||
const server = https.createServer(options, serverCallback);
|
||||
|
||||
server.listen(0, common.mustCall(() => {
|
||||
let tests = 0;
|
||||
|
||||
function done() {
|
||||
if (--tests === 0)
|
||||
server.close();
|
||||
}
|
||||
|
||||
// Do a request ignoring the unauthorized server certs
|
||||
const port = server.address().port;
|
||||
|
||||
const noCertCheckOptions = {
|
||||
const options = {
|
||||
hostname: '127.0.0.1',
|
||||
port: port,
|
||||
path: '/',
|
||||
method: 'GET',
|
||||
rejectUnauthorized: false
|
||||
};
|
||||
|
||||
noCertCheckOptions.Agent = new https.Agent(noCertCheckOptions);
|
||||
|
||||
const req = https.request(noCertCheckOptions, common.mustCall((res) => {
|
||||
tests++;
|
||||
const req = https.request(options, common.mustCall((res) => {
|
||||
let responseBody = '';
|
||||
res.on('data', function(d) {
|
||||
responseBody = responseBody + d;
|
||||
@ -78,40 +73,18 @@ server.listen(0, common.mustCall(() => {
|
||||
|
||||
res.on('end', common.mustCall(() => {
|
||||
assert.strictEqual(responseBody, body);
|
||||
testSucceeded();
|
||||
done();
|
||||
}));
|
||||
}));
|
||||
req.end();
|
||||
|
||||
req.on('error', function(e) {
|
||||
throw e;
|
||||
});
|
||||
|
||||
// Do a request that throws error due to the invalid server certs
|
||||
const checkCertOptions = {
|
||||
hostname: '127.0.0.1',
|
||||
port: port,
|
||||
path: '/',
|
||||
method: 'GET'
|
||||
};
|
||||
|
||||
const checkCertReq = https.request(checkCertOptions, function(res) {
|
||||
res.on('data', function() {
|
||||
throw new Error('data should not be received');
|
||||
});
|
||||
|
||||
res.on('end', function() {
|
||||
throw new Error('connection should not be established');
|
||||
});
|
||||
});
|
||||
checkCertReq.end();
|
||||
// Do a request that errors due to the invalid server certs
|
||||
options.rejectUnauthorized = true;
|
||||
tests++;
|
||||
const checkCertReq = https.request(options, common.mustNotCall()).end();
|
||||
|
||||
checkCertReq.on('error', common.mustCall((e) => {
|
||||
assert.strictEqual(e.code, 'UNABLE_TO_VERIFY_LEAF_SIGNATURE');
|
||||
testSucceeded();
|
||||
done();
|
||||
}));
|
||||
}));
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.strictEqual(successful, tests);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user