node/test/parallel/test-tls-session-timeout-errors.js
Joyee Cheung f993fca4e4
test: deflake sequential/test-tls-session-timeout
This patch:

- Splits the validation tests into a separate file and keep the
  test focus on functional test of the sessionTimeout option.
- Increase the testing timeout to 5 seconds in case it takes too
  long for the first connection to complete and the session is
  already expired when the second connection is started.
- Use a specific `sessionIdContext` to ensure stable session ID.
- Fix the s_client arguments by specifying CA file and server name.
- Do not use the serialized session ticket for the first connection.
  That was genearted years ago and may not work in different OpenSSL
  versions. Let the first fresh connection generate the ticket.
- Use random port instead of the common port.
- Add a timeout before the second connection to ensure session ticket
  is properly written.
- Log information to faciliate debugging.

PR-URL: https://github.com/nodejs/node/pull/59423
Fixes: https://github.com/nodejs/node/issues/26839
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Stefan Stojanovic <stefan.stojanovic@janeasystems.com>
2025-08-11 17:36:30 +00:00

36 lines
992 B
JavaScript

'use strict';
// This tests validation of sessionTimeout option in TLS server.
const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
}
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();
const assert = require('assert');
const tls = require('tls');
const fixtures = require('../common/fixtures');
const key = fixtures.readKey('rsa_private.pem');
const cert = fixtures.readKey('rsa_cert.crt');
// Node.js should not allow setting negative timeouts since new versions of
// OpenSSL do not handle those as users might expect
for (const sessionTimeout of [-1, -100, -(2 ** 31)]) {
assert.throws(() => {
tls.createServer({
key: key,
cert: cert,
ca: [cert],
sessionTimeout,
maxVersion: 'TLSv1.2',
});
}, {
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "options.sessionTimeout" is out of range. It ' +
`must be >= 0 && <= ${2 ** 31 - 1}. Received ${sessionTimeout}`,
});
}