summaryrefslogtreecommitdiff
path: root/test/parallel/test-tls-client-getephemeralkeyinfo.js
diff options
context:
space:
mode:
authorSam Roberts <vieuxtech@gmail.com>2019-01-08 16:06:43 -0800
committerDaniel Bevenius <daniel.bevenius@gmail.com>2019-01-14 08:01:40 +0100
commit374bddaaa14fd7fc6f12e9e798bfc932cc4c5377 (patch)
tree58f029c8a1571a74b48e84bcdf294777d5fc6a50 /test/parallel/test-tls-client-getephemeralkeyinfo.js
parent5021b259ed2029dd7c84c7c652268dcad13d1183 (diff)
downloadnode-new-374bddaaa14fd7fc6f12e9e798bfc932cc4c5377.tar.gz
test: rework ephemeralkeyinfo to run in parallel
Remove: - use of tls global so tests can run in parallel - test counting in favour of common.mustCall() - limit of only one cipher suite per ephemeral key type tested The last change will allow adding TLS 1.3 cipher suites and testing 'ECDH' key info with them. PR-URL: https://github.com/nodejs/node/pull/25409 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'test/parallel/test-tls-client-getephemeralkeyinfo.js')
-rw-r--r--test/parallel/test-tls-client-getephemeralkeyinfo.js71
1 files changed, 15 insertions, 56 deletions
diff --git a/test/parallel/test-tls-client-getephemeralkeyinfo.js b/test/parallel/test-tls-client-getephemeralkeyinfo.js
index 9432a277ac..a5db18a565 100644
--- a/test/parallel/test-tls-client-getephemeralkeyinfo.js
+++ b/test/parallel/test-tls-client-getephemeralkeyinfo.js
@@ -10,23 +10,12 @@ const tls = require('tls');
const key = fixtures.readKey('agent2-key.pem');
const cert = fixtures.readKey('agent2-cert.pem');
-let ntests = 0;
-let nsuccess = 0;
-
function loadDHParam(n) {
return fixtures.readKey(`dh${n}.pem`);
}
-const cipherlist = {
- 'NOT_PFS': 'AES128-SHA256',
- 'DH': 'DHE-RSA-AES128-GCM-SHA256',
- 'ECDH': 'ECDHE-RSA-AES128-GCM-SHA256'
-};
-
-function test(size, type, name, next) {
- const cipher = type ? cipherlist[type] : cipherlist.NOT_PFS;
-
- if (name) tls.DEFAULT_ECDH_CURVE = name;
+function test(size, type, name, cipher) {
+ assert(cipher);
const options = {
key: key,
@@ -34,66 +23,36 @@ function test(size, type, name, next) {
ciphers: cipher
};
+ if (name) options.ecdhCurve = name;
+
if (type === 'DH') options.dhparam = loadDHParam(size);
- const server = tls.createServer(options, function(conn) {
+ const server = tls.createServer(options, common.mustCall((conn) => {
assert.strictEqual(conn.getEphemeralKeyInfo(), null);
conn.end();
- });
+ }));
- server.on('close', common.mustCall(function(err) {
+ server.on('close', common.mustCall((err) => {
assert.ifError(err);
- if (next) next();
}));
- server.listen(0, '127.0.0.1', common.mustCall(function() {
+ server.listen(0, '127.0.0.1', common.mustCall(() => {
const client = tls.connect({
- port: this.address().port,
+ port: server.address().port,
rejectUnauthorized: false
}, function() {
const ekeyinfo = client.getEphemeralKeyInfo();
assert.strictEqual(ekeyinfo.type, type);
assert.strictEqual(ekeyinfo.size, size);
assert.strictEqual(ekeyinfo.name, name);
- nsuccess++;
server.close();
});
}));
}
-function testNOT_PFS() {
- test(undefined, undefined, undefined, testDHE1024);
- ntests++;
-}
-
-function testDHE1024() {
- test(1024, 'DH', undefined, testDHE2048);
- ntests++;
-}
-
-function testDHE2048() {
- test(2048, 'DH', undefined, testECDHE256);
- ntests++;
-}
-
-function testECDHE256() {
- test(256, 'ECDH', 'prime256v1', testECDHE512);
- ntests++;
-}
-
-function testECDHE512() {
- test(521, 'ECDH', 'secp521r1', testX25519);
- ntests++;
-}
-
-function testX25519() {
- test(253, 'ECDH', 'X25519', null);
- ntests++;
-}
-
-testNOT_PFS();
-
-process.on('exit', function() {
- assert.strictEqual(ntests, nsuccess);
- assert.strictEqual(ntests, 6);
-});
+test(undefined, undefined, undefined, 'AES128-SHA256');
+test(1024, 'DH', undefined, 'DHE-RSA-AES128-GCM-SHA256');
+test(2048, 'DH', undefined, 'DHE-RSA-AES128-GCM-SHA256');
+test(256, 'ECDH', 'prime256v1', 'ECDHE-RSA-AES128-GCM-SHA256');
+test(521, 'ECDH', 'secp521r1', 'ECDHE-RSA-AES128-GCM-SHA256');
+test(253, 'ECDH', 'X25519', 'ECDHE-RSA-AES128-GCM-SHA256');