Skip to content

Commit 944f1a3

Browse files
sam-githubcodebytere
authored andcommitted
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: #31584 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 79a6872 commit 944f1a3

File tree

1 file changed

+16
-43
lines changed

1 file changed

+16
-43
lines changed

‎test/parallel/test-https-simple.js‎

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ const options ={
3737
cert: fixtures.readKey('agent1-cert.pem')
3838
};
3939

40-
consttests=2;
41-
letsuccessful=0;
42-
43-
consttestSucceeded=()=>{
44-
successful=successful+1;
45-
if(successful===tests){
46-
server.close();
47-
}
48-
};
49-
5040
constbody='hello world\n';
5141

5242
constserverCallback=common.mustCall(function(req,res){
@@ -57,61 +47,44 @@ const serverCallback = common.mustCall(function(req, res){
5747
constserver=https.createServer(options,serverCallback);
5848

5949
server.listen(0,common.mustCall(()=>{
50+
lettests=0;
51+
52+
functiondone(){
53+
if(--tests===0)
54+
server.close();
55+
}
56+
6057
// Do a request ignoring the unauthorized server certs
6158
constport=server.address().port;
6259

63-
constnoCertCheckOptions={
60+
constoptions={
6461
hostname: '127.0.0.1',
6562
port: port,
6663
path: '/',
6764
method: 'GET',
6865
rejectUnauthorized: false
6966
};
70-
71-
noCertCheckOptions.Agent=newhttps.Agent(noCertCheckOptions);
72-
73-
constreq=https.request(noCertCheckOptions,common.mustCall((res)=>{
67+
tests++;
68+
constreq=https.request(options,common.mustCall((res)=>{
7469
letresponseBody='';
7570
res.on('data',function(d){
7671
responseBody=responseBody+d;
7772
});
7873

7974
res.on('end',common.mustCall(()=>{
8075
assert.strictEqual(responseBody,body);
81-
testSucceeded();
76+
done();
8277
}));
8378
}));
8479
req.end();
8580

86-
req.on('error',function(e){
87-
throwe;
88-
});
89-
90-
// Do a request that throws error due to the invalid server certs
91-
constcheckCertOptions={
92-
hostname: '127.0.0.1',
93-
port: port,
94-
path: '/',
95-
method: 'GET'
96-
};
97-
98-
constcheckCertReq=https.request(checkCertOptions,function(res){
99-
res.on('data',function(){
100-
thrownewError('data should not be received');
101-
});
102-
103-
res.on('end',function(){
104-
thrownewError('connection should not be established');
105-
});
106-
});
107-
checkCertReq.end();
81+
// Do a request that errors due to the invalid server certs
82+
options.rejectUnauthorized=true;
83+
tests++;
84+
constcheckCertReq=https.request(options,common.mustNotCall()).end();
10885

10986
checkCertReq.on('error',common.mustCall((e)=>{
11087
assert.strictEqual(e.code,'UNABLE_TO_VERIFY_LEAF_SIGNATURE');
111-
testSucceeded();
88+
done();
11289
}));
11390
}));
114-
115-
process.on('exit',function(){
116-
assert.strictEqual(successful,tests);
117-
});

0 commit comments

Comments
(0)