From 53f5e524125edca30efeefb5f8c42bea0a803aa7 Mon Sep 17 00:00:00 2001 From: Vse Mozhet Byt Date: Fri, 30 Jun 2017 20:52:53 +0300 Subject: [PATCH] test: fix require nits in some test-tls-* tests * Do not require if test is skipped. * Do not re-require without need. * Sort requiring by module names. PR-URL: https://github.com/nodejs/node/pull/14008 Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig --- test/internet/test-tls-add-ca-cert.js | 3 +- test/parallel/test-tls-alert-handling.js | 7 +++-- test/parallel/test-tls-alert.js | 9 +++--- test/parallel/test-tls-alpn-server-client.js | 3 +- test/parallel/test-tls-client-verify.js | 7 +++-- test/parallel/test-tls-cnnic-whitelist.js | 2 +- test/parallel/test-tls-npn-server-client.js | 9 +++--- test/parallel/test-tls-server-verify.js | 28 +++++++++---------- test/parallel/test-tls-sni-option.js | 8 ++++-- test/parallel/test-tls-sni-server-client.js | 8 ++++-- .../test-tls-startcom-wosign-whitelist.js | 5 ++-- 11 files changed, 50 insertions(+), 39 deletions(-) diff --git a/test/internet/test-tls-add-ca-cert.js b/test/internet/test-tls-add-ca-cert.js index 440d4b9a1afb1b..f57f1617ef83d9 100644 --- a/test/internet/test-tls-add-ca-cert.js +++ b/test/internet/test-tls-add-ca-cert.js @@ -10,10 +10,11 @@ if (!common.hasCrypto) { const assert = require('assert'); const fs = require('fs'); +const path = require('path'); const tls = require('tls'); function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', `${n}.pem`); + return path.join(common.fixturesDir, 'keys', `${n}.pem`); } function loadPEM(n) { diff --git a/test/parallel/test-tls-alert-handling.js b/test/parallel/test-tls-alert-handling.js index 5268f520f13958..d089ad223b1fd8 100644 --- a/test/parallel/test-tls-alert-handling.js +++ b/test/parallel/test-tls-alert-handling.js @@ -11,12 +11,13 @@ if (!common.hasCrypto) { return; } -const tls = require('tls'); -const net = require('net'); const fs = require('fs'); +const net = require('net'); +const path = require('path'); +const tls = require('tls'); function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', `${n}.pem`); + return path.join(common.fixturesDir, 'keys', `${n}.pem`); } function loadPEM(n) { diff --git a/test/parallel/test-tls-alert.js b/test/parallel/test-tls-alert.js index 4b9fba55a27efc..2b762b6cc48fc7 100644 --- a/test/parallel/test-tls-alert.js +++ b/test/parallel/test-tls-alert.js @@ -1,6 +1,5 @@ 'use strict'; const common = require('../common'); -const assert = require('assert'); if (!common.opensslCli) { common.skip('node compiled without OpenSSL CLI.'); @@ -11,15 +10,17 @@ if (!common.hasCrypto) { common.skip('missing crypto'); return; } -const tls = require('tls'); +const assert = require('assert'); +const { spawn } = require('child_process'); const fs = require('fs'); -const spawn = require('child_process').spawn; +const path = require('path'); +const tls = require('tls'); let success = false; function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', `${n}.pem`); + return path.join(common.fixturesDir, 'keys', `${n}.pem`); } function loadPEM(n) { diff --git a/test/parallel/test-tls-alpn-server-client.js b/test/parallel/test-tls-alpn-server-client.js index a397550d96863a..3d3453d32fdb82 100644 --- a/test/parallel/test-tls-alpn-server-client.js +++ b/test/parallel/test-tls-alpn-server-client.js @@ -14,10 +14,11 @@ if (!process.features.tls_alpn || !process.features.tls_npn) { const assert = require('assert'); const fs = require('fs'); +const path = require('path'); const tls = require('tls'); function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', `${n}.pem`); + return path.join(common.fixturesDir, 'keys', `${n}.pem`); } function loadPEM(n) { diff --git a/test/parallel/test-tls-client-verify.js b/test/parallel/test-tls-client-verify.js index 453e4f71493cf8..d10c0e16c548fe 100644 --- a/test/parallel/test-tls-client-verify.js +++ b/test/parallel/test-tls-client-verify.js @@ -1,14 +1,15 @@ 'use strict'; const common = require('../common'); -const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -const tls = require('tls'); +const assert = require('assert'); const fs = require('fs'); +const path = require('path'); +const tls = require('tls'); const hosterr = /Hostname\/IP doesn't match certificate's altnames/; const testCases = @@ -44,7 +45,7 @@ const testCases = ]; function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', `${n}.pem`); + return path.join(common.fixturesDir, 'keys', `${n}.pem`); } diff --git a/test/parallel/test-tls-cnnic-whitelist.js b/test/parallel/test-tls-cnnic-whitelist.js index a33e631ddf7437..084531748656e2 100644 --- a/test/parallel/test-tls-cnnic-whitelist.js +++ b/test/parallel/test-tls-cnnic-whitelist.js @@ -8,9 +8,9 @@ if (!common.hasCrypto) { } const assert = require('assert'); -const tls = require('tls'); const fs = require('fs'); const path = require('path'); +const tls = require('tls'); function filenamePEM(n) { return path.join(common.fixturesDir, 'keys', `${n}.pem`); diff --git a/test/parallel/test-tls-npn-server-client.js b/test/parallel/test-tls-npn-server-client.js index cdaeb7cf4ccb33..44e9b86ad71bdc 100644 --- a/test/parallel/test-tls-npn-server-client.js +++ b/test/parallel/test-tls-npn-server-client.js @@ -5,18 +5,19 @@ if (!process.features.tls_npn) { } const common = require('../common'); -const assert = require('assert'); -const fs = require('fs'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -const tls = require('tls'); +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const tls = require('tls'); function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', `${n}.pem`); + return path.join(common.fixturesDir, 'keys', `${n}.pem`); } function loadPEM(n) { diff --git a/test/parallel/test-tls-server-verify.js b/test/parallel/test-tls-server-verify.js index fd816ce0f9b294..2ecc3cc5a015d2 100644 --- a/test/parallel/test-tls-server-verify.js +++ b/test/parallel/test-tls-server-verify.js @@ -6,6 +6,11 @@ if (!common.opensslCli) { return; } +if (!common.hasCrypto) { + common.skip('missing crypto'); + return; +} + // This is a rather complex test which sets up various TLS servers with node // and connects to them using the 'openssl s_client' command line utility // with various keys. Depending on the certificate authority and other @@ -14,6 +19,14 @@ if (!common.opensslCli) { // - accepted and "unauthorized", or // - accepted and "authorized". +const assert = require('assert'); +const { spawn } = require('child_process'); +const { SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION } = + require('crypto').constants; +const fs = require('fs'); +const path = require('path'); +const tls = require('tls'); + const testCases = [{ title: 'Do not request certs. Everyone is unauthorized.', requestCert: false, @@ -98,22 +111,9 @@ const testCases = } ]; -if (!common.hasCrypto) { - common.skip('missing crypto'); - return; -} -const tls = require('tls'); - -const SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION = - require('crypto').constants.SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION; - -const assert = require('assert'); -const fs = require('fs'); -const spawn = require('child_process').spawn; - function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', `${n}.pem`); + return path.join(common.fixturesDir, 'keys', `${n}.pem`); } diff --git a/test/parallel/test-tls-sni-option.js b/test/parallel/test-tls-sni-option.js index 632419701004a6..ba9acbf528c8f4 100644 --- a/test/parallel/test-tls-sni-option.js +++ b/test/parallel/test-tls-sni-option.js @@ -5,17 +5,19 @@ if (!process.features.tls_sni) { } const common = require('../common'); -const assert = require('assert'); -const fs = require('fs'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } + +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); const tls = require('tls'); function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', `${n}.pem`); + return path.join(common.fixturesDir, 'keys', `${n}.pem`); } function loadPEM(n) { diff --git a/test/parallel/test-tls-sni-server-client.js b/test/parallel/test-tls-sni-server-client.js index a8c52ef5668184..e47781a972f87d 100644 --- a/test/parallel/test-tls-sni-server-client.js +++ b/test/parallel/test-tls-sni-server-client.js @@ -5,17 +5,19 @@ if (!process.features.tls_sni) { } const common = require('../common'); -const assert = require('assert'); -const fs = require('fs'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } + +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); const tls = require('tls'); function filenamePEM(n) { - return require('path').join(common.fixturesDir, 'keys', `${n}.pem`); + return path.join(common.fixturesDir, 'keys', `${n}.pem`); } function loadPEM(n) { diff --git a/test/parallel/test-tls-startcom-wosign-whitelist.js b/test/parallel/test-tls-startcom-wosign-whitelist.js index 21dbb55c156e8e..601c0e4393c2eb 100644 --- a/test/parallel/test-tls-startcom-wosign-whitelist.js +++ b/test/parallel/test-tls-startcom-wosign-whitelist.js @@ -1,15 +1,16 @@ 'use strict'; const common = require('../common'); -const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -const tls = require('tls'); +const assert = require('assert'); const fs = require('fs'); const path = require('path'); +const tls = require('tls'); + let finished = 0; function filenamePEM(n) {