test: deflake test-tls-passphrase

Move `socket.end()` to client.

Fixes: https://github.com/nodejs/node/issues/28111
Refs: https://github.com/nodejs/node/pull/27569

PR-URL: https://github.com/nodejs/node/pull/29134
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Luigi Pinca 2019-08-15 12:04:42 +02:00 committed by Rich Trott
parent 8d100c21c5
commit a0cc62f345

View File

@ -37,6 +37,10 @@ assert(Buffer.isBuffer(cert));
assert.strictEqual(typeof passKey.toString(), 'string'); assert.strictEqual(typeof passKey.toString(), 'string');
assert.strictEqual(typeof cert.toString(), 'string'); assert.strictEqual(typeof cert.toString(), 'string');
function onSecureConnect() {
return common.mustCall(function() { this.end(); });
}
const server = tls.Server({ const server = tls.Server({
key: passKey, key: passKey,
passphrase: 'password', passphrase: 'password',
@ -44,8 +48,6 @@ const server = tls.Server({
ca: [cert], ca: [cert],
requestCert: true, requestCert: true,
rejectUnauthorized: true rejectUnauthorized: true
}, function(s) {
s.end();
}); });
server.listen(0, common.mustCall(function() { server.listen(0, common.mustCall(function() {
@ -56,14 +58,14 @@ server.listen(0, common.mustCall(function() {
passphrase: 'password', passphrase: 'password',
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
key: rawKey, key: rawKey,
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
@ -71,7 +73,7 @@ server.listen(0, common.mustCall(function() {
passphrase: 'ignored', passphrase: 'ignored',
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
// Buffer[] // Buffer[]
tls.connect({ tls.connect({
@ -80,14 +82,14 @@ server.listen(0, common.mustCall(function() {
passphrase: 'password', passphrase: 'password',
cert: [cert], cert: [cert],
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
key: [rawKey], key: [rawKey],
cert: [cert], cert: [cert],
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
@ -95,7 +97,7 @@ server.listen(0, common.mustCall(function() {
passphrase: 'ignored', passphrase: 'ignored',
cert: [cert], cert: [cert],
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
// string // string
tls.connect({ tls.connect({
@ -104,14 +106,14 @@ server.listen(0, common.mustCall(function() {
passphrase: 'password', passphrase: 'password',
cert: cert.toString(), cert: cert.toString(),
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
key: rawKey.toString(), key: rawKey.toString(),
cert: cert.toString(), cert: cert.toString(),
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
@ -119,7 +121,7 @@ server.listen(0, common.mustCall(function() {
passphrase: 'ignored', passphrase: 'ignored',
cert: cert.toString(), cert: cert.toString(),
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
// String[] // String[]
tls.connect({ tls.connect({
@ -128,14 +130,14 @@ server.listen(0, common.mustCall(function() {
passphrase: 'password', passphrase: 'password',
cert: [cert.toString()], cert: [cert.toString()],
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
key: [rawKey.toString()], key: [rawKey.toString()],
cert: [cert.toString()], cert: [cert.toString()],
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
@ -143,7 +145,7 @@ server.listen(0, common.mustCall(function() {
passphrase: 'ignored', passphrase: 'ignored',
cert: [cert.toString()], cert: [cert.toString()],
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
// Object[] // Object[]
tls.connect({ tls.connect({
@ -151,7 +153,7 @@ server.listen(0, common.mustCall(function() {
key: [{ pem: passKey, passphrase: 'password' }], key: [{ pem: passKey, passphrase: 'password' }],
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
@ -159,7 +161,7 @@ server.listen(0, common.mustCall(function() {
passphrase: 'ignored', passphrase: 'ignored',
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
@ -167,28 +169,28 @@ server.listen(0, common.mustCall(function() {
passphrase: 'password', passphrase: 'password',
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
key: [{ pem: passKey.toString(), passphrase: 'password' }], key: [{ pem: passKey.toString(), passphrase: 'password' }],
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
key: [{ pem: rawKey, passphrase: 'ignored' }], key: [{ pem: rawKey, passphrase: 'ignored' }],
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
key: [{ pem: rawKey.toString(), passphrase: 'ignored' }], key: [{ pem: rawKey.toString(), passphrase: 'ignored' }],
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
@ -196,7 +198,7 @@ server.listen(0, common.mustCall(function() {
passphrase: 'ignored', passphrase: 'ignored',
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
@ -204,21 +206,21 @@ server.listen(0, common.mustCall(function() {
passphrase: 'ignored', passphrase: 'ignored',
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
key: [{ pem: rawKey }], key: [{ pem: rawKey }],
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
tls.connect({ tls.connect({
port: this.address().port, port: this.address().port,
key: [{ pem: rawKey.toString() }], key: [{ pem: rawKey.toString() }],
cert: cert, cert: cert,
rejectUnauthorized: false rejectUnauthorized: false
}, common.mustCall()); }, onSecureConnect());
})).unref(); })).unref();
const errMessagePassword = /bad decrypt/; const errMessagePassword = /bad decrypt/;