summaryrefslogtreecommitdiff
path: root/test/sequential
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2019-03-22 10:51:27 -0700
committerRich Trott <rtrott@gmail.com>2019-03-22 13:57:24 -0700
commit7d201c4e700ff94f17dab9185c03c44597976e8c (patch)
tree673525df52bbba0aa52dc153785c87802ac38eb1 /test/sequential
parentcc89e68e729e0c96da63764d01ac87e9e5ab1c50 (diff)
downloadandroid-node-v8-7d201c4e700ff94f17dab9185c03c44597976e8c.tar.gz
android-node-v8-7d201c4e700ff94f17dab9185c03c44597976e8c.tar.bz2
android-node-v8-7d201c4e700ff94f17dab9185c03c44597976e8c.zip
test: move pummel tls test to sequential
Move test-tls-session-timeout from pummel to sequential. It isn't very pummel-y and this will result in it being run on our CI more than once a day. (It broke recently and it would have been caught if it was in sequential rather than pummel.) It must be in sequential rather than pummel because it uses `common.PORT` which can result in test failures if more than one test uses it at one time in parallel. PR-URL: https://github.com/nodejs/node/pull/26865 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'test/sequential')
-rw-r--r--test/sequential/test-tls-session-timeout.js134
1 files changed, 134 insertions, 0 deletions
diff --git a/test/sequential/test-tls-session-timeout.js b/test/sequential/test-tls-session-timeout.js
new file mode 100644
index 0000000000..4e430b7135
--- /dev/null
+++ b/test/sequential/test-tls-session-timeout.js
@@ -0,0 +1,134 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+'use strict';
+const common = require('../common');
+
+if (!common.opensslCli)
+ common.skip('node compiled without OpenSSL CLI.');
+
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+
+const tmpdir = require('../common/tmpdir');
+tmpdir.refresh();
+
+doTest();
+
+// This test consists of three TLS requests --
+// * The first one should result in a new connection because we don't have
+// a valid session ticket.
+// * The second one should result in connection resumption because we used
+// the session ticket we saved from the first connection.
+// * The third one should result in a new connection because the ticket
+// that we used has expired by now.
+
+function doTest() {
+ const assert = require('assert');
+ const tls = require('tls');
+ const fs = require('fs');
+ const join = require('path').join;
+ const fixtures = require('../common/fixtures');
+ const spawn = require('child_process').spawn;
+
+ const SESSION_TIMEOUT = 1;
+
+ const key = fixtures.readSync('agent.key');
+ const cert = fixtures.readSync('agent.crt');
+ const options = {
+ key: key,
+ cert: cert,
+ ca: [cert],
+ sessionTimeout: SESSION_TIMEOUT,
+ maxVersion: 'TLSv1.2',
+ };
+
+ // We need to store a sample session ticket in the fixtures directory because
+ // `s_client` behaves incorrectly if we do not pass in both the `-sess_in`
+ // and the `-sess_out` flags, and the `-sess_in` argument must point to a
+ // file containing a proper serialization of a session ticket.
+ // To avoid a source control diff, we copy the ticket to a temporary file.
+
+ const sessionFileName = (function() {
+ const ticketFileName = 'tls-session-ticket.txt';
+ const tmpPath = join(tmpdir.path, ticketFileName);
+ fs.writeFileSync(tmpPath, fixtures.readSync(ticketFileName));
+ return tmpPath;
+ }());
+
+ // Expects a callback -- cb(connectionType : enum ['New'|'Reused'])
+
+ function Client(cb) {
+ const flags = [
+ 's_client',
+ '-connect', `localhost:${common.PORT}`,
+ '-sess_in', sessionFileName,
+ '-sess_out', sessionFileName,
+ ];
+ const client = spawn(common.opensslCli, flags, {
+ stdio: ['ignore', 'pipe', 'ignore']
+ });
+
+ let clientOutput = '';
+ client.stdout.on('data', (data) => {
+ clientOutput += data.toString();
+ });
+ client.on('exit', (code) => {
+ let connectionType;
+ const grepConnectionType = (line) => {
+ const matches = line.match(/(New|Reused), /);
+ if (matches) {
+ connectionType = matches[1];
+ return true;
+ }
+ };
+ const lines = clientOutput.split('\n');
+ if (!lines.some(grepConnectionType)) {
+ throw new Error('unexpected output from openssl client');
+ }
+ assert.strictEqual(code, 0);
+ cb(connectionType);
+ });
+ }
+
+ const server = tls.createServer(options, (cleartext) => {
+ cleartext.on('error', (er) => {
+ if (er.code !== 'ECONNRESET')
+ throw er;
+ });
+ cleartext.end();
+ });
+
+ server.listen(common.PORT, () => {
+ Client((connectionType) => {
+ assert.strictEqual(connectionType, 'New');
+ Client((connectionType) => {
+ assert.strictEqual(connectionType, 'Reused');
+ setTimeout(() => {
+ Client((connectionType) => {
+ assert.strictEqual(connectionType, 'New');
+ server.close();
+ });
+ }, (SESSION_TIMEOUT + 1) * 1000);
+ });
+ });
+ });
+}