Skip to content
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

test: multiple cas works in any order #6606

Closed
wants to merge 1 commit into from
Closed
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
45 changes: 30 additions & 15 deletions test/parallel/test-tls-two-cas-one-string.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const assert = require('assert');
const common = require('../common');
const tls = require('tls');
const fs = require('fs');
Expand All @@ -13,23 +14,37 @@ const cert =
const key =
fs.readFileSync(`${common.fixturesDir}/keys/agent3-key.pem`, 'utf8');

function test(ca, next) {
const server = tls.createServer({ ca, cert, key }, function(conn) {
this.close();
conn.end();
});

server.addContext('agent3', { ca, cert, key });
function test(ca) {
return new Promise(function(resolve, reject) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the switch to promises necessary? I like changes to be as minimal as possible; it makes for easier reviewing and code archeology.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would definitely switch to promises here; since, now there are six tests compared to earlier two.

This approach is already been used in other tests, for e.g., here. If that helps with the review process

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of the switch to Promises either but not sure I can defend the reasoning too much beyond what @bnoordhuis already said.

const server = tls.createServer(function(conn) {
this.close();
conn.end();
});

const host = common.localhostIPv4;
const port = common.PORT;
server.listen(port, host, function() {
tls.connect({ servername: 'agent3', host, port, ca });
});
server.addContext('agent3', { ca, cert, key });

server.once('close', next);
const host = common.localhostIPv4;
const port = common.PORT;
server.listen(port, host, function() {
var socket = tls.connect({ servername: 'agent3', host, port, ca });
var socketError = false;
socket.on('error', (e) => { socketError = e; });
server.once('close',
(e) => {
return socketError ? reject(socketError) : resolve();
});
});
});
}

const array = [ca1, ca2];
const string = ca1 + '\n' + ca2;
test(array, () => test(string, () => {}));
test(ca1 + '\n' + ca2)
.then(test.bind(null, ca2 + '\n' + ca1))
.then(test.bind(null, ca1 + ca2))
.then(test.bind(null, ca2 + ca1))
.then(test.bind(null, [ca1, ca2]))
.then(test.bind(null, [ca2, ca1]));

process.on('unhandledRejection', function(reason) {
assert.fail(null, null, reason);
});