Skip to content

test: snicallback prioritization issue #54251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions test/parallel/test-https-snicallback-override.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
'use strict';

const common = require('../common');
const { it, describe } = require('node:test');
const assert = require('node:assert');
const tls = require('node:tls');
const https = require('node:https');
const dns = require('node:dns');
const events = require('node:events');

const fixtures = require('../common/fixtures');
const crypto = require('node:crypto');

const root = {
cert: fixtures.readKey('ca5-cert.pem'),
key: fixtures.readKey('ca5-key.pem')
};

const agent1 = {
cert: fixtures.readKey('agent1-cert.pem'),
key: fixtures.readKey('agent1-key.pem')
};

const PORT = 8443;

const sni = {
'ca5.com': {
cert: new crypto.X509Certificate(root.cert),
secureContext: tls.createSecureContext(root)
},
'agent1.com': {
cert: new crypto.X509Certificate(agent1.cert),
context: tls.createSecureContext(agent1),
},
};

const agent = new https.Agent({
lookup: (hostname, options, cb) => {
if (Object.keys(sni).includes(hostname))
hostname = 'localhost';
return dns.lookup(hostname, options, cb);
}
});

function makeRequest(url, expectedCert) {
return new Promise((resolve, reject) => {
https.get(url, { rejectUnauthorized: false, agent }, common.mustCall((response) => {
const actualCert = response.socket.getPeerX509Certificate();

assert.deepStrictEqual(actualCert.subject, expectedCert.subject);

Check failure on line 50 in test/parallel/test-https-snicallback-override.js

View workflow job for this annotation

GitHub Actions / test-linux

--- stdout --- ▶ Regression test for SNICallback / Certification prioritization issue ✖ should use certificates from SNICallback (34.321996ms) AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'C=US\n' + + 'ST=CA\n' + + 'L=SF\n' + + 'O=The Node.js Foundation\n' + + 'OU=Node.js\n' + + 'CN=ca5\n' + + '[email protected]' - 'C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=agent1\[email protected]' at ClientRequest.<anonymous> (/home/runner/work/node/node/test/parallel/test-https-snicallback-override.js:50:14) at ClientRequest.<anonymous> (/home/runner/work/node/node/test/common/index.js:487:15) at Object.onceWrapper (node:events:635:26) at ClientRequest.emit (node:events:520:28) at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:704:27) at HTTPParser.parserOnHeadersComplete (node:_http_common:118:17) at TLSSocket.socketOnData (node:_http_client:546:22) at TLSSocket.emit (node:events:520:28) at addChunk (node:internal/streams/readable:559:12) at readableAddChunkPushByteMode (node:internal/streams/readable:510:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'C=US\nST=CA\nL=SF\nO=The Node.js Foundation\nOU=Node.js\nCN=ca5\[email protected]', expected: 'C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=agent1\[email protected]', operator: 'deepStrictEqual' } ▶ Regression test for SNICallback / Certification prioritization issue (37.210415ms) ::debug::starting to run Regression test for SNICallback / Certification prioritization issue ::debug::starting to run should use certificates from SNICallback ::error title=should use certificates from SNICallback,file=test/parallel/test-https-snicallback-override.js,line=50,col=14::Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected + 'C=US\n' + + 'ST=CA\n' + + 'L=SF\n' + + 'O=The Node.js Foundation\n' + + 'OU=Node.js\n' + + 'CN=ca5\n' + + '[email protected]' - 'C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=agent1\[email protected]' at process.emit (node:events:520:28) { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'C=US\n' + + 'ST=CA\n' + + 'L=SF\n' + + 'O=The Node.js Foundation\n' + + 'OU=Node.js\n' + + 'CN=ca5\n' + + '[email protected]' - 'C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=agent1\[email protected]' at ClientRequest.<anonymous> (/home/runner/work/node/node/test/parallel/test-https-snicallback-override.js:50:14) at ClientRequest.<anonymous> (/home/runner/work/node/node/test/common/index.js:487:15) at Object.onceWrapper (node:events:635:26) at ClientRequest.emit (node:events:520:28) at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:704:27) at HTTPParser.parserOnHeadersComplete (node:_http_common:118:17) at TLSSocket.socketOnData (node:_http_client:546:22) at TLSSocket.emit (node:events:520:28) at addChunk (node:internal/streams/readable:559:12) at readableAddChunkPushByteMode (node:internal/streams/readable:510:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'C=US\nST=CA\nL=SF\nO=The Node.js Foundation\nOU=Node.js\nCN=ca5\[email protected]', expected: 'C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=agent1\[email protected]', operator: 'deepStrictEqual' } } Command: out/Release/node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./tools/github_reporter/index.js --test-reporter-destination=stdout /home/runner/work/node/node/test/parallel/test-https-snicallback-override.js --- TIMEOUT ---

Check failure on line 50 in test/parallel/test-https-snicallback-override.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stdout --- ▶ Regression test for SNICallback / Certification prioritization issue ✖ should use certificates from SNICallback (19.960625ms) AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'C=US\n' + + 'ST=CA\n' + + 'L=SF\n' + + 'O=The Node.js Foundation\n' + + 'OU=Node.js\n' + + 'CN=ca5\n' + + '[email protected]' - 'C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=agent1\[email protected]' at ClientRequest.<anonymous> (/Users/runner/work/node/node/test/parallel/test-https-snicallback-override.js:50:14) at ClientRequest.<anonymous> (/Users/runner/work/node/node/test/common/index.js:487:15) at Object.onceWrapper (node:events:635:26) at ClientRequest.emit (node:events:520:28) at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:704:27) at HTTPParser.parserOnHeadersComplete (node:_http_common:118:17) at TLSSocket.socketOnData (node:_http_client:546:22) at TLSSocket.emit (node:events:520:28) at addChunk (node:internal/streams/readable:559:12) at readableAddChunkPushByteMode (node:internal/streams/readable:510:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'C=US\nST=CA\nL=SF\nO=The Node.js Foundation\nOU=Node.js\nCN=ca5\[email protected]', expected: 'C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=agent1\[email protected]', operator: 'deepStrictEqual' } ▶ Regression test for SNICallback / Certification prioritization issue (21.409166ms) ::debug::starting to run Regression test for SNICallback / Certification prioritization issue ::debug::starting to run should use certificates from SNICallback ::error title=should use certificates from SNICallback,file=test/parallel/test-https-snicallback-override.js,line=50,col=14::Error [ERR_TEST_FAILURE]: Expected values to be strictly deep-equal: + actual - expected + 'C=US\n' + + 'ST=CA\n' + + 'L=SF\n' + + 'O=The Node.js Foundation\n' + + 'OU=Node.js\n' + + 'CN=ca5\n' + + '[email protected]' - 'C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=agent1\[email protected]' at process.emit (node:events:520:28) { code: 'ERR_TEST_FAILURE', failureType: 'uncaughtException', cause: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: + actual - expected + 'C=US\n' + + 'ST=CA\n' + + 'L=SF\n' + + 'O=The Node.js Foundation\n' + + 'OU=Node.js\n' + + 'CN=ca5\n' + + '[email protected]' - 'C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=agent1\[email protected]' at ClientRequest.<anonymous> (/Users/runner/work/node/node/test/parallel/test-https-snicallback-override.js:50:14) at ClientRequest.<anonymous> (/Users/runner/work/node/node/test/common/index.js:487:15) at Object.onceWrapper (node:events:635:26) at ClientRequest.emit (node:events:520:28) at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:704:27) at HTTPParser.parserOnHeadersComplete (node:_http_common:118:17) at TLSSocket.socketOnData (node:_http_client:546:22) at TLSSocket.emit (node:events:520:28) at addChunk (node:internal/streams/readable:559:12) at readableAddChunkPushByteMode (node:internal/streams/readable:510:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: 'C=US\nST=CA\nL=SF\nO=The Node.js Foundation\nOU=Node.js\nCN=ca5\[email protected]', expected: 'C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=agent1\[email protected]', operator: 'deepStrictEqual' } } Command: out/Release/node --test-reporter=spec --test-reporter-destination=stdout --test-reporter=./tools/github_reporter/index.js --test-reporter-destination=stdout /Users/runner/work/node/node/test/parallel/test-https-snicallback-override.js --- TIMEOUT ---

response.on('data', common.mustCall((chunk) => {
assert.strictEqual(chunk.toString(), 'Hello, World!');
resolve();
}));

response.on('error', reject);
})).on('error', reject);
});
}

describe('Regression test for SNICallback / Certification prioritization issue', () => {
it('should use certificates from SNICallback', async (t) => {
let snicbCount = 0;
const server = https.createServer({
cert: root.cert,
key: root.key,
SNICallback: (servername, cb) => {
snicbCount++;
// This returns the secure context generated from the respective certificate
cb(null, sni[servername].context);
}
}, (req, res) => {
res.writeHead(200);
res.end('Hello, World!');
}).on('error', common.mustNotCall);

server.listen(PORT);
await events.once(server, 'listening');

// Assert that raw IP address gets the root cert
await makeRequest(`https://127.0.0.1:${PORT}`, sni['ca5.com'].cert);

for (const [hostname, { cert: expectedCert }] of Object.entries(sni)) {
// Currently, the agent1 request will fail as it receives the root cert (ca5) instead.
await makeRequest(`https://${hostname}:${PORT}`, expectedCert);
}

// SNICallback should only be called for the hostname requests, not the IP one
assert.strictEqual(snicbCount, 2);

server.close();
});
});
Loading