Skip to content

Commit 20489c5

Browse files
add comments and more assertions
1 parent d3af50f commit 20489c5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/parallel/test-https-snicallback-override.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ const sni = {
3737

3838
describe('Regression test for SNICallback / Certification prioritization issue', () => {
3939
it('should use certificates from SNICallback', async (t) => {
40+
let snicbCount = 0;
4041
const server = https.createServer({
4142
cert: root.cert,
4243
key: root.key,
4344
SNICallback: (servername, cb) => {
45+
snicbCount++;
46+
// This returns the secure context generated from the respective certificate
4447
cb(null, sni[servername].context)
4548
}
4649
}, (req, res) => {
@@ -59,11 +62,29 @@ describe('Regression test for SNICallback / Certification prioritization issue',
5962
server.listen(PORT);
6063
await events.once(server, 'listening');
6164

65+
await assert.doesNotReject(() => new Promise((resolve, reject) => {
66+
https.get(`https://127.0.0.1:${PORT}`, { rejectUnauthorized: false, agent }, (response) => {
67+
const actualCert = response.socket.getPeerX509Certificate();
68+
69+
// Assert that raw IP address gets the root cert
70+
assert.deepStrictEqual(actualCert.subject, sni['ca5.com'].cert.subject);
71+
72+
response.on('data', (chunk) => {
73+
assert.strictEqual(chunk.toString(), 'Hello, World!');
74+
resolve();
75+
});
76+
77+
response.on('error', reject);
78+
}).on('error', reject);
79+
}));
80+
6281
for (const [hostname, { cert: expectedCert }] of Object.entries(sni)) {
6382
await assert.doesNotReject(() => new Promise((resolve, reject) => {
6483
https.get(`https://${hostname}:${PORT}`, { rejectUnauthorized: false, agent }, (response) => {
6584
const actualCert = response.socket.getPeerX509Certificate();
6685

86+
// This assertion will fail if the certificate on the response does not match the one that is meant to be associated with the hostname
87+
// Currently, the agent1 request will fail as it receives the root cert (ca5) instead.
6788
assert.deepStrictEqual(actualCert.subject, expectedCert.subject);
6889

6990
response.on('data', (chunk) => {
@@ -76,6 +97,9 @@ describe('Regression test for SNICallback / Certification prioritization issue',
7697
}));
7798
}
7899

100+
// SNICallback should only be called for the hostname requests, not the IP one
101+
assert.strictEqual(snicbCount, 2);
102+
79103
server.close();
80104
});
81105
})

0 commit comments

Comments
 (0)