Skip to content

Commit a62dd97

Browse files
mcollinaaduh95
authored andcommitted
test: fix lint in dtls tests
a7d16a8 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 <hello@matteocollina.com> PR-URL: #64902 Reviewed-By: Mike McCready <66998419+MikeMcC399@users.noreply.github.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 027d528 commit a62dd97

23 files changed

Lines changed: 216 additions & 281 deletions

test/parallel/test-dtls-accessors.mjs

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import {
99
import assert from 'node:assert';
1010
import * as fixtures from '../common/fixtures.mjs';
1111

12-
const { strictEqual } = assert;
13-
const { readKey } = fixtures;
14-
1512
if (!hasCrypto) {
1613
skip('missing crypto');
1714
}
@@ -22,9 +19,9 @@ if (!process.features.dtls) {
2219

2320
const { listen, connect } = await import('node:dtls');
2421

25-
const cert = readKey('agent1-cert.pem').toString();
26-
const key = readKey('agent1-key.pem').toString();
27-
const ca = readKey('ca1-cert.pem').toString();
22+
const cert = fixtures.readKey('agent1-cert.pem').toString();
23+
const key = fixtures.readKey('agent1-key.pem').toString();
24+
const ca = fixtures.readKey('ca1-cert.pem').toString();
2825

2926
const gotServerSession = Promise.withResolvers();
3027

@@ -34,26 +31,26 @@ const server = listen(mustCall((session) => {
3431

3532
// --- Endpoint state after listen(): bound and listening. ---
3633
const es = server.state;
37-
strictEqual(es.bound, true);
38-
strictEqual(es.listening, true);
39-
strictEqual(es.closing, false);
40-
strictEqual(es.destroyed, false);
41-
strictEqual(es.sessionCount, 0);
34+
assert.strictEqual(es.bound, true);
35+
assert.strictEqual(es.listening, true);
36+
assert.strictEqual(es.closing, false);
37+
assert.strictEqual(es.destroyed, false);
38+
assert.strictEqual(es.sessionCount, 0);
4239

4340
// The busy property is settable via the endpoint and reflected in the state view.
44-
strictEqual(server.busy, false);
45-
strictEqual(es.busy, false);
41+
assert.strictEqual(server.busy, false);
42+
assert.strictEqual(es.busy, false);
4643
server.busy = true;
47-
strictEqual(server.busy, true);
48-
strictEqual(es.busy, true);
44+
assert.strictEqual(server.busy, true);
45+
assert.strictEqual(es.busy, true);
4946
server.busy = false;
50-
strictEqual(es.busy, false);
47+
assert.strictEqual(es.busy, false);
5148

5249
// --- Endpoint onerror accessor. ---
53-
strictEqual(server.onerror, undefined);
50+
assert.strictEqual(server.onerror, undefined);
5451
const onEndpointError = mustNotCall();
5552
server.onerror = onEndpointError;
56-
strictEqual(server.onerror, onEndpointError);
53+
assert.strictEqual(server.onerror, onEndpointError);
5754

5855
const client = connect('127.0.0.1', server.address.port, {
5956
ca: [ca],
@@ -62,43 +59,43 @@ const client = connect('127.0.0.1', server.address.port, {
6259

6360
// --- Session state during the handshake. ---
6461
const cs = client.state;
65-
strictEqual(cs.handshaking, true);
66-
strictEqual(cs.open, false);
67-
strictEqual(cs.closing, false);
68-
strictEqual(cs.destroyed, false);
69-
strictEqual(cs.hasMessageListener, false);
62+
assert.strictEqual(cs.handshaking, true);
63+
assert.strictEqual(cs.open, false);
64+
assert.strictEqual(cs.closing, false);
65+
assert.strictEqual(cs.destroyed, false);
66+
assert.strictEqual(cs.hasMessageListener, false);
7067

7168
// --- Session callback accessors: unset, then set. ---
72-
strictEqual(client.onmessage, undefined);
73-
strictEqual(client.onerror, undefined);
74-
strictEqual(client.onhandshake, undefined);
75-
strictEqual(client.onkeylog, undefined);
69+
assert.strictEqual(client.onmessage, undefined);
70+
assert.strictEqual(client.onerror, undefined);
71+
assert.strictEqual(client.onhandshake, undefined);
72+
assert.strictEqual(client.onkeylog, undefined);
7673
// A connect() session owns its internal endpoint.
77-
strictEqual(client.ownsEndpoint, true);
74+
assert.strictEqual(client.ownsEndpoint, true);
7875

7976
client.onmessage = mustNotCall();
80-
strictEqual(typeof client.onmessage, 'function');
77+
assert.strictEqual(typeof client.onmessage, 'function');
8178
// Attaching a message listener flips the shared flag.
82-
strictEqual(cs.hasMessageListener, true);
79+
assert.strictEqual(cs.hasMessageListener, true);
8380

8481
client.onerror = mustNotCall();
85-
strictEqual(typeof client.onerror, 'function');
82+
assert.strictEqual(typeof client.onerror, 'function');
8683

8784
client.onhandshake = mustCall();
88-
strictEqual(typeof client.onhandshake, 'function');
85+
assert.strictEqual(typeof client.onhandshake, 'function');
8986

9087
client.onkeylog = mustCallAtLeast();
91-
strictEqual(typeof client.onkeylog, 'function');
88+
assert.strictEqual(typeof client.onkeylog, 'function');
9289

9390
await client.opened;
9491

9592
// --- Session state after the handshake completes. ---
96-
strictEqual(cs.handshaking, false);
97-
strictEqual(cs.open, true);
93+
assert.strictEqual(cs.handshaking, false);
94+
assert.strictEqual(cs.open, true);
9895

9996
const serverSession = await gotServerSession.promise;
10097
await serverSession.opened;
101-
strictEqual(es.sessionCount, 1);
98+
assert.strictEqual(es.sessionCount, 1);
10299

103100
await client.close();
104101
await server.close();

test/parallel/test-dtls-alpn.mjs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import { hasCrypto, skip, mustCall } from '../common/index.mjs';
66
import assert from 'node:assert';
77
import * as fixtures from '../common/fixtures.mjs';
88

9-
const { strictEqual } = assert;
10-
const { readKey } = fixtures;
11-
129
if (!hasCrypto) {
1310
skip('missing crypto');
1411
}
@@ -19,16 +16,16 @@ if (!process.features.dtls) {
1916

2017
const { listen, connect } = await import('node:dtls');
2118

22-
const serverCert = readKey('agent1-cert.pem');
23-
const serverKey = readKey('agent1-key.pem');
24-
const ca = readKey('ca1-cert.pem');
19+
const serverCert = fixtures.readKey('agent1-cert.pem');
20+
const serverKey = fixtures.readKey('agent1-key.pem');
21+
const ca = fixtures.readKey('ca1-cert.pem');
2522

2623
const serverAlpnChecked = Promise.withResolvers();
2724

2825
const endpoint = listen(mustCall(async (session) => {
2926
await session.opened;
3027
// Server should see the negotiated ALPN protocol.
31-
strictEqual(session.alpnProtocol, 'coap');
28+
assert.strictEqual(session.alpnProtocol, 'coap');
3229
serverAlpnChecked.resolve();
3330
}), {
3431
cert: serverCert.toString(),
@@ -47,7 +44,7 @@ const session = connect('127.0.0.1', endpoint.address.port, {
4744
await session.opened;
4845

4946
// Client should see the negotiated protocol.
50-
strictEqual(session.alpnProtocol, 'coap');
47+
assert.strictEqual(session.alpnProtocol, 'coap');
5148

5249
await serverAlpnChecked.promise;
5350

@@ -77,8 +74,8 @@ await endpoint.close();
7774
const serverSession = await gotServerSession.promise;
7875
await serverSession.opened;
7976

80-
strictEqual(client.alpnProtocol, undefined);
81-
strictEqual(serverSession.alpnProtocol, undefined);
77+
assert.strictEqual(client.alpnProtocol, undefined);
78+
assert.strictEqual(serverSession.alpnProtocol, undefined);
8279

8380
await client.close();
8481
await server.close();

test/parallel/test-dtls-async-dispose.mjs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import { hasCrypto, skip, mustCall, mustNotCall } from '../common/index.mjs';
66
import assert from 'node:assert';
77
import * as fixtures from '../common/fixtures.mjs';
88

9-
const { strictEqual } = assert;
10-
const { readKey } = fixtures;
11-
129
if (!hasCrypto) {
1310
skip('missing crypto');
1411
}
@@ -19,9 +16,9 @@ if (!process.features.dtls) {
1916

2017
const { listen, connect } = await import('node:dtls');
2118

22-
const serverCert = readKey('agent1-cert.pem');
23-
const serverKey = readKey('agent1-key.pem');
24-
const ca = readKey('ca1-cert.pem');
19+
const serverCert = fixtures.readKey('agent1-cert.pem');
20+
const serverKey = fixtures.readKey('agent1-key.pem');
21+
const ca = fixtures.readKey('ca1-cert.pem');
2522

2623
const endpoint = listen(mustCall((session) => {
2724
session.onmessage = mustNotCall();
@@ -40,8 +37,8 @@ const session = connect('127.0.0.1', endpoint.address.port, {
4037
await session.opened;
4138

4239
// Test that Symbol.asyncDispose exists.
43-
strictEqual(typeof session[Symbol.asyncDispose], 'function');
44-
strictEqual(typeof endpoint[Symbol.asyncDispose], 'function');
40+
assert.strictEqual(typeof session[Symbol.asyncDispose], 'function');
41+
assert.strictEqual(typeof endpoint[Symbol.asyncDispose], 'function');
4542

4643
// Dispose the session.
4744
await session[Symbol.asyncDispose]();

test/parallel/test-dtls-basic.mjs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import { hasCrypto, skip, mustCall } from '../common/index.mjs';
66
import assert from 'node:assert';
77
import * as fixtures from '../common/fixtures.mjs';
88

9-
const { ok, strictEqual, match } = assert;
10-
const { readKey } = fixtures;
11-
129
if (!hasCrypto) {
1310
skip('missing crypto');
1411
}
@@ -19,9 +16,9 @@ if (!process.features.dtls) {
1916

2017
const { listen, connect } = await import('node:dtls');
2118

22-
const serverCert = readKey('agent1-cert.pem');
23-
const serverKey = readKey('agent1-key.pem');
24-
const ca = readKey('ca1-cert.pem');
19+
const serverCert = fixtures.readKey('agent1-cert.pem');
20+
const serverKey = fixtures.readKey('agent1-key.pem');
21+
const ca = fixtures.readKey('ca1-cert.pem');
2522

2623
const serverReceivedData = Promise.withResolvers();
2724
const clientReceivedData = Promise.withResolvers();
@@ -32,16 +29,16 @@ let clientHandshakeDone = false;
3229
// Start server.
3330
const endpoint = listen(mustCall((session) => {
3431
session.onmessage = mustCall((data) => {
35-
strictEqual(data.toString(), 'hello from client');
32+
assert.strictEqual(data.toString(), 'hello from client');
3633
serverReceivedData.resolve();
3734

3835
// Send response back to client.
3936
session.send('hello from server');
4037
});
4138

4239
session.onhandshake = mustCall((protocol) => {
43-
ok(protocol);
44-
match(protocol, /DTLS/i);
40+
assert.ok(protocol);
41+
assert.match(protocol, /DTLS/i);
4542
serverHandshakeDone = true;
4643
});
4744
}), {
@@ -52,8 +49,8 @@ const endpoint = listen(mustCall((session) => {
5249
});
5350

5451
const serverAddress = endpoint.address;
55-
ok(serverAddress);
56-
ok(serverAddress.port > 0);
52+
assert.ok(serverAddress);
53+
assert.ok(serverAddress.port > 0);
5754

5855
// Connect client.
5956
const clientSession = connect('127.0.0.1', serverAddress.port, {
@@ -62,18 +59,18 @@ const clientSession = connect('127.0.0.1', serverAddress.port, {
6259
});
6360

6461
clientSession.onmessage = mustCall((data) => {
65-
strictEqual(data.toString(), 'hello from server');
62+
assert.strictEqual(data.toString(), 'hello from server');
6663
clientReceivedData.resolve();
6764
});
6865

6966
clientSession.onhandshake = mustCall((protocol) => {
70-
ok(protocol);
67+
assert.ok(protocol);
7168
clientHandshakeDone = true;
7269
});
7370

7471
// Wait for handshake.
7572
const { protocol } = await clientSession.opened;
76-
match(protocol, /DTLS/i);
73+
assert.match(protocol, /DTLS/i);
7774

7875
// Send data.
7976
clientSession.send('hello from client');
@@ -82,8 +79,8 @@ clientSession.send('hello from client');
8279
await Promise.all([serverReceivedData.promise, clientReceivedData.promise]);
8380

8481
// Verify handshakes completed.
85-
ok(clientHandshakeDone);
86-
ok(serverHandshakeDone);
82+
assert.ok(clientHandshakeDone);
83+
assert.ok(serverHandshakeDone);
8784

8885
// Clean up.
8986
await clientSession.close();

test/parallel/test-dtls-ciphers.mjs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import { hasCrypto, skip, mustCall, mustNotCall } from '../common/index.mjs';
66
import assert from 'node:assert';
77
import * as fixtures from '../common/fixtures.mjs';
88

9-
const { strictEqual, throws } = assert;
10-
const { readKey } = fixtures;
11-
129
if (!hasCrypto) {
1310
skip('missing crypto');
1411
}
@@ -19,9 +16,9 @@ if (!process.features.dtls) {
1916

2017
const { listen, connect } = await import('node:dtls');
2118

22-
const cert = readKey('agent1-cert.pem').toString();
23-
const key = readKey('agent1-key.pem').toString();
24-
const ca = readKey('ca1-cert.pem').toString();
19+
const cert = fixtures.readKey('agent1-cert.pem').toString();
20+
const key = fixtures.readKey('agent1-key.pem').toString();
21+
const ca = fixtures.readKey('ca1-cert.pem').toString();
2522

2623
const CIPHER = 'ECDHE-RSA-AES128-GCM-SHA256';
2724

@@ -43,15 +40,15 @@ const CIPHER = 'ECDHE-RSA-AES128-GCM-SHA256';
4340
const serverSession = await gotServerSession.promise;
4441
await serverSession.opened;
4542

46-
strictEqual(client.cipher.name, CIPHER);
47-
strictEqual(serverSession.cipher.name, CIPHER);
43+
assert.strictEqual(client.cipher.name, CIPHER);
44+
assert.strictEqual(serverSession.cipher.name, CIPHER);
4845

4946
await client.close();
5047
await server.close();
5148
}
5249

5350
// Case 2: an invalid cipher list is rejected.
54-
throws(() => listen(mustNotCall(), {
51+
assert.throws(() => listen(mustNotCall(), {
5552
cert, key, port: 0, host: '127.0.0.1', ciphers: 'THIS-IS-NOT-A-CIPHER',
5653
}), { code: 'ERR_CRYPTO_OPERATION_FAILED' });
5754

@@ -74,6 +71,6 @@ throws(() => listen(mustNotCall(), {
7471
}
7572

7673
// Case 4: an invalid ECDH curve is rejected.
77-
throws(() => listen(mustNotCall(), {
74+
assert.throws(() => listen(mustNotCall(), {
7875
cert, key, port: 0, host: '127.0.0.1', ecdhCurve: 'not-a-curve',
7976
}), { code: 'ERR_CRYPTO_OPERATION_FAILED' });

test/parallel/test-dtls-client-cert.mjs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import { hasCrypto, skip, mustCall } from '../common/index.mjs';
77
import assert from 'node:assert';
88
import * as fixtures from '../common/fixtures.mjs';
99

10-
const { ok, rejects } = assert;
11-
const { readKey } = fixtures;
12-
1310
if (!hasCrypto) {
1411
skip('missing crypto');
1512
}
@@ -20,9 +17,9 @@ if (!process.features.dtls) {
2017

2118
const { listen, connect } = await import('node:dtls');
2219

23-
const cert = readKey('agent1-cert.pem').toString();
24-
const key = readKey('agent1-key.pem').toString();
25-
const ca = readKey('ca1-cert.pem').toString();
20+
const cert = fixtures.readKey('agent1-cert.pem').toString();
21+
const key = fixtures.readKey('agent1-key.pem').toString();
22+
const ca = fixtures.readKey('ca1-cert.pem').toString();
2623

2724
// Case 1: the client presents a certificate the server can verify.
2825
{
@@ -44,8 +41,8 @@ const ca = readKey('ca1-cert.pem').toString();
4441

4542
// The server received and verified the client's certificate.
4643
const clientCert = serverSession.peerCertificate;
47-
ok(clientCert);
48-
ok(clientCert.includes('BEGIN CERTIFICATE'));
44+
assert.ok(clientCert);
45+
assert.ok(clientCert.includes('BEGIN CERTIFICATE'));
4946

5047
await client.close();
5148
await server.close();
@@ -63,7 +60,7 @@ const ca = readKey('ca1-cert.pem').toString();
6360
});
6461

6562
// The exact alert text varies, so assert only that the handshake is rejected.
66-
await rejects(client.opened, {
63+
await assert.rejects(client.opened, {
6764
message: /handshake failure/
6865
});
6966

0 commit comments

Comments
 (0)