test: fix lint in dtls tests · nodejs/node@9aa8489 · GitHub
Skip to content

Commit 9aa8489

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 81cd6d7 commit 9aa8489

23 files changed

Lines changed: 216 additions & 281 deletions

‎test/parallel/test-dtls-accessors.mjs‎

Lines changed: 33 additions & 36 deletions

‎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

0 commit comments

Comments
 (0)