Skip to content

Commit a46087d

Browse files
mcollinapanva
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 b9dacd4 commit a46087d

17 files changed

Lines changed: 116 additions & 158 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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ await endpoint.close();
7474
const serverSession = await gotServerSession.promise;
7575
await serverSession.opened;
7676

77-
strictEqual(client.alpnProtocol, undefined);
78-
strictEqual(serverSession.alpnProtocol, undefined);
77+
assert.strictEqual(client.alpnProtocol, undefined);
78+
assert.strictEqual(serverSession.alpnProtocol, undefined);
7979

8080
await client.close();
8181
await server.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

test/parallel/test-dtls-connect-error-cleanup.mjs

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

11-
const { rejects } = assert;
12-
const { readKey } = fixtures;
13-
1411
if (!hasCrypto) {
1512
skip('missing crypto');
1613
}
@@ -21,9 +18,9 @@ if (!process.features.dtls) {
2118

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

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

2825
// The client rejects the certificate mid-handshake, so this server session
2926
// 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, {
3734
servername: 'wrong.example.com',
3835
});
3936

40-
await rejects(session.opened, /certificate verify failed/i);
37+
await assert.rejects(session.opened, /certificate verify failed/i);
4138

4239
// The failed connect must have closed its internally-owned endpoint. Without
4340
// that, this await never settles and the test times out.

test/parallel/test-dtls-destroy-in-callback.mjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import { hasCrypto, skip, mustCall } from '../common/index.mjs';
1010
import * as fixtures from '../common/fixtures.mjs';
1111

12-
const { readKey } = fixtures;
13-
1412
if (!hasCrypto) {
1513
skip('missing crypto');
1614
}
@@ -21,9 +19,9 @@ if (!process.features.dtls) {
2119

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

24-
const cert = readKey('agent1-cert.pem').toString();
25-
const key = readKey('agent1-key.pem').toString();
26-
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();
2725

2826
// ---------------------------------------------------------------------------
2927
// Case 1: destroy the (server) session from inside onmessage. The datagram

test/parallel/test-dtls-errors.mjs

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

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

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

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

2724
// A malformed certificate PEM is rejected.
28-
throws(() => listen(mustNotCall(), {
25+
assert.throws(() => listen(mustNotCall(), {
2926
cert: 'not a certificate', key, port: 0,
3027
}), { code: 'ERR_CRYPTO_OPERATION_FAILED' });
3128

3229
// A malformed private key PEM is rejected.
33-
throws(() => listen(mustNotCall(), {
30+
assert.throws(() => listen(mustNotCall(), {
3431
cert, key: 'not a key', port: 0,
3532
}), { code: 'ERR_CRYPTO_OPERATION_FAILED' });
3633

3734
// A private key that does not match the certificate is rejected.
38-
throws(() => listen(mustNotCall(), {
35+
assert.throws(() => listen(mustNotCall(), {
3936
cert, key: mismatchedKey, port: 0,
4037
}), { code: 'ERR_CRYPTO_OPERATION_FAILED' });
4138

4239
// Binding the same endpoint twice fails.
4340
{
4441
const endpoint = new DTLSEndpoint();
4542
endpoint.bind('127.0.0.1', 0);
46-
throws(() => endpoint.bind('127.0.0.1', 0), { code: 'ERR_INVALID_STATE' });
43+
assert.throws(() => endpoint.bind('127.0.0.1', 0), { code: 'ERR_INVALID_STATE' });
4744
await endpoint.close();
4845
}

test/parallel/test-dtls-keylog.mjs

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

10-
const { strictEqual, match } = 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
const gotKeylog = Promise.withResolvers();
2825

@@ -37,8 +34,8 @@ const client = connect('127.0.0.1', server.address.port, {
3734

3835
// A keylog line is "<LABEL> <hex> <hex>" (e.g. "CLIENT_RANDOM ...").
3936
client.onkeylog = mustCallAtLeast((line) => {
40-
strictEqual(typeof line, 'string');
41-
match(line, /^\S+ [0-9a-f]+ [0-9a-f]+$/i);
37+
assert.strictEqual(typeof line, 'string');
38+
assert.match(line, /^\S+ [0-9a-f]+ [0-9a-f]+$/i);
4239
gotKeylog.resolve();
4340
});
4441

0 commit comments

Comments
 (0)