From d55fbafd459d9976024ce264582203917542da72 Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sat, 1 Aug 2026 09:02:34 +0200 Subject: [PATCH] test: fix lint in dtls tests a7d16a8cc6e introduced destructured uses of assert and fixtures, which the test lint rules forbid, plus bare strictEqual/throws calls that were never imported and threw ReferenceError at runtime. Use the assert and fixtures namespaces directly. Signed-off-by: Matteo Collina --- test/parallel/test-dtls-accessors.mjs | 69 +++++++++---------- test/parallel/test-dtls-alpn.mjs | 4 +- test/parallel/test-dtls-ciphers.mjs | 17 ++--- test/parallel/test-dtls-client-cert.mjs | 15 ++-- .../test-dtls-connect-error-cleanup.mjs | 11 ++- .../test-dtls-destroy-in-callback.mjs | 8 +-- test/parallel/test-dtls-errors.mjs | 17 ++--- test/parallel/test-dtls-keylog.mjs | 13 ++-- test/parallel/test-dtls-mtu.mjs | 17 ++--- test/parallel/test-dtls-options.mjs | 6 +- .../test-dtls-reject-unauthorized.mjs | 11 ++- test/parallel/test-dtls-robustness.mjs | 8 +-- test/parallel/test-dtls-send.mjs | 17 ++--- .../test-dtls-session-table-cleanup.mjs | 17 ++--- test/parallel/test-dtls-srtp.mjs | 21 +++--- .../test-dtls-unhandled-rejection.mjs | 8 +-- test/parallel/test-dtls-verify-identity.mjs | 15 ++-- 17 files changed, 116 insertions(+), 158 deletions(-) diff --git a/test/parallel/test-dtls-accessors.mjs b/test/parallel/test-dtls-accessors.mjs index 41c7ca7b2382..bb93eeaebe6e 100644 --- a/test/parallel/test-dtls-accessors.mjs +++ b/test/parallel/test-dtls-accessors.mjs @@ -9,9 +9,6 @@ import { import assert from 'node:assert'; import * as fixtures from '../common/fixtures.mjs'; -const { strictEqual } = assert; -const { readKey } = fixtures; - if (!hasCrypto) { skip('missing crypto'); } @@ -22,9 +19,9 @@ if (!process.features.dtls) { const { listen, connect } = await import('node:dtls'); -const cert = readKey('agent1-cert.pem').toString(); -const key = readKey('agent1-key.pem').toString(); -const ca = readKey('ca1-cert.pem').toString(); +const cert = fixtures.readKey('agent1-cert.pem').toString(); +const key = fixtures.readKey('agent1-key.pem').toString(); +const ca = fixtures.readKey('ca1-cert.pem').toString(); const gotServerSession = Promise.withResolvers(); @@ -34,26 +31,26 @@ const server = listen(mustCall((session) => { // --- Endpoint state after listen(): bound and listening. --- const es = server.state; -strictEqual(es.bound, true); -strictEqual(es.listening, true); -strictEqual(es.closing, false); -strictEqual(es.destroyed, false); -strictEqual(es.sessionCount, 0); +assert.strictEqual(es.bound, true); +assert.strictEqual(es.listening, true); +assert.strictEqual(es.closing, false); +assert.strictEqual(es.destroyed, false); +assert.strictEqual(es.sessionCount, 0); // The busy property is settable via the endpoint and reflected in the state view. -strictEqual(server.busy, false); -strictEqual(es.busy, false); +assert.strictEqual(server.busy, false); +assert.strictEqual(es.busy, false); server.busy = true; -strictEqual(server.busy, true); -strictEqual(es.busy, true); +assert.strictEqual(server.busy, true); +assert.strictEqual(es.busy, true); server.busy = false; -strictEqual(es.busy, false); +assert.strictEqual(es.busy, false); // --- Endpoint onerror accessor. --- -strictEqual(server.onerror, undefined); +assert.strictEqual(server.onerror, undefined); const onEndpointError = mustNotCall(); server.onerror = onEndpointError; -strictEqual(server.onerror, onEndpointError); +assert.strictEqual(server.onerror, onEndpointError); const client = connect('127.0.0.1', server.address.port, { ca: [ca], @@ -62,43 +59,43 @@ const client = connect('127.0.0.1', server.address.port, { // --- Session state during the handshake. --- const cs = client.state; -strictEqual(cs.handshaking, true); -strictEqual(cs.open, false); -strictEqual(cs.closing, false); -strictEqual(cs.destroyed, false); -strictEqual(cs.hasMessageListener, false); +assert.strictEqual(cs.handshaking, true); +assert.strictEqual(cs.open, false); +assert.strictEqual(cs.closing, false); +assert.strictEqual(cs.destroyed, false); +assert.strictEqual(cs.hasMessageListener, false); // --- Session callback accessors: unset, then set. --- -strictEqual(client.onmessage, undefined); -strictEqual(client.onerror, undefined); -strictEqual(client.onhandshake, undefined); -strictEqual(client.onkeylog, undefined); +assert.strictEqual(client.onmessage, undefined); +assert.strictEqual(client.onerror, undefined); +assert.strictEqual(client.onhandshake, undefined); +assert.strictEqual(client.onkeylog, undefined); // A connect() session owns its internal endpoint. -strictEqual(client.ownsEndpoint, true); +assert.strictEqual(client.ownsEndpoint, true); client.onmessage = mustNotCall(); -strictEqual(typeof client.onmessage, 'function'); +assert.strictEqual(typeof client.onmessage, 'function'); // Attaching a message listener flips the shared flag. -strictEqual(cs.hasMessageListener, true); +assert.strictEqual(cs.hasMessageListener, true); client.onerror = mustNotCall(); -strictEqual(typeof client.onerror, 'function'); +assert.strictEqual(typeof client.onerror, 'function'); client.onhandshake = mustCall(); -strictEqual(typeof client.onhandshake, 'function'); +assert.strictEqual(typeof client.onhandshake, 'function'); client.onkeylog = mustCallAtLeast(); -strictEqual(typeof client.onkeylog, 'function'); +assert.strictEqual(typeof client.onkeylog, 'function'); await client.opened; // --- Session state after the handshake completes. --- -strictEqual(cs.handshaking, false); -strictEqual(cs.open, true); +assert.strictEqual(cs.handshaking, false); +assert.strictEqual(cs.open, true); const serverSession = await gotServerSession.promise; await serverSession.opened; -strictEqual(es.sessionCount, 1); +assert.strictEqual(es.sessionCount, 1); await client.close(); await server.close(); diff --git a/test/parallel/test-dtls-alpn.mjs b/test/parallel/test-dtls-alpn.mjs index 420cc3331b62..01054dd6432b 100644 --- a/test/parallel/test-dtls-alpn.mjs +++ b/test/parallel/test-dtls-alpn.mjs @@ -74,8 +74,8 @@ await endpoint.close(); const serverSession = await gotServerSession.promise; await serverSession.opened; - strictEqual(client.alpnProtocol, undefined); - strictEqual(serverSession.alpnProtocol, undefined); + assert.strictEqual(client.alpnProtocol, undefined); + assert.strictEqual(serverSession.alpnProtocol, undefined); await client.close(); await server.close(); diff --git a/test/parallel/test-dtls-ciphers.mjs b/test/parallel/test-dtls-ciphers.mjs index e58a1443c9c7..074c33f64b9b 100644 --- a/test/parallel/test-dtls-ciphers.mjs +++ b/test/parallel/test-dtls-ciphers.mjs @@ -6,9 +6,6 @@ import { hasCrypto, skip, mustCall, mustNotCall } from '../common/index.mjs'; import assert from 'node:assert'; import * as fixtures from '../common/fixtures.mjs'; -const { strictEqual, throws } = assert; -const { readKey } = fixtures; - if (!hasCrypto) { skip('missing crypto'); } @@ -19,9 +16,9 @@ if (!process.features.dtls) { const { listen, connect } = await import('node:dtls'); -const cert = readKey('agent1-cert.pem').toString(); -const key = readKey('agent1-key.pem').toString(); -const ca = readKey('ca1-cert.pem').toString(); +const cert = fixtures.readKey('agent1-cert.pem').toString(); +const key = fixtures.readKey('agent1-key.pem').toString(); +const ca = fixtures.readKey('ca1-cert.pem').toString(); const CIPHER = 'ECDHE-RSA-AES128-GCM-SHA256'; @@ -43,15 +40,15 @@ const CIPHER = 'ECDHE-RSA-AES128-GCM-SHA256'; const serverSession = await gotServerSession.promise; await serverSession.opened; - strictEqual(client.cipher.name, CIPHER); - strictEqual(serverSession.cipher.name, CIPHER); + assert.strictEqual(client.cipher.name, CIPHER); + assert.strictEqual(serverSession.cipher.name, CIPHER); await client.close(); await server.close(); } // Case 2: an invalid cipher list is rejected. -throws(() => listen(mustNotCall(), { +assert.throws(() => listen(mustNotCall(), { cert, key, port: 0, host: '127.0.0.1', ciphers: 'THIS-IS-NOT-A-CIPHER', }), { code: 'ERR_CRYPTO_OPERATION_FAILED' }); @@ -74,6 +71,6 @@ throws(() => listen(mustNotCall(), { } // Case 4: an invalid ECDH curve is rejected. -throws(() => listen(mustNotCall(), { +assert.throws(() => listen(mustNotCall(), { cert, key, port: 0, host: '127.0.0.1', ecdhCurve: 'not-a-curve', }), { code: 'ERR_CRYPTO_OPERATION_FAILED' }); diff --git a/test/parallel/test-dtls-client-cert.mjs b/test/parallel/test-dtls-client-cert.mjs index 2505eb6ff7c2..271bd7e322ab 100644 --- a/test/parallel/test-dtls-client-cert.mjs +++ b/test/parallel/test-dtls-client-cert.mjs @@ -7,9 +7,6 @@ import { hasCrypto, skip, mustCall } from '../common/index.mjs'; import assert from 'node:assert'; import * as fixtures from '../common/fixtures.mjs'; -const { ok, rejects } = assert; -const { readKey } = fixtures; - if (!hasCrypto) { skip('missing crypto'); } @@ -20,9 +17,9 @@ if (!process.features.dtls) { const { listen, connect } = await import('node:dtls'); -const cert = readKey('agent1-cert.pem').toString(); -const key = readKey('agent1-key.pem').toString(); -const ca = readKey('ca1-cert.pem').toString(); +const cert = fixtures.readKey('agent1-cert.pem').toString(); +const key = fixtures.readKey('agent1-key.pem').toString(); +const ca = fixtures.readKey('ca1-cert.pem').toString(); // Case 1: the client presents a certificate the server can verify. { @@ -44,8 +41,8 @@ const ca = readKey('ca1-cert.pem').toString(); // The server received and verified the client's certificate. const clientCert = serverSession.peerCertificate; - ok(clientCert); - ok(clientCert.includes('BEGIN CERTIFICATE')); + assert.ok(clientCert); + assert.ok(clientCert.includes('BEGIN CERTIFICATE')); await client.close(); await server.close(); @@ -63,7 +60,7 @@ const ca = readKey('ca1-cert.pem').toString(); }); // The exact alert text varies, so assert only that the handshake is rejected. - await rejects(client.opened, { + await assert.rejects(client.opened, { message: /handshake failure/ }); diff --git a/test/parallel/test-dtls-connect-error-cleanup.mjs b/test/parallel/test-dtls-connect-error-cleanup.mjs index 049c24879007..13dcf8da26bc 100644 --- a/test/parallel/test-dtls-connect-error-cleanup.mjs +++ b/test/parallel/test-dtls-connect-error-cleanup.mjs @@ -8,9 +8,6 @@ import { hasCrypto, skip, mustCall } from '../common/index.mjs'; import assert from 'node:assert'; import * as fixtures from '../common/fixtures.mjs'; -const { rejects } = assert; -const { readKey } = fixtures; - if (!hasCrypto) { skip('missing crypto'); } @@ -21,9 +18,9 @@ if (!process.features.dtls) { const { listen, connect } = await import('node:dtls'); -const cert = readKey('agent1-cert.pem').toString(); -const key = readKey('agent1-key.pem').toString(); -const ca = readKey('ca1-cert.pem').toString(); +const cert = fixtures.readKey('agent1-cert.pem').toString(); +const key = fixtures.readKey('agent1-key.pem').toString(); +const ca = fixtures.readKey('ca1-cert.pem').toString(); // The client rejects the certificate mid-handshake, so this server session // never opens; its opened rejection is handled internally by the library. @@ -37,7 +34,7 @@ const session = connect('127.0.0.1', server.address.port, { servername: 'wrong.example.com', }); -await rejects(session.opened, /certificate verify failed/i); +await assert.rejects(session.opened, /certificate verify failed/i); // The failed connect must have closed its internally-owned endpoint. Without // that, this await never settles and the test times out. diff --git a/test/parallel/test-dtls-destroy-in-callback.mjs b/test/parallel/test-dtls-destroy-in-callback.mjs index 97344bb70719..7915742ca01d 100644 --- a/test/parallel/test-dtls-destroy-in-callback.mjs +++ b/test/parallel/test-dtls-destroy-in-callback.mjs @@ -9,8 +9,6 @@ import { hasCrypto, skip, mustCall } from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; -const { readKey } = fixtures; - if (!hasCrypto) { skip('missing crypto'); } @@ -21,9 +19,9 @@ if (!process.features.dtls) { const { listen, connect } = await import('node:dtls'); -const cert = readKey('agent1-cert.pem').toString(); -const key = readKey('agent1-key.pem').toString(); -const ca = readKey('ca1-cert.pem').toString(); +const cert = fixtures.readKey('agent1-cert.pem').toString(); +const key = fixtures.readKey('agent1-key.pem').toString(); +const ca = fixtures.readKey('ca1-cert.pem').toString(); // --------------------------------------------------------------------------- // Case 1: destroy the (server) session from inside onmessage. The datagram diff --git a/test/parallel/test-dtls-errors.mjs b/test/parallel/test-dtls-errors.mjs index e17497fcac6c..e65c90abd4e0 100644 --- a/test/parallel/test-dtls-errors.mjs +++ b/test/parallel/test-dtls-errors.mjs @@ -7,9 +7,6 @@ import { hasCrypto, skip, mustNotCall } from '../common/index.mjs'; import assert from 'node:assert'; import * as fixtures from '../common/fixtures.mjs'; -const { throws } = assert; -const { readKey } = fixtures; - if (!hasCrypto) { skip('missing crypto'); } @@ -20,22 +17,22 @@ if (!process.features.dtls) { const { listen, DTLSEndpoint } = await import('node:dtls'); -const cert = readKey('agent1-cert.pem').toString(); -const key = readKey('agent1-key.pem').toString(); -const mismatchedKey = readKey('agent2-key.pem').toString(); +const cert = fixtures.readKey('agent1-cert.pem').toString(); +const key = fixtures.readKey('agent1-key.pem').toString(); +const mismatchedKey = fixtures.readKey('agent2-key.pem').toString(); // A malformed certificate PEM is rejected. -throws(() => listen(mustNotCall(), { +assert.throws(() => listen(mustNotCall(), { cert: 'not a certificate', key, port: 0, }), { code: 'ERR_CRYPTO_OPERATION_FAILED' }); // A malformed private key PEM is rejected. -throws(() => listen(mustNotCall(), { +assert.throws(() => listen(mustNotCall(), { cert, key: 'not a key', port: 0, }), { code: 'ERR_CRYPTO_OPERATION_FAILED' }); // A private key that does not match the certificate is rejected. -throws(() => listen(mustNotCall(), { +assert.throws(() => listen(mustNotCall(), { cert, key: mismatchedKey, port: 0, }), { code: 'ERR_CRYPTO_OPERATION_FAILED' }); @@ -43,6 +40,6 @@ throws(() => listen(mustNotCall(), { { const endpoint = new DTLSEndpoint(); endpoint.bind('127.0.0.1', 0); - throws(() => endpoint.bind('127.0.0.1', 0), { code: 'ERR_INVALID_STATE' }); + assert.throws(() => endpoint.bind('127.0.0.1', 0), { code: 'ERR_INVALID_STATE' }); await endpoint.close(); } diff --git a/test/parallel/test-dtls-keylog.mjs b/test/parallel/test-dtls-keylog.mjs index 49d70a4566f5..f32c1142b4c6 100644 --- a/test/parallel/test-dtls-keylog.mjs +++ b/test/parallel/test-dtls-keylog.mjs @@ -7,9 +7,6 @@ import { hasCrypto, skip, mustCall, mustCallAtLeast } from '../common/index.mjs' import assert from 'node:assert'; import * as fixtures from '../common/fixtures.mjs'; -const { strictEqual, match } = assert; -const { readKey } = fixtures; - if (!hasCrypto) { skip('missing crypto'); } @@ -20,9 +17,9 @@ if (!process.features.dtls) { const { listen, connect } = await import('node:dtls'); -const cert = readKey('agent1-cert.pem').toString(); -const key = readKey('agent1-key.pem').toString(); -const ca = readKey('ca1-cert.pem').toString(); +const cert = fixtures.readKey('agent1-cert.pem').toString(); +const key = fixtures.readKey('agent1-key.pem').toString(); +const ca = fixtures.readKey('ca1-cert.pem').toString(); const gotKeylog = Promise.withResolvers(); @@ -37,8 +34,8 @@ const client = connect('127.0.0.1', server.address.port, { // A keylog line is "