mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
a7d16a8cc6 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: https://github.com/nodejs/node/pull/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>
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
// Flags: --experimental-dtls --no-warnings
|
|
|
|
// Test: MTU option validation and that a small (but valid) MTU still completes
|
|
// a handshake and data exchange (exercising DTLS record fragmentation).
|
|
|
|
import { hasCrypto, skip, mustCall } from '../common/index.mjs';
|
|
import assert from 'node:assert';
|
|
import * as fixtures from '../common/fixtures.mjs';
|
|
|
|
if (!hasCrypto) {
|
|
skip('missing crypto');
|
|
}
|
|
|
|
if (!process.features.dtls) {
|
|
skip('DTLS is not enabled');
|
|
}
|
|
|
|
const { listen, connect, DTLSEndpoint } = await import('node:dtls');
|
|
|
|
const cert = fixtures.readKey('agent1-cert.pem').toString();
|
|
const key = fixtures.readKey('agent1-key.pem').toString();
|
|
const ca = fixtures.readKey('ca1-cert.pem').toString();
|
|
|
|
// MTU must be within [256, 65535].
|
|
assert.throws(() => new DTLSEndpoint({ mtu: 255 }), { code: 'ERR_OUT_OF_RANGE' });
|
|
assert.throws(() => new DTLSEndpoint({ mtu: 65536 }), { code: 'ERR_OUT_OF_RANGE' });
|
|
|
|
// A valid boundary MTU is accepted.
|
|
{
|
|
const endpoint = new DTLSEndpoint({ mtu: 256 });
|
|
await endpoint.close();
|
|
}
|
|
|
|
// A small valid MTU forces the handshake flights (e.g. the certificate) to be
|
|
// fragmented across records, and the exchange still succeeds.
|
|
{
|
|
const received = Promise.withResolvers();
|
|
|
|
const server = listen(mustCall((session) => {
|
|
session.onmessage = mustCall((data) => {
|
|
assert.strictEqual(data.toString(), 'hello');
|
|
session.send('world');
|
|
});
|
|
}), {
|
|
cert, key, port: 0, host: '127.0.0.1', mtu: 256,
|
|
});
|
|
|
|
const client = connect('127.0.0.1', server.address.port, {
|
|
ca: [ca],
|
|
rejectUnauthorized: false,
|
|
mtu: 256,
|
|
});
|
|
|
|
client.onmessage = mustCall((data) => {
|
|
assert.strictEqual(data.toString(), 'world');
|
|
received.resolve();
|
|
});
|
|
|
|
await client.opened;
|
|
client.send('hello');
|
|
await received.promise;
|
|
|
|
await client.close();
|
|
await server.close();
|
|
}
|