mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
test: ensure assertions are reached on all tests
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: https://github.com/nodejs/node/pull/64716 Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Aviv Keller <me@aviv.sh>
This commit is contained in:
234 files changed
+1706
-2253
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import fixtures from './fixtures.js';
|
||||
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
const {
|
||||
fixturesDir,
|
||||
path,
|
||||
|
||||
@@ -116,6 +116,10 @@ export default [
|
||||
selector: 'CallExpression:matches([callee.type="Identifier"][callee.name="assert"], [callee.type="MemberExpression"][callee.object.type="Identifier"][callee.object.name="assert"][callee.property.type="Identifier"][callee.property.name="ok"])[arguments.0.type="UnaryExpression"][arguments.0.operator="!"][arguments.0.argument.type="CallExpression"][arguments.0.argument.callee.type="MemberExpression"][arguments.0.argument.callee.object.regex][arguments.0.argument.callee.property.name="test"]',
|
||||
message: 'Use assert.doesNotMatch instead',
|
||||
},
|
||||
{
|
||||
selector: 'VariableDeclarator[init.type="Identifier"][init.name=/^(assert|fixtures)$/]',
|
||||
message: 'Do not destructure or rename `assert` nor `fixtures`',
|
||||
},
|
||||
...((fixturesSpecifier) => [
|
||||
{
|
||||
selector: `ImportDeclaration[source.value=${fixturesSpecifier.toString().replace('(\\.js)?', '\\.mjs')}]:not(${[
|
||||
|
||||
@@ -4,7 +4,6 @@ const { mustCall, hasCrypto } = require('../common');
|
||||
const assert = require('assert');
|
||||
const util = require('util');
|
||||
const { test } = require('node:test');
|
||||
const { AssertionError } = assert;
|
||||
const defaultMsgStart = 'Expected values to be strictly deep-equal:\n';
|
||||
const defaultMsgStartFull = `${defaultMsgStart}+ actual - expected`;
|
||||
|
||||
@@ -688,11 +687,11 @@ test('Handle sparse arrays', () => {
|
||||
const b = new Array(3);
|
||||
a[2] = true;
|
||||
b[1] = true;
|
||||
assertNotDeepOrStrict(a, b, AssertionError, { partial: 'pass' });
|
||||
assertNotDeepOrStrict(a, b, assert.AssertionError, { partial: 'pass' });
|
||||
b[2] = true;
|
||||
assertNotDeepOrStrict(a, b);
|
||||
a[0] = true;
|
||||
assertNotDeepOrStrict(a, b, AssertionError, { partial: 'pass' });
|
||||
assertNotDeepOrStrict(a, b, assert.AssertionError, { partial: 'pass' });
|
||||
});
|
||||
|
||||
test('Handle sets and maps with mixed keys', () => {
|
||||
@@ -715,7 +714,7 @@ test('Handle different error messages', () => {
|
||||
assertNotDeepOrStrict(err1, new Error('foo2'), assert.AssertionError);
|
||||
assertNotDeepOrStrict(err1, new TypeError('foo1'), assert.AssertionError);
|
||||
assertDeepAndStrictEqual(err1, new Error('foo1'));
|
||||
assertNotDeepOrStrict(err1, {}, AssertionError);
|
||||
assertNotDeepOrStrict(err1, {}, assert.AssertionError);
|
||||
});
|
||||
|
||||
test('Handle NaN', () => {
|
||||
@@ -811,18 +810,18 @@ test('Additional tests', () => {
|
||||
assertDeepAndStrictEqual(new Date(2000, 3, 14), new Date(2000, 3, 14));
|
||||
|
||||
assert.throws(() => { assert.deepEqual(new Date(), new Date(2000, 3, 14)); },
|
||||
AssertionError,
|
||||
assert.AssertionError,
|
||||
'deepEqual(new Date(), new Date(2000, 3, 14))');
|
||||
|
||||
assert.throws(
|
||||
() => { assert.notDeepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14)); },
|
||||
AssertionError,
|
||||
assert.AssertionError,
|
||||
'notDeepEqual(new Date(2000, 3, 14), new Date(2000, 3, 14))'
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
() => { assert.notDeepEqual('a'.repeat(1024), 'a'.repeat(1024)); },
|
||||
AssertionError,
|
||||
assert.AssertionError,
|
||||
'notDeepEqual("a".repeat(1024), "a".repeat(1024))'
|
||||
);
|
||||
|
||||
@@ -861,7 +860,7 @@ test('Additional tests', () => {
|
||||
assert.deepEqual(4, '4');
|
||||
assert.deepEqual(true, 1);
|
||||
assert.throws(() => assert.deepEqual(4, '5'),
|
||||
AssertionError,
|
||||
assert.AssertionError,
|
||||
'deepEqual( 4, \'5\')');
|
||||
});
|
||||
|
||||
@@ -870,7 +869,7 @@ test('Having the same number of owned properties && the same set of keys', () =>
|
||||
assert.deepEqual({ a: 4, b: '2' }, { a: 4, b: '2' });
|
||||
assert.deepEqual([4], ['4']);
|
||||
assert.throws(
|
||||
() => assert.deepEqual({ a: 4 }, { a: 4, b: true }), AssertionError);
|
||||
() => assert.deepEqual({ a: 4 }, { a: 4, b: true }), assert.AssertionError);
|
||||
assert.notDeepEqual(['a'], { 0: 'a' });
|
||||
assert.deepEqual({ a: 4, b: '1' }, { b: '1', a: 4 });
|
||||
const a1 = [1, 2, 3];
|
||||
@@ -880,7 +879,7 @@ test('Having the same number of owned properties && the same set of keys', () =>
|
||||
a2.b = true;
|
||||
a2.a = 'test';
|
||||
assert.throws(() => assert.deepEqual(Object.keys(a1), Object.keys(a2)),
|
||||
AssertionError);
|
||||
assert.AssertionError);
|
||||
assertDeepAndStrictEqual(a1, a2);
|
||||
});
|
||||
|
||||
@@ -946,7 +945,7 @@ test('Additional tests', () => {
|
||||
|
||||
assert.throws(
|
||||
() => assert.deepStrictEqual(new Date(), new Date(2000, 3, 14)),
|
||||
AssertionError,
|
||||
assert.AssertionError,
|
||||
'deepStrictEqual(new Date(), new Date(2000, 3, 14))'
|
||||
);
|
||||
|
||||
@@ -1059,7 +1058,7 @@ test('Additional tests', () => {
|
||||
|
||||
assert.throws(
|
||||
() => assert.deepStrictEqual([0, 1, 2, 'a', 'b'], [0, 1, 2, 'b', 'a']),
|
||||
AssertionError);
|
||||
assert.AssertionError);
|
||||
});
|
||||
|
||||
test('Having the same number of owned properties && the same set of keys', () => {
|
||||
@@ -1105,7 +1104,7 @@ test('Prototype check', () => {
|
||||
const obj1 = new Constructor1('Ryan', 'Dahl');
|
||||
let obj2 = new Constructor2('Ryan', 'Dahl');
|
||||
|
||||
assert.throws(() => assert.deepStrictEqual(obj1, obj2), AssertionError);
|
||||
assert.throws(() => assert.deepStrictEqual(obj1, obj2), assert.AssertionError);
|
||||
|
||||
Constructor2.prototype = Constructor1.prototype;
|
||||
obj2 = new Constructor2('Ryan', 'Dahl');
|
||||
@@ -1262,7 +1261,7 @@ test('Verify that changed tags will still check for the error message', () => {
|
||||
err[Symbol.toStringTag] = 'Foobar';
|
||||
const err2 = new Error('bar');
|
||||
err2[Symbol.toStringTag] = 'Foobar';
|
||||
assertNotDeepOrStrict(err, err2, AssertionError);
|
||||
assertNotDeepOrStrict(err, err2, assert.AssertionError);
|
||||
});
|
||||
|
||||
test('Check for non-native errors', () => {
|
||||
@@ -1281,8 +1280,8 @@ test('Check for non-native errors', () => {
|
||||
test('Check for Errors with cause property', () => {
|
||||
const e1 = new Error('err', { cause: new Error('cause e1') });
|
||||
const e2 = new Error('err', { cause: new Error('cause e2') });
|
||||
assertNotDeepOrStrict(e1, e2, AssertionError);
|
||||
assertNotDeepOrStrict(e1, new Error('err'), AssertionError);
|
||||
assertNotDeepOrStrict(e1, e2, assert.AssertionError);
|
||||
assertNotDeepOrStrict(e1, new Error('err'), assert.AssertionError);
|
||||
assertDeepAndStrictEqual(e1, new Error('err', { cause: new Error('cause e1') }));
|
||||
});
|
||||
|
||||
@@ -1294,8 +1293,8 @@ test('Check for AggregateError', () => {
|
||||
const e3 = new AggregateError([e1duplicate, e2], 'Aggregate Error');
|
||||
const e3duplicate = new AggregateError([e1, e2], 'Aggregate Error');
|
||||
const e4 = new AggregateError([e1], 'Aggregate Error');
|
||||
assertNotDeepOrStrict(e1, e3, AssertionError);
|
||||
assertNotDeepOrStrict(e3, e4, AssertionError);
|
||||
assertNotDeepOrStrict(e1, e3, assert.AssertionError);
|
||||
assertNotDeepOrStrict(e3, e4, assert.AssertionError);
|
||||
assertDeepAndStrictEqual(e3, e3duplicate);
|
||||
});
|
||||
|
||||
|
||||
@@ -9,9 +9,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,15 +16,15 @@ if (!hasQuic) {
|
||||
const { listen, connect, QuicEndpoint } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const endpoint = new QuicEndpoint({ validateAddress: true });
|
||||
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
const info = await serverSession.opened;
|
||||
// The handshake should complete despite the Retry flow.
|
||||
strictEqual(info.protocol, 'quic-test');
|
||||
assert.strictEqual(info.protocol, 'quic-test');
|
||||
serverSession.close();
|
||||
}), {
|
||||
endpoint,
|
||||
@@ -42,7 +39,7 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
});
|
||||
|
||||
const info = await clientSession.opened;
|
||||
strictEqual(info.protocol, 'quic-test');
|
||||
assert.strictEqual(info.protocol, 'quic-test');
|
||||
|
||||
// The serverEndpoint must be closed after we wait for the clientSession to close.
|
||||
await clientSession.closed;
|
||||
|
||||
@@ -4,9 +4,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual, notStrictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -14,8 +11,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
// Test h3 ALPN negotiation with Http3ApplicationImpl.
|
||||
// Both server and client use the default ALPN (h3).
|
||||
@@ -24,14 +21,14 @@ const serverOpened = Promise.withResolvers();
|
||||
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
const info = await serverSession.opened;
|
||||
strictEqual(info.protocol, 'h3');
|
||||
assert.strictEqual(info.protocol, 'h3');
|
||||
serverOpened.resolve();
|
||||
serverSession.close();
|
||||
}), {
|
||||
sni: { '*': { keys: [key], certs: [cert] } },
|
||||
});
|
||||
|
||||
notStrictEqual(serverEndpoint.address, undefined);
|
||||
assert.notStrictEqual(serverEndpoint.address, undefined);
|
||||
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
servername: 'localhost',
|
||||
@@ -40,7 +37,7 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
|
||||
async function checkClient() {
|
||||
const info = await clientSession.opened;
|
||||
strictEqual(info.protocol, 'h3');
|
||||
assert.strictEqual(info.protocol, 'h3');
|
||||
}
|
||||
|
||||
await Promise.all([serverOpened.promise, checkClient()]);
|
||||
|
||||
@@ -8,11 +8,9 @@
|
||||
// 0x100 | <tls_alert>. For `no_application_protocol` (alert 120 / 0x78) this
|
||||
// is 0x178 == 376.
|
||||
|
||||
import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
|
||||
import { hasQuic, skip, mustNotCall, expectsError } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual, match } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -25,11 +23,6 @@ const expected = {
|
||||
message: /no application protocol/
|
||||
};
|
||||
|
||||
const onerror = mustCall((err) => {
|
||||
strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
|
||||
strictEqual(err.errorCode, 376n);
|
||||
match(err.message, /no application protocol/);
|
||||
});
|
||||
const transportParams = { maxIdleTimeout: 1 };
|
||||
|
||||
// The handshake fails so the session is never surfaced to JS
|
||||
@@ -43,12 +36,12 @@ const serverEndpoint = await listen(
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
alpn: 'nonexistent-protocol',
|
||||
transportParams,
|
||||
onerror,
|
||||
onerror: expectsError(expected),
|
||||
});
|
||||
|
||||
await rejects(clientSession.opened, expected);
|
||||
await assert.rejects(clientSession.opened, expected);
|
||||
|
||||
// The handshake should fail — opened may reject or never resolve.
|
||||
// The session should close with an error.
|
||||
await rejects(clientSession.closed, expected);
|
||||
await assert.rejects(clientSession.closed, expected);
|
||||
await serverEndpoint.close();
|
||||
@@ -4,9 +4,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { notStrictEqual, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -14,8 +11,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
// Server offers multiple ALPNs. Client requests one that the server supports.
|
||||
// Verify the negotiated protocol matches on both sides.
|
||||
@@ -25,7 +22,7 @@ const serverOpened = Promise.withResolvers();
|
||||
async function checkSession(session) {
|
||||
const info = await session.opened;
|
||||
// The client should negotiate proto-b (the only protocol it requested)
|
||||
strictEqual(info.protocol, 'proto-b');
|
||||
assert.strictEqual(info.protocol, 'proto-b');
|
||||
}
|
||||
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
@@ -36,7 +33,7 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
alpn: ['proto-a', 'proto-b', 'proto-c'],
|
||||
});
|
||||
|
||||
notStrictEqual(serverEndpoint.address, undefined);
|
||||
assert.notStrictEqual(serverEndpoint.address, undefined);
|
||||
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
alpn: 'proto-b',
|
||||
|
||||
@@ -8,8 +8,6 @@ import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import net from 'node:net';
|
||||
|
||||
const { ok, rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -34,18 +32,18 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
handshakeTimeout: 500,
|
||||
verifyPeer: 'manual',
|
||||
onerror: mustCall((err) => {
|
||||
strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
|
||||
assert.strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
|
||||
}),
|
||||
});
|
||||
|
||||
// The session should fail — the server never sees the packet.
|
||||
await rejects(clientSession.opened, {
|
||||
await assert.rejects(clientSession.opened, {
|
||||
code: 'ERR_QUIC_TRANSPORT_ERROR',
|
||||
});
|
||||
|
||||
// Verify the stat counter.
|
||||
ok(serverEndpoint.stats.packetsBlocked > 0n,
|
||||
'packetsBlocked should be non-zero');
|
||||
assert.ok(serverEndpoint.stats.packetsBlocked > 0n,
|
||||
'packetsBlocked should be non-zero');
|
||||
|
||||
await serverEndpoint.close();
|
||||
}
|
||||
@@ -72,8 +70,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
await clientSession.opened;
|
||||
await clientSession.close();
|
||||
|
||||
strictEqual(serverEndpoint.stats.packetsBlocked, 0n,
|
||||
'No packets should be blocked for allowed address');
|
||||
assert.strictEqual(serverEndpoint.stats.packetsBlocked, 0n); // No packets should be blocked for allowed address
|
||||
|
||||
await serverEndpoint.close();
|
||||
}
|
||||
@@ -7,8 +7,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -42,5 +40,5 @@ stream.onblocked = mustCall(() => {
|
||||
stream.setBody(new Uint8Array(4096));
|
||||
|
||||
// The stream's closed promise should reject with the error from the throw.
|
||||
await rejects(stream.closed, testError);
|
||||
await assert.rejects(stream.closed, testError);
|
||||
await serverEndpoint.close();
|
||||
@@ -6,8 +6,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -20,7 +18,7 @@ const serverDone = Promise.withResolvers();
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
// The session is destroyed by the ondatagram throw. The closed promise
|
||||
// rejects with testError. Verify that and signal completion.
|
||||
await rejects(serverSession.closed, testError);
|
||||
await assert.rejects(serverSession.closed, testError);
|
||||
serverDone.resolve();
|
||||
}), {
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
@@ -28,7 +26,7 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
throw testError;
|
||||
},
|
||||
onerror: mustCall((err) => {
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -28,7 +26,7 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
throw testError;
|
||||
},
|
||||
onerror: mustCall((err) => {
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
}),
|
||||
});
|
||||
await clientSession.opened;
|
||||
@@ -37,5 +35,5 @@ await clientSession.opened;
|
||||
await clientSession.sendDatagram(new Uint8Array([1, 2, 3]));
|
||||
|
||||
// The session's closed should reject with the error from the throw.
|
||||
await rejects(clientSession.closed, testError);
|
||||
await assert.rejects(clientSession.closed, testError);
|
||||
await serverEndpoint.close();
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -26,12 +24,12 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
transportParams,
|
||||
onerror: mustCall((err) => {
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
}),
|
||||
});
|
||||
await clientSession.opened;
|
||||
|
||||
clientSession.destroy(testError);
|
||||
|
||||
await rejects(clientSession.closed, testError);
|
||||
await assert.rejects(clientSession.closed, testError);
|
||||
await serverEndpoint.close();
|
||||
@@ -7,8 +7,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual, throws } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -22,19 +20,19 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
await serverSession.opened;
|
||||
|
||||
// Session onerror validation: non-functions throw.
|
||||
throws(() => { serverSession.onerror = 'not a function'; }, errorCheck);
|
||||
throws(() => { serverSession.onerror = 42; }, errorCheck);
|
||||
throws(() => { serverSession.onerror = null; }, errorCheck);
|
||||
assert.throws(() => { serverSession.onerror = 'not a function'; }, errorCheck);
|
||||
assert.throws(() => { serverSession.onerror = 42; }, errorCheck);
|
||||
assert.throws(() => { serverSession.onerror = null; }, errorCheck);
|
||||
|
||||
// Setting to a function works.
|
||||
const fn = () => {};
|
||||
serverSession.onerror = fn;
|
||||
// The getter returns the bound version, not the original.
|
||||
strictEqual(typeof serverSession.onerror, 'function');
|
||||
assert.strictEqual(typeof serverSession.onerror, 'function');
|
||||
|
||||
// Setting to undefined clears it.
|
||||
serverSession.onerror = undefined;
|
||||
strictEqual(serverSession.onerror, undefined);
|
||||
assert.strictEqual(serverSession.onerror, undefined);
|
||||
|
||||
serverSession.close();
|
||||
}));
|
||||
@@ -47,17 +45,17 @@ const stream = await clientSession.createBidirectionalStream({
|
||||
body: new TextEncoder().encode('x'),
|
||||
});
|
||||
|
||||
throws(() => { stream.onerror = 'not a function'; }, errorCheck);
|
||||
throws(() => { stream.onerror = 42; }, errorCheck);
|
||||
throws(() => { stream.onerror = null; }, errorCheck);
|
||||
assert.throws(() => { stream.onerror = 'not a function'; }, errorCheck);
|
||||
assert.throws(() => { stream.onerror = 42; }, errorCheck);
|
||||
assert.throws(() => { stream.onerror = null; }, errorCheck);
|
||||
|
||||
// Setting to a function works.
|
||||
stream.onerror = () => {};
|
||||
strictEqual(typeof stream.onerror, 'function');
|
||||
assert.strictEqual(typeof stream.onerror, 'function');
|
||||
|
||||
// Setting to undefined clears it.
|
||||
stream.onerror = undefined;
|
||||
strictEqual(stream.onerror, undefined);
|
||||
assert.strictEqual(stream.onerror, undefined);
|
||||
|
||||
await clientSession.closed;
|
||||
await serverEndpoint.close();
|
||||
@@ -10,8 +10,6 @@ import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
|
||||
const { ok, rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -22,8 +20,8 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
// It should fire once for the first client session (destroyed with error)
|
||||
// and not for the second (destroyed without error).
|
||||
dc.subscribe('quic.session.error', mustCall((msg) => {
|
||||
ok(msg.session, 'session.error should include session');
|
||||
ok(msg.error, 'session.error should include error');
|
||||
assert.ok(msg.session, 'session.error should include session');
|
||||
assert.ok(msg.error, 'session.error should include error');
|
||||
}));
|
||||
|
||||
const transportParams = { maxIdleTimeout: 1 };
|
||||
@@ -44,17 +42,17 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
let onerrorCalled = false;
|
||||
clientSession.onerror = mustCall((err) => {
|
||||
// Receives the original error.
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
onerrorCalled = true;
|
||||
});
|
||||
|
||||
clientSession.destroy(testError);
|
||||
|
||||
// Onerror was called synchronously during destroy.
|
||||
strictEqual(onerrorCalled, true);
|
||||
assert.strictEqual(onerrorCalled, true);
|
||||
|
||||
// Closed rejects with the original error.
|
||||
await rejects(clientSession.closed, testError);
|
||||
await assert.rejects(clientSession.closed, testError);
|
||||
}
|
||||
|
||||
// Second client: destroy WITHOUT error — onerror should NOT fire.
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -30,13 +28,13 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
throw testError;
|
||||
},
|
||||
onerror: mustCall((err) => {
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
}),
|
||||
});
|
||||
|
||||
await clientSession.opened;
|
||||
|
||||
// The session's closed should reject with the error from the throw.
|
||||
await rejects(clientSession.closed, testError);
|
||||
await assert.rejects(clientSession.closed, testError);
|
||||
|
||||
await serverEndpoint.close();
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -25,7 +23,7 @@ const preferredEndpoint = await listen(mustNotCall(), {});
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
// The server session closes with a transport error when the
|
||||
// client is destroyed by the throw. That's expected.
|
||||
await rejects(serverSession.closed, {
|
||||
await assert.rejects(serverSession.closed, {
|
||||
code: 'ERR_QUIC_TRANSPORT_ERROR',
|
||||
});
|
||||
}), {
|
||||
@@ -42,13 +40,13 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
},
|
||||
onerror: mustCall((err) => {
|
||||
// The error from the throw should be delivered here.
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
}),
|
||||
});
|
||||
await clientSession.opened;
|
||||
|
||||
// The session's closed should reject with the thrown error.
|
||||
await rejects(clientSession.closed, testError);
|
||||
await assert.rejects(clientSession.closed, testError);
|
||||
|
||||
await serverEndpoint.close();
|
||||
await preferredEndpoint.close();
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -26,7 +24,7 @@ const serverEndpoint = await listen(mustCall((serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
// The stream's onerror should fire with the throw from onreset.
|
||||
stream.onerror = mustCall((err) => {
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
});
|
||||
|
||||
stream.onreset = () => {
|
||||
@@ -36,7 +34,7 @@ const serverEndpoint = await listen(mustCall((serverSession) => {
|
||||
serverReady.resolve();
|
||||
|
||||
// Stream closed rejects because the onreset throw destroyed it.
|
||||
await rejects(stream.closed, testError);
|
||||
await assert.rejects(stream.closed, testError);
|
||||
serverStreamDone.resolve();
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -29,13 +27,13 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
throw testError;
|
||||
},
|
||||
onerror: mustCall((err) => {
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
}),
|
||||
});
|
||||
|
||||
await clientSession.opened;
|
||||
|
||||
// The session's closed should reject with the error from the throw.
|
||||
await rejects(clientSession.closed, testError);
|
||||
await assert.rejects(clientSession.closed, testError);
|
||||
|
||||
await serverEndpoint.close();
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual, rejects } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -20,7 +18,7 @@ const testError = new Error('async onstream rejection');
|
||||
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
serverSession.onerror = mustCall((err) => {
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
});
|
||||
|
||||
serverSession.onstream = async () => {
|
||||
@@ -28,7 +26,7 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
};
|
||||
|
||||
// Session closed rejects with the error from the async rejection.
|
||||
await rejects(serverSession.closed, testError);
|
||||
await assert.rejects(serverSession.closed, testError);
|
||||
}), { transportParams: { maxIdleTimeout: 1 } });
|
||||
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -22,7 +20,7 @@ const testError = new Error('sync onstream throw');
|
||||
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
serverSession.onerror = mustCall((err) => {
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
});
|
||||
|
||||
serverSession.onstream = () => {
|
||||
@@ -30,7 +28,7 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
};
|
||||
|
||||
// The session's closed rejects with the error from destroy().
|
||||
await rejects(serverSession.closed, testError);
|
||||
await assert.rejects(serverSession.closed, testError);
|
||||
}), { transportParams: { maxIdleTimeout: 1 } });
|
||||
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -43,17 +41,17 @@ await clientSession.opened;
|
||||
let onerrorCalled = false;
|
||||
stream.onerror = mustCall((err) => {
|
||||
// Receives the original error.
|
||||
strictEqual(err, testError);
|
||||
assert.strictEqual(err, testError);
|
||||
onerrorCalled = true;
|
||||
});
|
||||
|
||||
stream.destroy(testError);
|
||||
|
||||
// The onerror was called synchronously during destroy.
|
||||
strictEqual(onerrorCalled, true);
|
||||
assert.strictEqual(onerrorCalled, true);
|
||||
|
||||
// The stream.closed rejects with the original error.
|
||||
await rejects(stream.closed, testError);
|
||||
await assert.rejects(stream.closed, testError);
|
||||
}
|
||||
|
||||
// The stream.onerror not called when destroy() has no error.
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { ok, rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -24,11 +22,11 @@ const transportParams = { maxIdleTimeout: 1 };
|
||||
// The SuppressedError is thrown via process.nextTick after the
|
||||
// onerror promise rejects, so it appears as an uncaught exception.
|
||||
process.on('uncaughtException', mustCall((err) => {
|
||||
ok(err instanceof SuppressedError);
|
||||
assert.ok(err instanceof SuppressedError);
|
||||
// .error is the onerror rejection reason
|
||||
strictEqual(err.error, onerrorRejection);
|
||||
assert.strictEqual(err.error, onerrorRejection);
|
||||
// .suppressed is the original error that triggered destroy
|
||||
strictEqual(err.suppressed, originalError);
|
||||
assert.strictEqual(err.suppressed, originalError);
|
||||
}));
|
||||
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
@@ -48,6 +46,6 @@ clientSession.onerror = mustCall(async () => {
|
||||
clientSession.destroy(originalError);
|
||||
|
||||
// Closed rejects with the original error (not the SuppressedError).
|
||||
await rejects(clientSession.closed, originalError);
|
||||
await assert.rejects(clientSession.closed, originalError);
|
||||
|
||||
await serverEndpoint.close();
|
||||
@@ -10,8 +10,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { ok, rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -26,11 +24,11 @@ const transportParams = { maxIdleTimeout: 1 };
|
||||
// The SuppressedError is thrown via process.nextTick, so it appears
|
||||
// as an uncaught exception.
|
||||
process.on('uncaughtException', mustCall((err) => {
|
||||
ok(err instanceof SuppressedError);
|
||||
assert.ok(err instanceof SuppressedError);
|
||||
// .error is the onerror failure
|
||||
strictEqual(err.error, onerrorError);
|
||||
assert.strictEqual(err.error, onerrorError);
|
||||
// .suppressed is the original error that triggered destroy
|
||||
strictEqual(err.suppressed, originalError);
|
||||
assert.strictEqual(err.suppressed, originalError);
|
||||
}));
|
||||
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
@@ -49,5 +47,5 @@ clientSession.onerror = mustCall(() => {
|
||||
clientSession.destroy(originalError);
|
||||
|
||||
// Closed rejects with the original error (not the SuppressedError).
|
||||
await rejects(clientSession.closed, originalError);
|
||||
await assert.rejects(clientSession.closed, originalError);
|
||||
await serverEndpoint.close();
|
||||
@@ -7,8 +7,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -26,7 +24,7 @@ for (const cc of ['reno', 'cubic', 'bbr']) {
|
||||
const serverEndpoint = await listen(mustCall((serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
const data = await bytes(stream);
|
||||
strictEqual(data.byteLength, payloadLength);
|
||||
assert.strictEqual(data.byteLength, payloadLength);
|
||||
stream.writer.endSync();
|
||||
await stream.closed;
|
||||
serverSession.close();
|
||||
@@ -45,7 +43,7 @@ for (const cc of ['reno', 'cubic', 'bbr']) {
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
|
||||
// Verify the session stats show congestion control was active.
|
||||
ok(clientSession.stats.cwnd > 0n, `${cc}: cwnd should be > 0`);
|
||||
assert.ok(clientSession.stats.cwnd > 0n, `${cc}: cwnd should be > 0`);
|
||||
|
||||
await clientSession.closed;
|
||||
await serverEndpoint.close();
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -45,7 +43,7 @@ for (let i = 0; i < numClients; i++) {
|
||||
body: encoder.encode(message),
|
||||
});
|
||||
const received = await bytes(stream);
|
||||
strictEqual(new TextDecoder().decode(received), message);
|
||||
assert.strictEqual(new TextDecoder().decode(received), message);
|
||||
await stream.closed;
|
||||
cs.close();
|
||||
await cs.closed;
|
||||
|
||||
@@ -9,9 +9,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,19 +16,19 @@ if (!hasQuic) {
|
||||
const { listen, connect, QuicEndpoint } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
// Create endpoint with maxConnectionsTotal = 1.
|
||||
const endpoint = new QuicEndpoint({ maxConnectionsTotal: 1 });
|
||||
|
||||
// Verify the limits are readable and mutable.
|
||||
strictEqual(endpoint.maxConnectionsTotal, 1);
|
||||
assert.strictEqual(endpoint.maxConnectionsTotal, 1);
|
||||
// The default maxConnectionsPerHost is 100 — a non-zero default that
|
||||
// prevents a single host from exhausting server resources.
|
||||
strictEqual(endpoint.maxConnectionsPerHost, 100);
|
||||
assert.strictEqual(endpoint.maxConnectionsPerHost, 100);
|
||||
endpoint.maxConnectionsPerHost = 50;
|
||||
strictEqual(endpoint.maxConnectionsPerHost, 50);
|
||||
assert.strictEqual(endpoint.maxConnectionsPerHost, 50);
|
||||
endpoint.maxConnectionsPerHost = 0;
|
||||
|
||||
let sessionCount = 0;
|
||||
@@ -60,21 +57,21 @@ const cs2 = await connect(serverEndpoint.address, {
|
||||
verifyPeer: 'manual',
|
||||
transportParams: { maxIdleTimeout: 1 },
|
||||
onerror: mustCall((err) => {
|
||||
strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
|
||||
assert.strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
|
||||
}),
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
rejects(cs2.opened, {
|
||||
assert.rejects(cs2.opened, {
|
||||
code: 'ERR_QUIC_TRANSPORT_ERROR',
|
||||
}),
|
||||
rejects(cs2.closed, {
|
||||
assert.rejects(cs2.closed, {
|
||||
code: 'ERR_QUIC_TRANSPORT_ERROR',
|
||||
}),
|
||||
]);
|
||||
|
||||
// Only 1 session should have been accepted by the server.
|
||||
strictEqual(sessionCount, 1);
|
||||
assert.strictEqual(sessionCount, 1);
|
||||
|
||||
await cs1.close();
|
||||
await serverEndpoint.close();
|
||||
@@ -9,8 +9,6 @@
|
||||
import { hasQuic, skip, mustCall, mustCallAtLeast } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { notStrictEqual, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -32,7 +30,7 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
ondatagramstatus: mustCallAtLeast((id, status) => {
|
||||
if (status === 'abandoned') {
|
||||
strictEqual(id, ids[0]);
|
||||
assert.strictEqual(id, ids[0]);
|
||||
abandoned = true;
|
||||
}
|
||||
// We'll likely only get status for one other datagram.
|
||||
@@ -49,13 +47,13 @@ ids[0] = await clientSession.sendDatagram(new Uint8Array([1]));
|
||||
ids[1] = await clientSession.sendDatagram(new Uint8Array([2]));
|
||||
ids[2] = await clientSession.sendDatagram(new Uint8Array([3]));
|
||||
|
||||
notStrictEqual(ids[0], 0n);
|
||||
notStrictEqual(ids[1], 0n);
|
||||
notStrictEqual(ids[2], 0n);
|
||||
assert.notStrictEqual(ids[0], 0n);
|
||||
assert.notStrictEqual(ids[1], 0n);
|
||||
assert.notStrictEqual(ids[2], 0n);
|
||||
|
||||
// The abandoned status fires synchronously during sendDatagram when the
|
||||
// queue overflows. It should already be set
|
||||
strictEqual(abandoned, true);
|
||||
assert.strictEqual(abandoned, true);
|
||||
|
||||
await Promise.all([
|
||||
serverSession.close(),
|
||||
|
||||
@@ -9,9 +9,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,8 +16,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const allReceived = Promise.withResolvers();
|
||||
const allStatusReceived = Promise.withResolvers();
|
||||
@@ -39,9 +36,9 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
ondatagram: mustCall(function(data, early) {
|
||||
// We should only receive datagrams 1 and 2
|
||||
strictEqual(data.length, 1);
|
||||
ok(data[0] === 0 || data[0] === 1);
|
||||
ok(!early);
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.ok(data[0] === 0 || data[0] === 1);
|
||||
assert.ok(!early);
|
||||
if (++serverCounter === 2) allReceived.resolve();
|
||||
}, 2),
|
||||
});
|
||||
@@ -76,8 +73,8 @@ for (let i = 0; i < 5; i++) {
|
||||
await Promise.all([allReceived.promise, allStatusReceived.promise]);
|
||||
|
||||
// 3 abandoned (datagrams 1, 2, 3) and 2 acknowledged (datagrams 4, 5).
|
||||
strictEqual(clientAbandonCounter, 3);
|
||||
strictEqual(clientAckCounter, 2);
|
||||
assert.strictEqual(clientAbandonCounter, 3);
|
||||
assert.strictEqual(clientAckCounter, 2);
|
||||
|
||||
await clientSession.closed;
|
||||
await serverEndpoint.close();
|
||||
@@ -9,9 +9,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,8 +16,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const allReceived = Promise.withResolvers();
|
||||
const allStatusReceived = Promise.withResolvers();
|
||||
@@ -39,9 +36,9 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
ondatagram: mustCall(function(data, early) {
|
||||
// With drop-oldest, the queue keeps the newest. After 5 sends with
|
||||
// queue size 2, only datagrams 4 and 5 (values 3 and 4) remain.
|
||||
strictEqual(data.length, 1);
|
||||
ok(data[0] === 3 || data[0] === 4);
|
||||
ok(!early);
|
||||
assert.strictEqual(data.length, 1);
|
||||
assert.ok(data[0] === 3 || data[0] === 4);
|
||||
assert.ok(!early);
|
||||
if (++serverCounter === 2) allReceived.resolve();
|
||||
}, 2),
|
||||
});
|
||||
@@ -77,8 +74,8 @@ for (let i = 0; i < 5; i++) {
|
||||
await Promise.all([allReceived.promise, allStatusReceived.promise]);
|
||||
|
||||
// 3 abandoned (datagrams 1, 2, 3) and 2 acknowledged (datagrams 4, 5).
|
||||
strictEqual(clientAbandonCounter, 3);
|
||||
strictEqual(clientAckCounter, 2);
|
||||
assert.strictEqual(clientAbandonCounter, 3);
|
||||
assert.strictEqual(clientAckCounter, 2);
|
||||
|
||||
await clientSession.closed;
|
||||
await serverEndpoint.close();
|
||||
@@ -10,9 +10,6 @@ import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
const { setTimeout } = await import('node:timers/promises');
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -20,8 +17,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const serverGot = Promise.withResolvers();
|
||||
const clientGot = Promise.withResolvers();
|
||||
@@ -39,8 +36,8 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
// The sendDatagram call happens inside ondatagram (ngtcp2 callback
|
||||
// scope). The datagram is queued and flushed by SendPendingData.
|
||||
ondatagram: mustCall((data, early, session) => {
|
||||
ok(data instanceof Uint8Array);
|
||||
ok(!early);
|
||||
assert.ok(data instanceof Uint8Array);
|
||||
assert.ok(!early);
|
||||
session.sendDatagram(data);
|
||||
serverGot.resolve();
|
||||
}),
|
||||
@@ -52,11 +49,11 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
transportParams: { maxDatagramFrameSize: 10 },
|
||||
// Client receives datagram from server.
|
||||
ondatagram: mustCall(function(data) {
|
||||
ok(data instanceof Uint8Array);
|
||||
strictEqual(data.byteLength, 3);
|
||||
strictEqual(data[0], 10);
|
||||
strictEqual(data[1], 20);
|
||||
strictEqual(data[2], 30);
|
||||
assert.ok(data instanceof Uint8Array);
|
||||
assert.strictEqual(data.byteLength, 3);
|
||||
assert.strictEqual(data[0], 10);
|
||||
assert.strictEqual(data[1], 20);
|
||||
assert.strictEqual(data[2], 30);
|
||||
clientGot.resolve();
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -9,8 +9,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import { setTimeout } from 'node:timers/promises';
|
||||
|
||||
const { strictEqual, notStrictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -32,11 +30,11 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
|
||||
// Zero-length ArrayBufferView
|
||||
const zeroId = await clientSession.sendDatagram(new Uint8Array(0));
|
||||
strictEqual(zeroId, 0n);
|
||||
assert.strictEqual(zeroId, 0n);
|
||||
|
||||
// Zero-length string
|
||||
const emptyStringId = await clientSession.sendDatagram('');
|
||||
strictEqual(emptyStringId, 0n);
|
||||
assert.strictEqual(emptyStringId, 0n);
|
||||
|
||||
await clientSession.close();
|
||||
await serverEndpoint.close();
|
||||
@@ -57,11 +55,11 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
await clientSession.opened;
|
||||
|
||||
// maxDatagramSize reflects the peer's (server's) transport param.
|
||||
strictEqual(clientSession.maxDatagramSize, 0);
|
||||
assert.strictEqual(clientSession.maxDatagramSize, 0);
|
||||
|
||||
// Sending returns 0n immediately — datagram not sent.
|
||||
const id = await clientSession.sendDatagram(new Uint8Array([1, 2, 3]));
|
||||
strictEqual(id, 0n);
|
||||
assert.strictEqual(id, 0n);
|
||||
|
||||
await clientSession.close();
|
||||
await serverEndpoint.close();
|
||||
@@ -86,7 +84,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
|
||||
// Send a datagram even though the server has no ondatagram handler.
|
||||
const id = await clientSession.sendDatagram(new Uint8Array([1, 2, 3]));
|
||||
notStrictEqual(id, 0n);
|
||||
assert.notStrictEqual(id, 0n);
|
||||
|
||||
await clientSession.closed;
|
||||
await serverEndpoint.close();
|
||||
|
||||
@@ -9,9 +9,6 @@ import { hasQuic, skip, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { rejects } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,8 +16,8 @@ if (!hasQuic) {
|
||||
const { listen } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const sni = { '*': { keys: [key], certs: [cert] } };
|
||||
const alpn = ['quic-test'];
|
||||
|
||||
@@ -40,7 +37,7 @@ const invalid = [
|
||||
|
||||
for (const maxDatagramFrameSize of invalid) {
|
||||
const transportParams = { maxDatagramFrameSize };
|
||||
await rejects(
|
||||
await assert.rejects(
|
||||
listen(mustNotCall(), { sni, alpn, transportParams }),
|
||||
{ code: 'ERR_INVALID_ARG_VALUE' },
|
||||
`listen should reject maxDatagramFrameSize: ${maxDatagramFrameSize}`,
|
||||
|
||||
@@ -11,9 +11,6 @@ import { hasQuic, skip, mustCall, mustCallAtLeast } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { ok } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -22,8 +19,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const numDatagrams = 5;
|
||||
let serverDatagramCount = 0;
|
||||
@@ -48,7 +45,7 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
alpn: ['quic-test'],
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
ondatagram: mustCallAtLeast((data) => {
|
||||
ok(data instanceof Uint8Array);
|
||||
assert.ok(data instanceof Uint8Array);
|
||||
serverDatagramCount++;
|
||||
gotSomeDg.resolve();
|
||||
}),
|
||||
@@ -79,7 +76,7 @@ for await (const _ of stream) { /* drain */ } // eslint-disable-line no-unused-v
|
||||
await stream.closed;
|
||||
|
||||
// At least some datagrams should have arrived.
|
||||
ok(serverDatagramCount > 0, 'Server should have received at least one datagram');
|
||||
assert.ok(serverDatagramCount > 0, 'Server should have received at least one datagram');
|
||||
|
||||
await clientSession.closed;
|
||||
await serverEndpoint.close();
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual, deepStrictEqual, notStrictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -40,21 +38,19 @@ await clientSession.opened;
|
||||
const source = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
|
||||
const firstId = await clientSession.sendDatagram(source);
|
||||
notStrictEqual(firstId, 0n);
|
||||
strictEqual(source.buffer.detached, false,
|
||||
'source ArrayBuffer must not be detached after sendDatagram');
|
||||
assert.notStrictEqual(firstId, 0n);
|
||||
assert.strictEqual(source.buffer.detached, false); // source ArrayBuffer must not be detached after sendDatagram
|
||||
|
||||
const secondId = await clientSession.sendDatagram(source);
|
||||
notStrictEqual(secondId, 0n);
|
||||
strictEqual(source.buffer.detached, false,
|
||||
'source ArrayBuffer must remain live after second sendDatagram');
|
||||
assert.notStrictEqual(secondId, 0n);
|
||||
assert.strictEqual(source.buffer.detached, false); // source ArrayBuffer must remain live after second sendDatagram
|
||||
|
||||
// Mutating the source after the previous sendDatagram returned must
|
||||
// not affect what the peer ultimately receives — the bytes have
|
||||
// already been copied into the QUIC layer's internal buffer.
|
||||
source[0] = 99;
|
||||
const thirdId = await clientSession.sendDatagram(source);
|
||||
notStrictEqual(thirdId, 0n);
|
||||
assert.notStrictEqual(thirdId, 0n);
|
||||
|
||||
await allReceived.promise;
|
||||
|
||||
@@ -66,7 +62,7 @@ const expected = [
|
||||
Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]).toString('hex'),
|
||||
Buffer.from([99, 2, 3, 4, 5, 6, 7, 8]).toString('hex'),
|
||||
].sort();
|
||||
deepStrictEqual(sorted, expected);
|
||||
assert.deepStrictEqual(sorted, expected);
|
||||
|
||||
await clientSession.closed;
|
||||
await serverEndpoint.close();
|
||||
@@ -15,8 +15,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { ok, strictEqual, notStrictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -32,7 +30,7 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
}), {
|
||||
transportParams: { maxDatagramFrameSize: 200 },
|
||||
ondatagram: mustCall((data) => {
|
||||
ok(data instanceof Uint8Array);
|
||||
assert.ok(data instanceof Uint8Array);
|
||||
serverGot.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -46,19 +44,19 @@ const maxSize = clientSession.maxDatagramSize;
|
||||
|
||||
// maxDatagramSize should be less than maxDatagramFrameSize due to
|
||||
// the DATAGRAM frame overhead (1 byte type + varint length encoding).
|
||||
ok(maxSize > 0);
|
||||
ok(maxSize < 200);
|
||||
assert.ok(maxSize > 0);
|
||||
assert.ok(maxSize < 200);
|
||||
|
||||
// DGRAM-03 / DGIMP-10: Datagram too large — returns 0n.
|
||||
const oversized = new Uint8Array(maxSize + 1);
|
||||
const tooLargeId = await clientSession.sendDatagram(oversized);
|
||||
strictEqual(tooLargeId, 0n);
|
||||
assert.strictEqual(tooLargeId, 0n);
|
||||
|
||||
// Datagram at exactly maxDatagramSize — accepted and delivered.
|
||||
const exactMax = new Uint8Array(maxSize);
|
||||
exactMax[0] = 42;
|
||||
const exactId = await clientSession.sendDatagram(exactMax);
|
||||
notStrictEqual(exactId, 0n);
|
||||
assert.notStrictEqual(exactId, 0n);
|
||||
|
||||
await Promise.all([serverGot.promise, clientSession.closed]);
|
||||
await serverEndpoint.close();
|
||||
@@ -11,8 +11,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { deepStrictEqual, notStrictEqual, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -42,16 +40,16 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
|
||||
// Send hex-encoded string — '48656c6c6f' is 'Hello' in hex.
|
||||
const hexId = await clientSession.sendDatagram('48656c6c6f', 'hex');
|
||||
notStrictEqual(hexId, 0n);
|
||||
assert.notStrictEqual(hexId, 0n);
|
||||
|
||||
// Send base64-encoded string — 'V29ybGQ=' is 'World' in base64.
|
||||
const b64Id = await clientSession.sendDatagram('V29ybGQ=', 'base64');
|
||||
notStrictEqual(b64Id, 0n);
|
||||
assert.notStrictEqual(b64Id, 0n);
|
||||
|
||||
await allReceived.promise;
|
||||
|
||||
deepStrictEqual(received[0], Buffer.from('Hello'));
|
||||
deepStrictEqual(received[1], Buffer.from('World'));
|
||||
assert.deepStrictEqual(received[0], Buffer.from('Hello'));
|
||||
assert.deepStrictEqual(received[1], Buffer.from('World'));
|
||||
|
||||
await clientSession.closed;
|
||||
await serverEndpoint.close();
|
||||
@@ -67,7 +65,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
}), {
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
ondatagram: mustCall((data) => {
|
||||
deepStrictEqual(Buffer.from(data), Buffer.from([42]));
|
||||
assert.deepStrictEqual(Buffer.from(data), Buffer.from([42]));
|
||||
serverGot.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -81,7 +79,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
const promiseId = await clientSession.sendDatagram(
|
||||
Promise.resolve(new Uint8Array([42])),
|
||||
);
|
||||
notStrictEqual(promiseId, 0n);
|
||||
assert.notStrictEqual(promiseId, 0n);
|
||||
|
||||
await Promise.all([serverGot.promise, clientSession.closed]);
|
||||
await serverEndpoint.close();
|
||||
@@ -113,7 +111,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
});
|
||||
|
||||
const id = await clientSession.sendDatagram(slowPromise);
|
||||
strictEqual(id, 0n);
|
||||
assert.strictEqual(id, 0n);
|
||||
|
||||
await serverEndpoint.close();
|
||||
}
|
||||
@@ -128,7 +126,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
}), {
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
ondatagram: mustCall((data) => {
|
||||
deepStrictEqual(Buffer.from(data), Buffer.from([10, 20, 30]));
|
||||
assert.deepStrictEqual(Buffer.from(data), Buffer.from([10, 20, 30]));
|
||||
serverGot.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -146,10 +144,10 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
view[2] = 30;
|
||||
|
||||
const id = await clientSession.sendDatagram(view);
|
||||
notStrictEqual(id, 0n);
|
||||
assert.notStrictEqual(id, 0n);
|
||||
|
||||
// The SharedArrayBuffer should still be usable (copied, not transferred).
|
||||
strictEqual(view[0], 10);
|
||||
assert.strictEqual(view[0], 10);
|
||||
|
||||
await Promise.all([serverGot.promise, clientSession.closed]);
|
||||
await serverEndpoint.close();
|
||||
@@ -166,7 +164,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
ondatagram: mustCall((data) => {
|
||||
// The received data should match the slice content.
|
||||
deepStrictEqual(Buffer.from(data), Buffer.from('hello'));
|
||||
assert.deepStrictEqual(Buffer.from(data), Buffer.from('hello'));
|
||||
serverGot.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -180,7 +178,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
// ArrayBuffer is larger and the view has a non-zero offset.
|
||||
const pooledBuf = Buffer.from('hello');
|
||||
const id = await clientSession.sendDatagram(pooledBuf);
|
||||
notStrictEqual(id, 0n);
|
||||
assert.notStrictEqual(id, 0n);
|
||||
|
||||
await Promise.all([serverGot.promise, clientSession.closed]);
|
||||
await serverEndpoint.close();
|
||||
@@ -196,7 +194,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
}), {
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
ondatagram: mustCall((data) => {
|
||||
deepStrictEqual(Buffer.from(data), Buffer.from([0xCA, 0xFE]));
|
||||
assert.deepStrictEqual(Buffer.from(data), Buffer.from([0xCA, 0xFE]));
|
||||
serverGot.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -213,7 +211,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
// DataView over bytes [2, 3] of the buffer.
|
||||
const dv = new DataView(ab, 2, 2);
|
||||
const id = await clientSession.sendDatagram(dv);
|
||||
notStrictEqual(id, 0n);
|
||||
assert.notStrictEqual(id, 0n);
|
||||
|
||||
await Promise.all([serverGot.promise, clientSession.closed]);
|
||||
await serverEndpoint.close();
|
||||
|
||||
@@ -9,9 +9,6 @@ import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
const { setTimeout } = await import('node:timers/promises');
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,8 +16,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const serverGot = Promise.withResolvers();
|
||||
const statusReceived = Promise.withResolvers();
|
||||
@@ -48,9 +45,9 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
verifyPeer: 'manual',
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
ondatagramstatus: mustCall((id, status) => {
|
||||
strictEqual(typeof id, 'bigint');
|
||||
strictEqual(typeof status, 'string');
|
||||
ok(
|
||||
assert.strictEqual(typeof id, 'bigint');
|
||||
assert.strictEqual(typeof status, 'string');
|
||||
assert.ok(
|
||||
status === 'acknowledged' || status === 'lost' || status === 'abandoned',
|
||||
`status should be 'acknowledged', 'lost', or 'abandoned', got '${status}'`,
|
||||
);
|
||||
@@ -68,9 +65,9 @@ const id = await clientSession.sendDatagram(new Uint8Array([1, 2, 3]));
|
||||
await Promise.all([serverGot.promise, statusReceived.promise]);
|
||||
|
||||
// The status callback should have been called with the same ID.
|
||||
strictEqual(statusId, id);
|
||||
assert.strictEqual(statusId, id);
|
||||
// On localhost the datagram should be acknowledged, not lost.
|
||||
strictEqual(statusValue, 'acknowledged');
|
||||
assert.strictEqual(statusValue, 'acknowledged');
|
||||
|
||||
await clientSession.closed;
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { ok, deepStrictEqual, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -27,9 +25,9 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
}), {
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
ondatagram: mustCall((data) => {
|
||||
ok(data instanceof Uint8Array);
|
||||
assert.ok(data instanceof Uint8Array);
|
||||
// Verify the received bytes match the UTF-8 encoding.
|
||||
deepStrictEqual(Buffer.from(data), expected);
|
||||
assert.deepStrictEqual(Buffer.from(data), expected);
|
||||
serverGot.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -40,7 +38,7 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
await clientSession.opened;
|
||||
|
||||
const id = await clientSession.sendDatagram(message);
|
||||
strictEqual(id, 1n);
|
||||
assert.strictEqual(id, 1n);
|
||||
|
||||
await Promise.all([serverGot.promise, clientSession.closed]);
|
||||
await serverEndpoint.close();
|
||||
@@ -8,9 +8,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -18,8 +15,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const serverGot = Promise.withResolvers();
|
||||
|
||||
@@ -27,8 +24,8 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
await serverSession.opened;
|
||||
// maxDatagramSize reflects peer's max payload (frame size
|
||||
// minus DATAGRAM frame overhead of type byte + varint length).
|
||||
ok(serverSession.maxDatagramSize > 0);
|
||||
ok(serverSession.maxDatagramSize < 1200);
|
||||
assert.ok(serverSession.maxDatagramSize > 0);
|
||||
assert.ok(serverSession.maxDatagramSize < 1200);
|
||||
// Wait for the datagram before closing.
|
||||
await serverGot.promise;
|
||||
await serverSession.close();
|
||||
@@ -37,8 +34,8 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
alpn: ['quic-test'],
|
||||
transportParams: { maxDatagramFrameSize: 1200 },
|
||||
ondatagram: mustCall((data) => {
|
||||
ok(data instanceof Uint8Array);
|
||||
strictEqual(data.byteLength, 3);
|
||||
assert.ok(data instanceof Uint8Array);
|
||||
assert.strictEqual(data.byteLength, 3);
|
||||
serverGot.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -52,8 +49,8 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
await clientSession.opened;
|
||||
|
||||
// Client maxDatagramSize reflects actual payload max.
|
||||
ok(clientSession.maxDatagramSize > 0);
|
||||
ok(clientSession.maxDatagramSize < 1200);
|
||||
assert.ok(clientSession.maxDatagramSize > 0);
|
||||
assert.ok(clientSession.maxDatagramSize < 1200);
|
||||
|
||||
// Client sends datagram.
|
||||
const id = await clientSession.sendDatagram(new Uint8Array([1, 2, 3]));
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { ok } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -20,7 +18,7 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
const info = await serverSession.opened;
|
||||
|
||||
// The handshake info should be available.
|
||||
ok(info, 'handshake info should be available');
|
||||
assert.ok(info, 'handshake info should be available');
|
||||
|
||||
await serverSession.closed;
|
||||
}));
|
||||
@@ -31,25 +29,25 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
const info = await clientSession.opened;
|
||||
|
||||
// Verify the handshake completed and we can inspect the session.
|
||||
ok(info, 'handshake info should be available');
|
||||
assert.ok(info, 'handshake info should be available');
|
||||
|
||||
// Check that the session has reasonable default stream limits by
|
||||
// verifying we can create at least one bidirectional and one
|
||||
// unidirectional stream.
|
||||
const bidiStream = await clientSession.createBidirectionalStream();
|
||||
ok(bidiStream, 'should be able to create a bidi stream');
|
||||
assert.ok(bidiStream, 'should be able to create a bidi stream');
|
||||
bidiStream.destroy();
|
||||
|
||||
const uniStream = await clientSession.createUnidirectionalStream();
|
||||
ok(uniStream, 'should be able to create a uni stream');
|
||||
assert.ok(uniStream, 'should be able to create a uni stream');
|
||||
uniStream.destroy();
|
||||
|
||||
// Check the endpoint's maxConnectionsPerHost and maxConnectionsTotal
|
||||
// defaults are either 0 (unlimited) or a reasonable positive number.
|
||||
const maxPerHost = serverEndpoint.maxConnectionsPerHost;
|
||||
const maxTotal = serverEndpoint.maxConnectionsTotal;
|
||||
ok(maxPerHost >= 0, 'maxConnectionsPerHost should be non-negative');
|
||||
ok(maxTotal >= 0, 'maxConnectionsTotal should be non-negative');
|
||||
assert.ok(maxPerHost >= 0, 'maxConnectionsPerHost should be non-negative');
|
||||
assert.ok(maxTotal >= 0, 'maxConnectionsTotal should be non-negative');
|
||||
|
||||
await clientSession.close();
|
||||
await serverEndpoint.close();
|
||||
@@ -8,9 +8,6 @@ import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -18,14 +15,14 @@ if (!hasQuic) {
|
||||
const { listen, QuicEndpoint } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
let busyChangeCount = 0;
|
||||
dc.subscribe('quic.endpoint.busy.change', mustCall((msg) => {
|
||||
busyChangeCount++;
|
||||
ok(msg.endpoint);
|
||||
strictEqual(typeof msg.busy, 'boolean');
|
||||
assert.ok(msg.endpoint);
|
||||
assert.strictEqual(typeof msg.busy, 'boolean');
|
||||
}, 2));
|
||||
|
||||
const endpoint = new QuicEndpoint();
|
||||
@@ -39,6 +36,6 @@ const serverEndpoint = await listen(mustNotCall(), {
|
||||
endpoint.busy = true;
|
||||
endpoint.busy = false;
|
||||
|
||||
strictEqual(busyChangeCount, 2);
|
||||
assert.strictEqual(busyChangeCount, 2);
|
||||
|
||||
await serverEndpoint.close();
|
||||
@@ -7,8 +7,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,9 +17,9 @@ const statusDone = Promise.withResolvers();
|
||||
|
||||
// quic.session.receive.datagram.status fires with status.
|
||||
dc.subscribe('quic.session.receive.datagram.status', mustCall((msg) => {
|
||||
ok(msg.session);
|
||||
ok(msg.id);
|
||||
strictEqual(msg?.status, 'acknowledged');
|
||||
assert.ok(msg.session);
|
||||
assert.ok(msg.id);
|
||||
assert.strictEqual(msg?.status, 'acknowledged');
|
||||
statusDone.resolve();
|
||||
}));
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
|
||||
const { ok } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -20,15 +18,15 @@ const serverGot = Promise.withResolvers();
|
||||
|
||||
// quic.session.send.datagram fires on send.
|
||||
dc.subscribe('quic.session.send.datagram', mustCall((msg) => {
|
||||
ok(msg.session);
|
||||
ok(msg.id);
|
||||
ok(msg.length > 0);
|
||||
assert.ok(msg.session);
|
||||
assert.ok(msg.id);
|
||||
assert.ok(msg.length > 0);
|
||||
}));
|
||||
|
||||
// quic.session.receive.datagram fires on receipt.
|
||||
dc.subscribe('quic.session.receive.datagram', mustCall((msg) => {
|
||||
ok(msg.session);
|
||||
ok(msg.length > 0);
|
||||
assert.ok(msg.session);
|
||||
assert.ok(msg.length > 0);
|
||||
}));
|
||||
|
||||
const serverEndpoint = await listen(async (serverSession) => {
|
||||
|
||||
@@ -9,10 +9,6 @@ import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { readKey } = fixtures;
|
||||
|
||||
const { ok, rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -20,14 +16,14 @@ if (!hasQuic) {
|
||||
const { listen } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const sni = { '*': { keys: [key], certs: [cert] } };
|
||||
const alpn = ['quic-test'];
|
||||
|
||||
dc.subscribe('quic.endpoint.error', mustCall((msg) => {
|
||||
ok(msg.endpoint);
|
||||
ok(msg.error);
|
||||
assert.ok(msg.endpoint);
|
||||
assert.ok(msg.error);
|
||||
}));
|
||||
|
||||
// Create first endpoint to occupy a port.
|
||||
@@ -42,8 +38,8 @@ const ep2 = await listen(mustNotCall(), {
|
||||
});
|
||||
|
||||
// ep2 is destroyed due to bind failure.
|
||||
strictEqual(ep2.destroyed, true);
|
||||
await rejects(ep2.closed, {
|
||||
assert.strictEqual(ep2.destroyed, true);
|
||||
await assert.rejects(ep2.closed, {
|
||||
code: 'ERR_QUIC_ENDPOINT_CLOSED',
|
||||
message: /Bind failure/,
|
||||
});
|
||||
|
||||
@@ -8,8 +8,6 @@ import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
|
||||
const { ok } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -20,15 +18,15 @@ const clientChannelFired = Promise.withResolvers();
|
||||
|
||||
// Subscribe to the path validation diagnostics channel.
|
||||
// Verify the client-side event fires with the correct properties.
|
||||
dc.subscribe('quic.session.path.validation', (msg) => {
|
||||
ok(msg.session, 'message should have session');
|
||||
ok(msg.result, 'message should have result');
|
||||
ok(msg.newLocalAddress, 'message should have newLocalAddress');
|
||||
ok(msg.newRemoteAddress, 'message should have newRemoteAddress');
|
||||
dc.subscribe('quic.session.path.validation', mustCall((msg) => {
|
||||
assert.ok(msg.session, 'message should have session');
|
||||
assert.ok(msg.result, 'message should have result');
|
||||
assert.ok(msg.newLocalAddress, 'message should have newLocalAddress');
|
||||
assert.ok(msg.newRemoteAddress, 'message should have newRemoteAddress');
|
||||
if (msg.preferredAddress === true) {
|
||||
clientChannelFired.resolve();
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
const preferredEndpoint = await listen(mustNotCall(), {
|
||||
onpathvalidation() {},
|
||||
|
||||
@@ -8,8 +8,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -20,15 +18,15 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
let handshakeCount = 0;
|
||||
dc.subscribe('quic.session.handshake', mustCall((msg) => {
|
||||
handshakeCount++;
|
||||
ok(msg.session);
|
||||
assert.ok(msg.session);
|
||||
// The handshake info should include standard TLS fields.
|
||||
strictEqual(typeof msg.protocol, 'string');
|
||||
strictEqual(typeof msg.servername, 'string');
|
||||
assert.strictEqual(typeof msg.protocol, 'string');
|
||||
assert.strictEqual(typeof msg.servername, 'string');
|
||||
}, 2));
|
||||
|
||||
// quic.session.update.key fires on key update.
|
||||
dc.subscribe('quic.session.update.key', mustCall((msg) => {
|
||||
ok(msg.session);
|
||||
assert.ok(msg.session);
|
||||
}));
|
||||
|
||||
const serverEndpoint = await listen(async (serverSession) => {
|
||||
@@ -46,4 +44,4 @@ await clientSession.closed;
|
||||
await serverEndpoint.close();
|
||||
|
||||
// Both client and server handshakes should have fired.
|
||||
strictEqual(handshakeCount, 2);
|
||||
assert.strictEqual(handshakeCount, 2);
|
||||
@@ -10,8 +10,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -23,23 +21,23 @@ const encoder = new TextEncoder();
|
||||
|
||||
// Fires when the client creates a stream.
|
||||
dc.subscribe('quic.session.open.stream', mustCall((msg) => {
|
||||
ok(msg.stream);
|
||||
ok(msg.session);
|
||||
strictEqual(msg.direction, 'bidi', 'open.stream direction should be bidi');
|
||||
assert.ok(msg.stream);
|
||||
assert.ok(msg.session);
|
||||
assert.strictEqual(msg.direction, 'bidi'); // open.stream direction should be bidi
|
||||
}));
|
||||
|
||||
// Fires when the server receives a stream.
|
||||
dc.subscribe('quic.session.received.stream', mustCall((msg) => {
|
||||
ok(msg.stream);
|
||||
ok(msg.session);
|
||||
strictEqual(msg.direction, 'bidi', 'received.stream direction should be bidi');
|
||||
assert.ok(msg.stream);
|
||||
assert.ok(msg.session);
|
||||
assert.strictEqual(msg.direction, 'bidi'); // received.stream direction should be bidi
|
||||
}));
|
||||
|
||||
// Fires when a stream is destroyed.
|
||||
dc.subscribe('quic.stream.closed', mustCall((msg) => {
|
||||
ok(msg.stream);
|
||||
ok(msg.session);
|
||||
ok(msg.stats, 'stream.closed should include stats');
|
||||
assert.ok(msg.stream);
|
||||
assert.ok(msg.session);
|
||||
assert.ok(msg.stats, 'stream.closed should include stats');
|
||||
}, 2));
|
||||
|
||||
const serverDone = Promise.withResolvers();
|
||||
|
||||
@@ -8,8 +8,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
|
||||
const { ok } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -26,17 +24,17 @@ function checkDone() {
|
||||
|
||||
// quic.session.ticket fires when session ticket received.
|
||||
dc.subscribe('quic.session.ticket', mustCall((msg) => {
|
||||
ok(msg.session);
|
||||
ok(msg.ticket);
|
||||
assert.ok(msg.session);
|
||||
assert.ok(msg.ticket);
|
||||
ticketFired = true;
|
||||
checkDone();
|
||||
}));
|
||||
|
||||
// quic.session.new.token fires when NEW_TOKEN received.
|
||||
dc.subscribe('quic.session.new.token', mustCall((msg) => {
|
||||
ok(msg.session);
|
||||
ok(msg.token);
|
||||
ok(msg.address);
|
||||
assert.ok(msg.session);
|
||||
assert.ok(msg.token);
|
||||
assert.ok(msg.address);
|
||||
tokenFired = true;
|
||||
checkDone();
|
||||
}));
|
||||
@@ -46,8 +44,8 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
}));
|
||||
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
onsessionticket: mustCall((ticket) => { ok(ticket); }),
|
||||
onnewtoken: mustCall((token) => { ok(token); }),
|
||||
onsessionticket: mustCall((ticket) => { assert.ok(ticket); }),
|
||||
onnewtoken: mustCall((token) => { assert.ok(token); }),
|
||||
});
|
||||
await Promise.all([clientSession.opened, allDone.promise]);
|
||||
await clientSession.close();
|
||||
|
||||
@@ -14,8 +14,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
|
||||
const { ok } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -27,47 +25,47 @@ const events = [];
|
||||
// endpoint.created fires for both server and client endpoints.
|
||||
dc.subscribe('quic.endpoint.created', mustCall((msg) => {
|
||||
events.push('endpoint.created');
|
||||
ok(msg.endpoint);
|
||||
assert.ok(msg.endpoint);
|
||||
}, 2));
|
||||
|
||||
// endpoint.listen fires once (server only).
|
||||
dc.subscribe('quic.endpoint.listen', mustCall((msg) => {
|
||||
events.push('endpoint.listen');
|
||||
ok(msg.endpoint);
|
||||
assert.ok(msg.endpoint);
|
||||
}));
|
||||
|
||||
// endpoint.closing fires once (server endpoint closes).
|
||||
dc.subscribe('quic.endpoint.closing', mustCall((msg) => {
|
||||
events.push('endpoint.closing');
|
||||
ok(msg.endpoint);
|
||||
assert.ok(msg.endpoint);
|
||||
}));
|
||||
|
||||
// endpoint.closed fires once (server endpoint closed).
|
||||
dc.subscribe('quic.endpoint.closed', mustCall((msg) => {
|
||||
events.push('endpoint.closed');
|
||||
ok(msg.endpoint);
|
||||
ok(msg.stats, 'endpoint.closed should include stats');
|
||||
assert.ok(msg.endpoint);
|
||||
assert.ok(msg.stats, 'endpoint.closed should include stats');
|
||||
}));
|
||||
|
||||
// endpoint.connect fires before a client session is created.
|
||||
dc.subscribe('quic.endpoint.connect', mustCall((msg) => {
|
||||
events.push('endpoint.connect');
|
||||
ok(msg.endpoint);
|
||||
ok(msg.address);
|
||||
ok(msg.options);
|
||||
assert.ok(msg.endpoint);
|
||||
assert.ok(msg.address);
|
||||
assert.ok(msg.options);
|
||||
}));
|
||||
|
||||
// session.created.client fires for the client session.
|
||||
dc.subscribe('quic.session.created.client', mustCall((msg) => {
|
||||
events.push('session.created.client');
|
||||
ok(msg.session);
|
||||
assert.ok(msg.session);
|
||||
}));
|
||||
|
||||
// session.created.server fires for the server session.
|
||||
dc.subscribe('quic.session.created.server', mustCall((msg) => {
|
||||
events.push('session.created.server');
|
||||
ok(msg.session);
|
||||
ok(msg.address, 'server session should include remote address');
|
||||
assert.ok(msg.session);
|
||||
assert.ok(msg.address, 'server session should include remote address');
|
||||
}));
|
||||
|
||||
// session.closing fires when session.close() is called.
|
||||
@@ -75,14 +73,14 @@ dc.subscribe('quic.session.created.server', mustCall((msg) => {
|
||||
// The client session closes via CONNECTION_CLOSE without going through close().
|
||||
dc.subscribe('quic.session.closing', mustCall((msg) => {
|
||||
events.push('session.closing');
|
||||
ok(msg.session);
|
||||
assert.ok(msg.session);
|
||||
}));
|
||||
|
||||
// session.closed fires when session is fully closed.
|
||||
dc.subscribe('quic.session.closed', mustCall((msg) => {
|
||||
events.push('session.closed');
|
||||
ok(msg.session);
|
||||
ok(msg.stats, 'session.closed should include stats');
|
||||
assert.ok(msg.session);
|
||||
assert.ok(msg.stats, 'session.closed should include stats');
|
||||
}, 2));
|
||||
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
@@ -97,10 +95,10 @@ await Promise.all([clientSession.opened, clientSession.closed]);
|
||||
await serverEndpoint.close();
|
||||
|
||||
// Verify key events occurred.
|
||||
ok(events.includes('endpoint.created'), 'missing endpoint.created');
|
||||
ok(events.includes('endpoint.listen'), 'missing endpoint.listen');
|
||||
ok(events.includes('endpoint.connect'), 'missing endpoint.connect');
|
||||
ok(events.includes('session.created.client'), 'missing session.created.client');
|
||||
ok(events.includes('session.created.server'), 'missing session.created.server');
|
||||
ok(events.includes('endpoint.closing'), 'missing endpoint.closing');
|
||||
ok(events.includes('endpoint.closed'), 'missing endpoint.closed');
|
||||
assert.ok(events.includes('endpoint.created'), 'missing endpoint.created');
|
||||
assert.ok(events.includes('endpoint.listen'), 'missing endpoint.listen');
|
||||
assert.ok(events.includes('endpoint.connect'), 'missing endpoint.connect');
|
||||
assert.ok(events.includes('session.created.client'), 'missing session.created.client');
|
||||
assert.ok(events.includes('session.created.server'), 'missing session.created.server');
|
||||
assert.ok(events.includes('endpoint.closing'), 'missing endpoint.closing');
|
||||
assert.ok(events.includes('endpoint.closed'), 'missing endpoint.closed');
|
||||
@@ -9,8 +9,6 @@
|
||||
import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { ok } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -36,7 +34,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
// With 3x PTO on localhost (~1-4ms RTT), the draining period should
|
||||
// be well under 1 second. The idle timeout is 10 seconds. If the
|
||||
// draining period fix is working, elapsed should be much less than 10s.
|
||||
ok(elapsed < 2000, `Expected draining to complete in < 2s, took ${elapsed}ms`);
|
||||
assert.ok(elapsed < 2000, `Expected draining to complete in < 2s, took ${elapsed}ms`);
|
||||
|
||||
await serverEndpoint.close();
|
||||
}
|
||||
@@ -58,7 +56,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
const elapsed = Date.now() - start;
|
||||
|
||||
// 10x PTO is still very short on localhost. Should complete promptly.
|
||||
ok(elapsed < 2000, `Expected draining to complete in < 2s, took ${elapsed}ms`);
|
||||
assert.ok(elapsed < 2000, `Expected draining to complete in < 2s, took ${elapsed}ms`);
|
||||
|
||||
await serverEndpoint.close();
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -30,18 +28,18 @@ await clientSession.opened;
|
||||
clientSession.close();
|
||||
|
||||
// Creating a stream on a closing session rejects.
|
||||
await rejects(
|
||||
await assert.rejects(
|
||||
clientSession.createBidirectionalStream(),
|
||||
{ code: 'ERR_INVALID_STATE' },
|
||||
);
|
||||
|
||||
await rejects(
|
||||
await assert.rejects(
|
||||
clientSession.createUnidirectionalStream(),
|
||||
{ code: 'ERR_INVALID_STATE' },
|
||||
);
|
||||
|
||||
// sendDatagram on a closing session throws.
|
||||
await rejects(
|
||||
await assert.rejects(
|
||||
clientSession.sendDatagram(new Uint8Array([1, 2, 3])),
|
||||
{ code: 'ERR_INVALID_STATE' },
|
||||
);
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -26,7 +24,7 @@ const stream = await clientSession.createBidirectionalStream();
|
||||
|
||||
// Destroy the stream, then try operations on it.
|
||||
stream.destroy();
|
||||
strictEqual(stream.destroyed, true);
|
||||
assert.strictEqual(stream.destroyed, true);
|
||||
|
||||
// Operations on destroyed stream should not throw.
|
||||
stream.destroy(); // Idempotent.
|
||||
@@ -34,20 +32,20 @@ stream.writer.endSync(); // No-op on destroyed.
|
||||
|
||||
// Destroy the session, then try operations on it.
|
||||
clientSession.destroy();
|
||||
strictEqual(clientSession.destroyed, true);
|
||||
assert.strictEqual(clientSession.destroyed, true);
|
||||
|
||||
// Properties should return null/undefined gracefully.
|
||||
strictEqual(clientSession.endpoint, null);
|
||||
strictEqual(clientSession.path, undefined);
|
||||
strictEqual(clientSession.certificate, undefined);
|
||||
strictEqual(clientSession.peerCertificate, undefined);
|
||||
strictEqual(clientSession.ephemeralKeyInfo, undefined);
|
||||
assert.strictEqual(clientSession.endpoint, null);
|
||||
assert.strictEqual(clientSession.path, undefined);
|
||||
assert.strictEqual(clientSession.certificate, undefined);
|
||||
assert.strictEqual(clientSession.peerCertificate, undefined);
|
||||
assert.strictEqual(clientSession.ephemeralKeyInfo, undefined);
|
||||
|
||||
// destroy() again is idempotent.
|
||||
clientSession.destroy();
|
||||
|
||||
// sendDatagram on destroyed session throws ERR_INVALID_STATE.
|
||||
await rejects(
|
||||
await assert.rejects(
|
||||
clientSession.sendDatagram(new Uint8Array([1])),
|
||||
{ code: 'ERR_INVALID_STATE' },
|
||||
);
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -43,8 +41,8 @@ await stream.closed;
|
||||
// Close the endpoint while the server session is still active
|
||||
// (the session is open but the stream is done).
|
||||
serverEndpoint.close();
|
||||
strictEqual(serverEndpoint.closing, true);
|
||||
strictEqual(serverEndpoint.destroyed, false);
|
||||
assert.strictEqual(serverEndpoint.closing, true);
|
||||
assert.strictEqual(serverEndpoint.destroyed, false);
|
||||
|
||||
// The endpoint is waiting for the server session. Close the
|
||||
// client session to trigger the server session to close.
|
||||
@@ -52,4 +50,4 @@ await clientSession.close();
|
||||
|
||||
// The server session should close from the CONNECTION_CLOSE.
|
||||
await Promise.all([serverDone.promise, serverEndpoint.closed]);
|
||||
strictEqual(serverEndpoint.destroyed, true);
|
||||
assert.strictEqual(serverEndpoint.destroyed, true);
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -37,17 +35,17 @@ await stream.closed;
|
||||
// Double close() on session — both return the same promise.
|
||||
const p1 = clientSession.close();
|
||||
const p2 = clientSession.close();
|
||||
strictEqual(p1, p2);
|
||||
assert.strictEqual(p1, p2);
|
||||
await clientSession.closed;
|
||||
|
||||
// Double destroy() — second call is no-op.
|
||||
clientSession.destroy();
|
||||
strictEqual(clientSession.destroyed, true);
|
||||
assert.strictEqual(clientSession.destroyed, true);
|
||||
clientSession.destroy(); // Should not throw.
|
||||
strictEqual(clientSession.destroyed, true);
|
||||
assert.strictEqual(clientSession.destroyed, true);
|
||||
|
||||
// Double close() on endpoint.
|
||||
const ep1 = serverEndpoint.close();
|
||||
const ep2 = serverEndpoint.close();
|
||||
strictEqual(ep1, ep2);
|
||||
assert.strictEqual(ep1, ep2);
|
||||
await serverEndpoint.closed;
|
||||
@@ -7,8 +7,6 @@
|
||||
import { hasQuic, skip, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -28,7 +26,7 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
// Destroy immediately without waiting for opened.
|
||||
clientSession.destroy();
|
||||
|
||||
strictEqual(clientSession.destroyed, true);
|
||||
assert.strictEqual(clientSession.destroyed, true);
|
||||
|
||||
// Opened may reject (session destroyed before handshake completed)
|
||||
// or resolve if handshake completed fast enough.
|
||||
|
||||
@@ -4,9 +4,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -14,11 +11,11 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
// enableEarlyData must be a boolean
|
||||
await rejects(connect({ port: 1234 }, {
|
||||
await assert.rejects(connect({ port: 1234 }, {
|
||||
alpn: 'quic-test',
|
||||
enableEarlyData: 'yes',
|
||||
}), {
|
||||
@@ -50,8 +47,8 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
enableEarlyData: false,
|
||||
});
|
||||
clientSession.opened.then(mustCall((info) => {
|
||||
strictEqual(info.earlyDataAttempted, false);
|
||||
strictEqual(info.earlyDataAccepted, false);
|
||||
assert.strictEqual(info.earlyDataAttempted, false);
|
||||
assert.strictEqual(info.earlyDataAccepted, false);
|
||||
clientOpened.resolve();
|
||||
}));
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -27,13 +25,13 @@ const clientSession = await connect(serverEndpoint.address);
|
||||
await clientSession.opened;
|
||||
|
||||
// session[Symbol.asyncDispose] closes the session.
|
||||
strictEqual(typeof clientSession[Symbol.asyncDispose], 'function');
|
||||
assert.strictEqual(typeof clientSession[Symbol.asyncDispose], 'function');
|
||||
await clientSession[Symbol.asyncDispose]();
|
||||
strictEqual(clientSession.destroyed, true);
|
||||
assert.strictEqual(clientSession.destroyed, true);
|
||||
|
||||
await serverDone.promise;
|
||||
|
||||
// endpoint[Symbol.asyncDispose] closes the endpoint.
|
||||
strictEqual(typeof serverEndpoint[Symbol.asyncDispose], 'function');
|
||||
assert.strictEqual(typeof serverEndpoint[Symbol.asyncDispose], 'function');
|
||||
await serverEndpoint[Symbol.asyncDispose]();
|
||||
strictEqual(serverEndpoint.destroyed, true);
|
||||
assert.strictEqual(serverEndpoint.destroyed, true);
|
||||
@@ -11,9 +11,6 @@ import { hasQuic, skip, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual, ok, rejects } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -21,15 +18,15 @@ if (!hasQuic) {
|
||||
const { listen } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const sni = { '*': { keys: [key], certs: [cert] } };
|
||||
const alpn = ['quic-test'];
|
||||
|
||||
// Bind first endpoint to get an assigned port.
|
||||
const ep1 = await listen(mustNotCall(), { sni, alpn });
|
||||
const { port } = ep1.address;
|
||||
ok(port > 0);
|
||||
assert.ok(port > 0);
|
||||
|
||||
// Attempt to listen on the same port — should fail with bind error.
|
||||
// listen() returns an endpoint that is immediately destroyed.
|
||||
@@ -38,10 +35,10 @@ const ep2 = await listen(mustNotCall(), {
|
||||
alpn,
|
||||
endpoint: { address: `127.0.0.1:${port}` },
|
||||
});
|
||||
strictEqual(ep2.destroyed, true);
|
||||
assert.strictEqual(ep2.destroyed, true);
|
||||
|
||||
// The bind failure surfaces as a rejected closed promise.
|
||||
await rejects(ep2.closed, {
|
||||
await assert.rejects(ep2.closed, {
|
||||
code: 'ERR_QUIC_ENDPOINT_CLOSED',
|
||||
message: /Bind failure/,
|
||||
});
|
||||
|
||||
@@ -8,9 +8,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual, ok } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -18,8 +15,8 @@ if (!hasQuic) {
|
||||
const { listen, connect, QuicEndpoint } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
// Binding to a specific port.
|
||||
{
|
||||
@@ -38,10 +35,10 @@ const cert = readKey('agent1-cert.pem');
|
||||
|
||||
// The address should reflect what we bound to.
|
||||
const addr = serverEndpoint.address;
|
||||
strictEqual(addr.address, '127.0.0.1');
|
||||
strictEqual(addr.family, 'ipv4');
|
||||
strictEqual(typeof addr.port, 'number');
|
||||
ok(addr.port > 0, 'port should be assigned');
|
||||
assert.strictEqual(addr.address, '127.0.0.1');
|
||||
assert.strictEqual(addr.family, 'ipv4');
|
||||
assert.strictEqual(typeof addr.port, 'number');
|
||||
assert.ok(addr.port > 0, 'port should be assigned');
|
||||
|
||||
// Verify a client can connect to the bound address.
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
|
||||
@@ -8,9 +8,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -18,8 +15,8 @@ if (!hasQuic) {
|
||||
const { listen, connect, QuicEndpoint } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const endpoint = new QuicEndpoint();
|
||||
|
||||
@@ -42,9 +39,9 @@ const cs1 = await connect(serverEndpoint.address, {
|
||||
await cs1.opened;
|
||||
|
||||
// Set the endpoint busy.
|
||||
strictEqual(endpoint.busy, false);
|
||||
assert.strictEqual(endpoint.busy, false);
|
||||
endpoint.busy = true;
|
||||
strictEqual(endpoint.busy, true);
|
||||
assert.strictEqual(endpoint.busy, true);
|
||||
|
||||
// Second connection while busy — server rejects.
|
||||
const cs2 = await connect(serverEndpoint.address, {
|
||||
@@ -52,21 +49,21 @@ const cs2 = await connect(serverEndpoint.address, {
|
||||
verifyPeer: 'manual',
|
||||
transportParams: { maxIdleTimeout: 1 },
|
||||
onerror: mustCall((err) => {
|
||||
strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
|
||||
assert.strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
|
||||
}),
|
||||
});
|
||||
|
||||
await rejects(cs2.opened, {
|
||||
await assert.rejects(cs2.opened, {
|
||||
code: 'ERR_QUIC_TRANSPORT_ERROR',
|
||||
});
|
||||
|
||||
await rejects(cs2.closed, {
|
||||
await assert.rejects(cs2.closed, {
|
||||
code: 'ERR_QUIC_TRANSPORT_ERROR',
|
||||
});
|
||||
|
||||
// Unset busy.
|
||||
endpoint.busy = false;
|
||||
strictEqual(endpoint.busy, false);
|
||||
assert.strictEqual(endpoint.busy, false);
|
||||
|
||||
// Clean up.
|
||||
await cs1.close();
|
||||
|
||||
@@ -10,8 +10,6 @@ import assert from 'node:assert';
|
||||
const { setTimeout } = await import('node:timers/promises');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -37,13 +35,13 @@ const encoder = new TextEncoder();
|
||||
await serverSession.opened;
|
||||
|
||||
// Before close, closing is false.
|
||||
strictEqual(serverEndpoint.closing, false);
|
||||
assert.strictEqual(serverEndpoint.closing, false);
|
||||
|
||||
// Initiate endpoint close — it should wait for this session.
|
||||
serverEndpoint.close();
|
||||
|
||||
// After close() is called, closing is true.
|
||||
strictEqual(serverEndpoint.closing, true);
|
||||
assert.strictEqual(serverEndpoint.closing, true);
|
||||
|
||||
// The endpoint's closed promise should NOT resolve yet — session is open.
|
||||
let endpointClosed = false;
|
||||
@@ -51,7 +49,7 @@ const encoder = new TextEncoder();
|
||||
|
||||
// Give a tick to confirm endpoint hasn't closed yet.
|
||||
await setTimeout(100);
|
||||
strictEqual(endpointClosed, false);
|
||||
assert.strictEqual(endpointClosed, false);
|
||||
|
||||
// Wait for the stream to complete, then close the session.
|
||||
await streamDone.promise;
|
||||
@@ -75,5 +73,5 @@ const encoder = new TextEncoder();
|
||||
stream.closed,
|
||||
serverEndpoint.closed]);
|
||||
|
||||
strictEqual(serverEndpoint.destroyed, true);
|
||||
assert.strictEqual(serverEndpoint.destroyed, true);
|
||||
}
|
||||
@@ -10,8 +10,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -52,7 +50,7 @@ const closingPromise = serverEndpoint.close();
|
||||
// With the fix, the error is still recorded and surfaces on
|
||||
// `endpoint.closed`. Without the fix, it'd be silently dropped.
|
||||
const destroyError = new Error('destroy after close');
|
||||
const closedAssertion = rejects(serverEndpoint.closed, destroyError);
|
||||
const closedAssertion = assert.rejects(serverEndpoint.closed, destroyError);
|
||||
|
||||
serverEndpoint.destroy(destroyError);
|
||||
|
||||
@@ -60,7 +58,7 @@ await closedAssertion;
|
||||
|
||||
// `endpoint.close()` returns the same promise as `endpoint.closed`, so
|
||||
// it should reject with the same error as well.
|
||||
await rejects(closingPromise, destroyError);
|
||||
await assert.rejects(closingPromise, destroyError);
|
||||
|
||||
await serverDone.promise;
|
||||
clientSession.destroy();
|
||||
@@ -22,8 +22,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -69,9 +67,9 @@ await serverHandshake.promise;
|
||||
// (rejects with the transport error decoded from the CONNECTION_CLOSE
|
||||
// frame) ends up as an unhandled rejection in the brief window before
|
||||
// this test gets back to awaiting them.
|
||||
const serverClosedAssertion = rejects(serverEndpoint.closed, serverError);
|
||||
const clientClosedAssertion = rejects(clientSession.closed, mustCall((err) => {
|
||||
strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
|
||||
const serverClosedAssertion = assert.rejects(serverEndpoint.closed, serverError);
|
||||
const clientClosedAssertion = assert.rejects(clientSession.closed, mustCall((err) => {
|
||||
assert.strictEqual(err.code, 'ERR_QUIC_TRANSPORT_ERROR');
|
||||
return true;
|
||||
}));
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import { setTimeout } from 'node:timers/promises';
|
||||
|
||||
const { ok } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -36,14 +34,14 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
await client.opened;
|
||||
|
||||
// Endpoint is alive while the session is active.
|
||||
ok(!clientEndpoint.destroyed, 'endpoint should be alive');
|
||||
assert.ok(!clientEndpoint.destroyed, 'endpoint should be alive');
|
||||
|
||||
await client.close();
|
||||
|
||||
// The endpoint's UDP handle is unref'd when all sessions close,
|
||||
// so it won't block process exit. Explicitly close it for cleanup.
|
||||
await clientEndpoint.close();
|
||||
ok(clientEndpoint.destroyed, 'endpoint should be destroyed after close');
|
||||
assert.ok(clientEndpoint.destroyed, 'endpoint should be destroyed after close');
|
||||
|
||||
await serverEndpoint.close();
|
||||
}
|
||||
@@ -65,15 +63,15 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
|
||||
// The endpoint should NOT be immediately destroyed — idle timer
|
||||
// is running.
|
||||
ok(!clientEndpoint.destroyed,
|
||||
'endpoint should still be alive during idle timeout');
|
||||
assert.ok(!clientEndpoint.destroyed,
|
||||
'endpoint should still be alive during idle timeout');
|
||||
|
||||
// Wait for the idle timeout to fire (1 second + margin).
|
||||
// Use a ref'd timer to keep the event loop alive while the
|
||||
// unref'd idle timer runs.
|
||||
await setTimeout(2000);
|
||||
ok(clientEndpoint.destroyed,
|
||||
'endpoint should be destroyed after idle timeout');
|
||||
assert.ok(clientEndpoint.destroyed,
|
||||
'endpoint should be destroyed after idle timeout');
|
||||
|
||||
await serverEndpoint.close();
|
||||
}
|
||||
@@ -9,8 +9,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -35,7 +33,7 @@ const transportParams = { maxIdleTimeout: 1 };
|
||||
// a handler attached. The throw inside `onsession` is delivered
|
||||
// synchronously from the C++ -> JS callback, so the rejection can
|
||||
// arrive on the very next microtask after `connect()` returns.
|
||||
const closedAssertion = rejects(serverEndpoint.closed, sessionError);
|
||||
const closedAssertion = assert.rejects(serverEndpoint.closed, sessionError);
|
||||
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
transportParams,
|
||||
@@ -49,7 +47,7 @@ const transportParams = { maxIdleTimeout: 1 };
|
||||
// robust to network-dropped close packets and stops the event loop
|
||||
// from waiting on the client's idle timer to expire.
|
||||
clientSession.destroy();
|
||||
await rejects(serverEndpoint.close(), sessionError);
|
||||
await assert.rejects(serverEndpoint.close(), sessionError);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
@@ -63,7 +61,7 @@ const transportParams = { maxIdleTimeout: 1 };
|
||||
throw sessionError;
|
||||
}), { transportParams, onerror() {} });
|
||||
|
||||
const closedAssertion = rejects(serverEndpoint.closed, sessionError);
|
||||
const closedAssertion = assert.rejects(serverEndpoint.closed, sessionError);
|
||||
|
||||
const clientSession = await connect(serverEndpoint.address, {
|
||||
transportParams,
|
||||
@@ -72,5 +70,5 @@ const transportParams = { maxIdleTimeout: 1 };
|
||||
await closedAssertion;
|
||||
|
||||
clientSession.destroy();
|
||||
await rejects(serverEndpoint.close(), sessionError);
|
||||
await assert.rejects(serverEndpoint.close(), sessionError);
|
||||
}
|
||||
@@ -12,8 +12,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual, notStrictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -36,8 +34,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
// findSuitableEndpoint returns the first available non-listening
|
||||
// non-closing endpoint. After client1 is created, its endpoint
|
||||
// is available for client2.
|
||||
strictEqual(client1.endpoint, client2.endpoint,
|
||||
'client sessions should share an endpoint');
|
||||
assert.strictEqual(client1.endpoint, client2.endpoint); // Client sessions should share an endpoint
|
||||
|
||||
await client1.close();
|
||||
await client2.close();
|
||||
@@ -60,8 +57,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
});
|
||||
await client2.opened;
|
||||
|
||||
notStrictEqual(client1.endpoint, client2.endpoint,
|
||||
'client sessions should have separate endpoints');
|
||||
assert.notStrictEqual(client1.endpoint, client2.endpoint); // Client sessions should have separate endpoints
|
||||
|
||||
await client1.close();
|
||||
await client2.close();
|
||||
@@ -81,8 +77,7 @@ const { listen, connect } = await import('../common/quic.mjs');
|
||||
// the server endpoint is in the registry. Self-connect is excluded
|
||||
// because the client's DCID associations would collide with the
|
||||
// server's session routing on the same endpoint.
|
||||
notStrictEqual(client.endpoint, serverEndpoint,
|
||||
'client should not reuse the server endpoint');
|
||||
assert.notStrictEqual(client.endpoint, serverEndpoint); // Client should not reuse the server endpoint
|
||||
|
||||
await client.close();
|
||||
await serverEndpoint.close();
|
||||
|
||||
@@ -9,9 +9,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,8 +16,8 @@ if (!hasQuic) {
|
||||
const { listen, connect, QuicEndpoint } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
{
|
||||
const endpoint = new QuicEndpoint();
|
||||
@@ -36,9 +33,9 @@ const cert = readKey('agent1-cert.pem');
|
||||
});
|
||||
|
||||
// After listen, the endpoint should be listening.
|
||||
strictEqual(serverEndpoint.listening, true);
|
||||
strictEqual(serverEndpoint.closing, false);
|
||||
strictEqual(serverEndpoint.destroyed, false);
|
||||
assert.strictEqual(serverEndpoint.listening, true);
|
||||
assert.strictEqual(serverEndpoint.closing, false);
|
||||
assert.strictEqual(serverEndpoint.destroyed, false);
|
||||
|
||||
const cs = await connect(serverEndpoint.address, {
|
||||
alpn: 'quic-test',
|
||||
@@ -50,10 +47,10 @@ const cert = readKey('agent1-cert.pem');
|
||||
// After close(), closing transitions to true. The endpoint is still
|
||||
// "listening" in the sense that it holds the socket, but closing is true.
|
||||
serverEndpoint.close();
|
||||
strictEqual(serverEndpoint.closing, true);
|
||||
assert.strictEqual(serverEndpoint.closing, true);
|
||||
|
||||
await serverEndpoint.closed;
|
||||
strictEqual(serverEndpoint.destroyed, true);
|
||||
assert.strictEqual(serverEndpoint.destroyed, true);
|
||||
}
|
||||
|
||||
// Binding to 0.0.0.0.
|
||||
@@ -72,8 +69,8 @@ const cert = readKey('agent1-cert.pem');
|
||||
});
|
||||
|
||||
const addr = serverEndpoint.address;
|
||||
strictEqual(addr.address, '0.0.0.0');
|
||||
ok(addr.port > 0);
|
||||
assert.strictEqual(addr.address, '0.0.0.0');
|
||||
assert.ok(addr.port > 0);
|
||||
|
||||
// Connect via 127.0.0.1 since 0.0.0.0 listens on all interfaces.
|
||||
const cs = await connect(`127.0.0.1:${addr.port}`, {
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
import { hasQuic, skip } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual, throws, ok } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -23,63 +21,63 @@ if (!hasQuic) {
|
||||
const { QuicError } = await import('node:quic');
|
||||
|
||||
// Sanity: QuicError is a function (class) and extends Error.
|
||||
strictEqual(typeof QuicError, 'function');
|
||||
ok(new QuicError('msg', { errorCode: 0n }) instanceof Error);
|
||||
assert.strictEqual(typeof QuicError, 'function');
|
||||
assert.ok(new QuicError('msg', { errorCode: 0n }) instanceof Error);
|
||||
|
||||
// Required arguments.
|
||||
// `message` must be a string -> validateString throws ERR_INVALID_ARG_TYPE.
|
||||
throws(() => new QuicError(), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
assert.throws(() => new QuicError(), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
// `options` defaults to an empty object, so `errorCode` is missing.
|
||||
throws(() => new QuicError('msg'), { code: 'ERR_MISSING_ARGS' });
|
||||
assert.throws(() => new QuicError('msg'), { code: 'ERR_MISSING_ARGS' });
|
||||
// Explicit non-object options -> validateObject throws ERR_INVALID_ARG_TYPE.
|
||||
throws(() => new QuicError('msg', null), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
assert.throws(() => new QuicError('msg', null), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
// Empty options -> errorCode missing -> ERR_MISSING_ARGS.
|
||||
throws(() => new QuicError('msg', {}), { code: 'ERR_MISSING_ARGS' });
|
||||
assert.throws(() => new QuicError('msg', {}), { code: 'ERR_MISSING_ARGS' });
|
||||
|
||||
// `message` must be a string.
|
||||
throws(() => new QuicError(42, { errorCode: 0n }), {
|
||||
assert.throws(() => new QuicError(42, { errorCode: 0n }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
// `errorCode` must be bigint or number.
|
||||
throws(() => new QuicError('msg', { errorCode: 'oops' }), {
|
||||
assert.throws(() => new QuicError('msg', { errorCode: 'oops' }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
throws(() => new QuicError('msg', { errorCode: true }), {
|
||||
assert.throws(() => new QuicError('msg', { errorCode: true }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
// `null` is preserved by destructuring (only `undefined` triggers the
|
||||
// default), so it flows through to the type check rather than the
|
||||
// missing-args check.
|
||||
throws(() => new QuicError('msg', { errorCode: null }), {
|
||||
assert.throws(() => new QuicError('msg', { errorCode: null }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
// `errorCode` range checks.
|
||||
throws(() => new QuicError('msg', { errorCode: -1 }), {
|
||||
assert.throws(() => new QuicError('msg', { errorCode: -1 }), {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
});
|
||||
throws(() => new QuicError('msg', { errorCode: -1n }), {
|
||||
assert.throws(() => new QuicError('msg', { errorCode: -1n }), {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
});
|
||||
// 2**62 is the first invalid value (max varint is 2**62 - 1).
|
||||
throws(() => new QuicError('msg', { errorCode: 1n << 62n }), {
|
||||
assert.throws(() => new QuicError('msg', { errorCode: 1n << 62n }), {
|
||||
code: 'ERR_OUT_OF_RANGE',
|
||||
});
|
||||
|
||||
// `type` validation.
|
||||
throws(() => new QuicError('msg', { errorCode: 0n, type: 'bogus' }), {
|
||||
assert.throws(() => new QuicError('msg', { errorCode: 0n, type: 'bogus' }), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
throws(() => new QuicError('msg', { errorCode: 0n, type: 42 }), {
|
||||
assert.throws(() => new QuicError('msg', { errorCode: 0n, type: 42 }), {
|
||||
code: 'ERR_INVALID_ARG_VALUE',
|
||||
});
|
||||
|
||||
// `code` (Node.js error code) must be a string when supplied.
|
||||
throws(() => new QuicError('msg', { errorCode: 0n, code: 42 }), {
|
||||
assert.throws(() => new QuicError('msg', { errorCode: 0n, code: 42 }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
throws(() => new QuicError('msg', { errorCode: 0n, code: null }), {
|
||||
assert.throws(() => new QuicError('msg', { errorCode: 0n, code: null }), {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
});
|
||||
|
||||
@@ -88,32 +86,32 @@ throws(() => new QuicError('msg', { errorCode: 0n, code: null }), {
|
||||
// 1. Bigint errorCode, default type, default Node code.
|
||||
{
|
||||
const err = new QuicError('something broke', { errorCode: 0x42n });
|
||||
strictEqual(err.message, 'something broke');
|
||||
strictEqual(err.code, 'ERR_QUIC_STREAM_ABORTED');
|
||||
strictEqual(err.errorCode, 0x42n);
|
||||
strictEqual(err.type, 'application');
|
||||
ok(err instanceof Error);
|
||||
ok(err instanceof QuicError);
|
||||
assert.strictEqual(err.message, 'something broke');
|
||||
assert.strictEqual(err.code, 'ERR_QUIC_STREAM_ABORTED');
|
||||
assert.strictEqual(err.errorCode, 0x42n);
|
||||
assert.strictEqual(err.type, 'application');
|
||||
assert.ok(err instanceof Error);
|
||||
assert.ok(err instanceof QuicError);
|
||||
}
|
||||
|
||||
// 2. Number errorCode, coerced to bigint.
|
||||
{
|
||||
const err = new QuicError('numeric code', { errorCode: 5 });
|
||||
strictEqual(err.errorCode, 5n);
|
||||
strictEqual(typeof err.errorCode, 'bigint');
|
||||
assert.strictEqual(err.errorCode, 5n);
|
||||
assert.strictEqual(typeof err.errorCode, 'bigint');
|
||||
}
|
||||
|
||||
// 3. Boundary: 0n is allowed.
|
||||
{
|
||||
const err = new QuicError('zero', { errorCode: 0n });
|
||||
strictEqual(err.errorCode, 0n);
|
||||
assert.strictEqual(err.errorCode, 0n);
|
||||
}
|
||||
|
||||
// 4. Boundary: 2**62 - 1 is allowed (largest valid 62-bit varint).
|
||||
{
|
||||
const max = (1n << 62n) - 1n;
|
||||
const err = new QuicError('max', { errorCode: max });
|
||||
strictEqual(err.errorCode, max);
|
||||
assert.strictEqual(err.errorCode, max);
|
||||
}
|
||||
|
||||
// 5. Explicit type='transport'.
|
||||
@@ -122,7 +120,7 @@ throws(() => new QuicError('msg', { errorCode: 0n, code: null }), {
|
||||
errorCode: 0x1n,
|
||||
type: 'transport',
|
||||
});
|
||||
strictEqual(err.type, 'transport');
|
||||
assert.strictEqual(err.type, 'transport');
|
||||
}
|
||||
|
||||
// 6. Explicit type='application' (default).
|
||||
@@ -131,7 +129,7 @@ throws(() => new QuicError('msg', { errorCode: 0n, code: null }), {
|
||||
errorCode: 0x102n,
|
||||
type: 'application',
|
||||
});
|
||||
strictEqual(err.type, 'application');
|
||||
assert.strictEqual(err.type, 'application');
|
||||
}
|
||||
|
||||
// 7. Custom Node.js error code string via options.code.
|
||||
@@ -140,8 +138,8 @@ throws(() => new QuicError('msg', { errorCode: 0n, code: null }), {
|
||||
errorCode: 0x10cn,
|
||||
code: 'ERR_CUSTOM_QUIC_FAILURE',
|
||||
});
|
||||
strictEqual(err.code, 'ERR_CUSTOM_QUIC_FAILURE');
|
||||
strictEqual(err.errorCode, 0x10cn);
|
||||
assert.strictEqual(err.code, 'ERR_CUSTOM_QUIC_FAILURE');
|
||||
assert.strictEqual(err.errorCode, 0x10cn);
|
||||
}
|
||||
|
||||
// 8. Properties are read-only via getters (errorCode, type backed by
|
||||
@@ -153,8 +151,8 @@ throws(() => new QuicError('msg', { errorCode: 0n, code: null }), {
|
||||
// The getters live on the prototype; assigning through the instance
|
||||
// is silently ignored in non-strict mode (modules are strict, so
|
||||
// this throws TypeError). We just assert the value is unchanged.
|
||||
throws(() => { err.errorCode = 0xffn; }, { name: 'TypeError' });
|
||||
throws(() => { err.type = 'transport'; }, { name: 'TypeError' });
|
||||
strictEqual(err.errorCode, 0x1n);
|
||||
strictEqual(err.type, 'application');
|
||||
assert.throws(() => { err.errorCode = 0xffn; }, { name: 'TypeError' });
|
||||
assert.throws(() => { err.type = 'transport'; }, { name: 'TypeError' });
|
||||
assert.strictEqual(err.errorCode, 0x1n);
|
||||
assert.strictEqual(err.type, 'application');
|
||||
}
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { rejects } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -35,8 +33,8 @@ const serverEndpoint = await listen(async (serverSession) => {
|
||||
clientSession.destroy(testError);
|
||||
|
||||
// Both opened and closed should reject with the same error.
|
||||
await rejects(clientSession.opened, testError);
|
||||
await rejects(clientSession.closed, testError);
|
||||
await assert.rejects(clientSession.opened, testError);
|
||||
await assert.rejects(clientSession.closed, testError);
|
||||
}
|
||||
|
||||
// Second client: destroy AFTER the handshake completes.
|
||||
@@ -53,7 +51,7 @@ const serverEndpoint = await listen(async (serverSession) => {
|
||||
await clientSession.opened;
|
||||
|
||||
// Closed rejects with the error.
|
||||
await rejects(clientSession.closed, testError);
|
||||
await assert.rejects(clientSession.closed, testError);
|
||||
}
|
||||
|
||||
await serverEndpoint.close();
|
||||
@@ -5,8 +5,6 @@
|
||||
import { hasQuic, skip } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual, throws, ok } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -14,36 +12,36 @@ if (!hasQuic) {
|
||||
const quic = await import('node:quic');
|
||||
|
||||
// Top-level exports.
|
||||
strictEqual(typeof quic.listen, 'function');
|
||||
strictEqual(typeof quic.connect, 'function');
|
||||
strictEqual(typeof quic.QuicEndpoint, 'function');
|
||||
strictEqual(typeof quic.QuicSession, 'function');
|
||||
strictEqual(typeof quic.QuicStream, 'function');
|
||||
strictEqual(typeof quic.constants, 'object');
|
||||
assert.strictEqual(typeof quic.listen, 'function');
|
||||
assert.strictEqual(typeof quic.connect, 'function');
|
||||
assert.strictEqual(typeof quic.QuicEndpoint, 'function');
|
||||
assert.strictEqual(typeof quic.QuicSession, 'function');
|
||||
assert.strictEqual(typeof quic.QuicStream, 'function');
|
||||
assert.strictEqual(typeof quic.constants, 'object');
|
||||
|
||||
// Congestion control constants.
|
||||
strictEqual(quic.constants.cc.RENO, 'reno');
|
||||
strictEqual(quic.constants.cc.CUBIC, 'cubic');
|
||||
strictEqual(quic.constants.cc.BBR, 'bbr');
|
||||
assert.strictEqual(quic.constants.cc.RENO, 'reno');
|
||||
assert.strictEqual(quic.constants.cc.CUBIC, 'cubic');
|
||||
assert.strictEqual(quic.constants.cc.BBR, 'bbr');
|
||||
|
||||
// DEFAULT_CIPHERS.
|
||||
strictEqual(typeof quic.constants.DEFAULT_CIPHERS, 'string');
|
||||
ok(quic.constants.DEFAULT_CIPHERS.length > 0);
|
||||
ok(quic.constants.DEFAULT_CIPHERS.includes('TLS_AES_128_GCM_SHA256'));
|
||||
assert.strictEqual(typeof quic.constants.DEFAULT_CIPHERS, 'string');
|
||||
assert.ok(quic.constants.DEFAULT_CIPHERS.length > 0);
|
||||
assert.ok(quic.constants.DEFAULT_CIPHERS.includes('TLS_AES_128_GCM_SHA256'));
|
||||
|
||||
// DEFAULT_GROUPS.
|
||||
strictEqual(typeof quic.constants.DEFAULT_GROUPS, 'string');
|
||||
ok(quic.constants.DEFAULT_GROUPS.length > 0);
|
||||
assert.strictEqual(typeof quic.constants.DEFAULT_GROUPS, 'string');
|
||||
assert.ok(quic.constants.DEFAULT_GROUPS.length > 0);
|
||||
|
||||
// QuicEndpoint can be constructed directly.
|
||||
// QuicSession and QuicStream cannot — they throw ERR_ILLEGAL_CONSTRUCTOR.
|
||||
{
|
||||
const ep = new quic.QuicEndpoint();
|
||||
ok(ep instanceof quic.QuicEndpoint);
|
||||
assert.ok(ep instanceof quic.QuicEndpoint);
|
||||
}
|
||||
throws(() => new quic.QuicSession(), {
|
||||
assert.throws(() => new quic.QuicSession(), {
|
||||
code: 'ERR_ILLEGAL_CONSTRUCTOR',
|
||||
});
|
||||
throws(() => new quic.QuicStream(), {
|
||||
assert.throws(() => new quic.QuicStream(), {
|
||||
code: 'ERR_ILLEGAL_CONSTRUCTOR',
|
||||
});
|
||||
@@ -2,8 +2,6 @@
|
||||
import { hasQuic, skip } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual, throws } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -11,29 +9,29 @@ if (!hasQuic) {
|
||||
const quic = await import('node:quic');
|
||||
|
||||
// Test that the main exports exist and are of the correct type.
|
||||
strictEqual(typeof quic.connect, 'function');
|
||||
strictEqual(typeof quic.listen, 'function');
|
||||
strictEqual(typeof quic.QuicEndpoint, 'function');
|
||||
strictEqual(typeof quic.QuicSession, 'function');
|
||||
strictEqual(typeof quic.QuicStream, 'function');
|
||||
strictEqual(typeof quic.QuicEndpoint.Stats, 'function');
|
||||
strictEqual(typeof quic.QuicSession.Stats, 'function');
|
||||
strictEqual(typeof quic.QuicStream.Stats, 'function');
|
||||
strictEqual(typeof quic.constants, 'object');
|
||||
strictEqual(typeof quic.constants.cc, 'object');
|
||||
assert.strictEqual(typeof quic.connect, 'function');
|
||||
assert.strictEqual(typeof quic.listen, 'function');
|
||||
assert.strictEqual(typeof quic.QuicEndpoint, 'function');
|
||||
assert.strictEqual(typeof quic.QuicSession, 'function');
|
||||
assert.strictEqual(typeof quic.QuicStream, 'function');
|
||||
assert.strictEqual(typeof quic.QuicEndpoint.Stats, 'function');
|
||||
assert.strictEqual(typeof quic.QuicSession.Stats, 'function');
|
||||
assert.strictEqual(typeof quic.QuicStream.Stats, 'function');
|
||||
assert.strictEqual(typeof quic.constants, 'object');
|
||||
assert.strictEqual(typeof quic.constants.cc, 'object');
|
||||
|
||||
// Test that the constants exist and are of the correct type.
|
||||
strictEqual(quic.constants.cc.RENO, 'reno');
|
||||
strictEqual(quic.constants.cc.CUBIC, 'cubic');
|
||||
strictEqual(quic.constants.cc.BBR, 'bbr');
|
||||
strictEqual(quic.constants.DEFAULT_CIPHERS,
|
||||
'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:' +
|
||||
assert.strictEqual(quic.constants.cc.RENO, 'reno');
|
||||
assert.strictEqual(quic.constants.cc.CUBIC, 'cubic');
|
||||
assert.strictEqual(quic.constants.cc.BBR, 'bbr');
|
||||
assert.strictEqual(quic.constants.DEFAULT_CIPHERS,
|
||||
'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:' +
|
||||
'TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_CCM_SHA256');
|
||||
strictEqual(quic.constants.DEFAULT_GROUPS, 'X25519:P-256:P-384:P-521');
|
||||
assert.strictEqual(quic.constants.DEFAULT_GROUPS, 'X25519:P-256:P-384:P-521');
|
||||
|
||||
// Ensure the constants are.. well, constant.
|
||||
throws(() => { quic.constants.cc.RENO = 'foo'; }, TypeError);
|
||||
strictEqual(quic.constants.cc.RENO, 'reno');
|
||||
assert.throws(() => { quic.constants.cc.RENO = 'foo'; }, TypeError);
|
||||
assert.strictEqual(quic.constants.cc.RENO, 'reno');
|
||||
|
||||
throws(() => { quic.constants.DEFAULT_CIPHERS = 123; }, TypeError);
|
||||
strictEqual(typeof quic.constants.DEFAULT_CIPHERS, 'string');
|
||||
assert.throws(() => { quic.constants.DEFAULT_CIPHERS = 123; }, TypeError);
|
||||
assert.strictEqual(typeof quic.constants.DEFAULT_CIPHERS, 'string');
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { deepStrictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -27,7 +25,7 @@ const serverDone = Promise.withResolvers();
|
||||
const serverEndpoint = await listen(mustCall((serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
const received = await bytes(stream);
|
||||
deepStrictEqual(received, data);
|
||||
assert.deepStrictEqual(received, data);
|
||||
stream.writer.endSync();
|
||||
await stream.closed;
|
||||
serverSession.close();
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -28,7 +26,7 @@ const serverEndpoint = await listen(mustCall((serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
// Read all data — this extends the flow control window.
|
||||
const received = await bytes(stream);
|
||||
strictEqual(received.byteLength, dataLength);
|
||||
assert.strictEqual(received.byteLength, dataLength);
|
||||
stream.writer.endSync();
|
||||
await stream.closed;
|
||||
serverSession.close();
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -35,7 +33,7 @@ const encoder = new TextEncoder();
|
||||
const serverEndpoint = await listen(mustCall((serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
const received = await bytes(stream);
|
||||
strictEqual(received.byteLength, expected.byteLength);
|
||||
assert.strictEqual(received.byteLength, expected.byteLength);
|
||||
stream.writer.endSync();
|
||||
await stream.closed;
|
||||
serverSession.close();
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -26,7 +24,7 @@ const serverDone = Promise.withResolvers();
|
||||
const serverEndpoint = await listen(mustCall((serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
const received = await bytes(stream);
|
||||
strictEqual(received.byteLength, expected.byteLength);
|
||||
assert.strictEqual(received.byteLength, expected.byteLength);
|
||||
await stream.closed;
|
||||
serverSession.close();
|
||||
serverDone.resolve();
|
||||
|
||||
@@ -11,9 +11,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual, rejects } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -21,8 +18,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
async function makeServer(onheadersHandler, extraOpts = {}) {
|
||||
@@ -73,11 +70,11 @@ async function makeServer(onheadersHandler, extraOpts = {}) {
|
||||
}),
|
||||
});
|
||||
|
||||
await rejects(s.closed, mustCall((err) => {
|
||||
strictEqual(err.message, 'onheaders sync error');
|
||||
await assert.rejects(s.closed, mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'onheaders sync error');
|
||||
return true;
|
||||
}));
|
||||
strictEqual(s.destroyed, true);
|
||||
assert.strictEqual(s.destroyed, true);
|
||||
|
||||
c.close();
|
||||
await done.promise;
|
||||
@@ -113,11 +110,11 @@ async function makeServer(onheadersHandler, extraOpts = {}) {
|
||||
}),
|
||||
});
|
||||
|
||||
await rejects(s.closed, mustCall((err) => {
|
||||
strictEqual(err.message, 'onheaders async error');
|
||||
await assert.rejects(s.closed, mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'onheaders async error');
|
||||
return true;
|
||||
}));
|
||||
strictEqual(s.destroyed, true);
|
||||
assert.strictEqual(s.destroyed, true);
|
||||
|
||||
c.close();
|
||||
await done.promise;
|
||||
@@ -154,18 +151,18 @@ async function makeServer(onheadersHandler, extraOpts = {}) {
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
ontrailers: mustCall(function() {
|
||||
throw new Error('ontrailers sync error');
|
||||
}),
|
||||
});
|
||||
|
||||
await rejects(s.closed, mustCall((err) => {
|
||||
strictEqual(err.message, 'ontrailers sync error');
|
||||
await assert.rejects(s.closed, mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'ontrailers sync error');
|
||||
return true;
|
||||
}));
|
||||
strictEqual(s.destroyed, true);
|
||||
assert.strictEqual(s.destroyed, true);
|
||||
|
||||
c.close();
|
||||
await done.promise;
|
||||
@@ -196,7 +193,7 @@ async function makeServer(onheadersHandler, extraOpts = {}) {
|
||||
throw new Error('onorigin error');
|
||||
}),
|
||||
onerror: mustCall(function(error) {
|
||||
strictEqual(error.message, 'onorigin error');
|
||||
assert.strictEqual(error.message, 'onorigin error');
|
||||
}),
|
||||
});
|
||||
await clientSession.opened;
|
||||
@@ -212,12 +209,12 @@ async function makeServer(onheadersHandler, extraOpts = {}) {
|
||||
|
||||
// The session is destroyed by the callback error, which
|
||||
// destroys the stream with the same error.
|
||||
await rejects(stream.closed, mustCall((err) => {
|
||||
strictEqual(err.message, 'onorigin error');
|
||||
await assert.rejects(stream.closed, mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'onorigin error');
|
||||
return true;
|
||||
}));
|
||||
|
||||
await rejects(clientSession.closed, mustCall(() => true));
|
||||
await assert.rejects(clientSession.closed, mustCall(() => true));
|
||||
|
||||
serverEndpoint.close();
|
||||
}
|
||||
@@ -232,8 +229,8 @@ async function makeServer(onheadersHandler, extraOpts = {}) {
|
||||
const serverEndpoint = await listen(mustCall(async (ss) => {
|
||||
ss.onstream = mustCall(async (stream) => {
|
||||
// The server stream rejects because onwanttrailers threw.
|
||||
await rejects(stream.closed, mustCall((err) => {
|
||||
strictEqual(err.message, 'onwanttrailers error');
|
||||
await assert.rejects(stream.closed, mustCall((err) => {
|
||||
assert.strictEqual(err.message, 'onwanttrailers error');
|
||||
serverStreamRejected.resolve();
|
||||
return true;
|
||||
}));
|
||||
@@ -268,7 +265,7 @@ async function makeServer(onheadersHandler, extraOpts = {}) {
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -8,9 +8,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,8 +16,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
// Two streams. The graceful close waits for both streams to complete,
|
||||
@@ -65,7 +62,7 @@ const decoder = new TextDecoder();
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall((headers) => {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -77,14 +74,14 @@ const decoder = new TextDecoder();
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall((headers) => {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
// Both streams should complete normally despite the close.
|
||||
const bodies = await Promise.all([bytes(stream1), bytes(stream2)]);
|
||||
strictEqual(decoder.decode(bodies[0]), '/one');
|
||||
strictEqual(decoder.decode(bodies[1]), '/two');
|
||||
assert.strictEqual(decoder.decode(bodies[0]), '/one');
|
||||
assert.strictEqual(decoder.decode(bodies[1]), '/two');
|
||||
|
||||
await Promise.all([stream1.closed,
|
||||
stream2.closed,
|
||||
|
||||
@@ -12,9 +12,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -23,8 +20,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
@@ -75,7 +72,7 @@ const requests = paths.map(mustCall(async (path) => {
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall((headers) => {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
headersReceived.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -83,7 +80,7 @@ const requests = paths.map(mustCall(async (path) => {
|
||||
await headersReceived.promise;
|
||||
const body = await bytes(stream);
|
||||
const text = decoder.decode(body);
|
||||
strictEqual(text, `response for ${path}`);
|
||||
assert.strictEqual(text, `response for ${path}`);
|
||||
await stream.closed;
|
||||
}, REQUEST_COUNT));
|
||||
|
||||
|
||||
@@ -10,9 +10,6 @@
|
||||
import { hasQuic, skip, mustCall, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
const { readKey } = fixtures;
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
@@ -23,8 +20,8 @@ const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
const { setTimeout: sleep } = await import('timers/promises');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
// Test 1: H3 datagrams with enableDatagrams: true on both sides.
|
||||
@@ -48,11 +45,11 @@ const decoder = new TextDecoder();
|
||||
transportParams: { maxDatagramFrameSize: 100 },
|
||||
// Server echoes received datagram back to client.
|
||||
ondatagram: mustCall(function(data) {
|
||||
ok(data instanceof Uint8Array);
|
||||
strictEqual(data.byteLength, 3);
|
||||
strictEqual(data[0], 10);
|
||||
strictEqual(data[1], 20);
|
||||
strictEqual(data[2], 30);
|
||||
assert.ok(data instanceof Uint8Array);
|
||||
assert.strictEqual(data.byteLength, 3);
|
||||
assert.strictEqual(data[0], 10);
|
||||
assert.strictEqual(data[1], 20);
|
||||
assert.strictEqual(data[2], 30);
|
||||
// Echo it back.
|
||||
this.sendDatagram(new Uint8Array([42, 43, 44]));
|
||||
serverGotDatagram.resolve();
|
||||
@@ -71,11 +68,11 @@ const decoder = new TextDecoder();
|
||||
transportParams: { maxDatagramFrameSize: 100 },
|
||||
// Client receives datagram from server.
|
||||
ondatagram: mustCall(function(data) {
|
||||
ok(data instanceof Uint8Array);
|
||||
strictEqual(data.byteLength, 3);
|
||||
strictEqual(data[0], 42);
|
||||
strictEqual(data[1], 43);
|
||||
strictEqual(data[2], 44);
|
||||
assert.ok(data instanceof Uint8Array);
|
||||
assert.strictEqual(data.byteLength, 3);
|
||||
assert.strictEqual(data[0], 42);
|
||||
assert.strictEqual(data[1], 43);
|
||||
assert.strictEqual(data[2], 44);
|
||||
clientGotDatagram.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -90,7 +87,7 @@ const decoder = new TextDecoder();
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -99,7 +96,7 @@ const decoder = new TextDecoder();
|
||||
|
||||
// H3 response body is received.
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
await stream.closed;
|
||||
|
||||
// Both sides received their datagram.
|
||||
@@ -154,7 +151,7 @@ const decoder = new TextDecoder();
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall((headers) => {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -162,12 +159,12 @@ const decoder = new TextDecoder();
|
||||
// SETTINGS (with h3_datagram=0) arrive, the client should know
|
||||
// the peer doesn't support H3 datagrams.
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'no-dgram');
|
||||
assert.strictEqual(decoder.decode(body), 'no-dgram');
|
||||
|
||||
// Attempt to send a datagram. Since the peer's H3 SETTINGS
|
||||
// indicate h3_datagram=0, this should return 0 (not sent).
|
||||
const dgId = await clientSession.sendDatagram(new Uint8Array([1, 2, 3]));
|
||||
strictEqual(dgId, 0n);
|
||||
assert.strictEqual(dgId, 0n);
|
||||
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
clientSession.close();
|
||||
|
||||
@@ -8,9 +8,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual, rejects } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,8 +16,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
// Server closes with explicit application error code.
|
||||
@@ -58,16 +55,16 @@ const decoder = new TextDecoder();
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
|
||||
// Client sees the application error code.
|
||||
await rejects(clientSession.closed, {
|
||||
await assert.rejects(clientSession.closed, {
|
||||
code: 'ERR_QUIC_APPLICATION_ERROR',
|
||||
});
|
||||
|
||||
@@ -109,12 +106,12 @@ const decoder = new TextDecoder();
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
await stream.closed;
|
||||
|
||||
// Graceful close - session close promise resolves
|
||||
|
||||
@@ -9,9 +9,6 @@ import assert from 'node:assert';
|
||||
import { setImmediate } from 'node:timers/promises';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -20,8 +17,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
@@ -31,7 +28,7 @@ const serverEndpoint = await listen(mustCall(async (ss) => {
|
||||
ss.onstream = mustCall(async (stream) => {
|
||||
// Read client data, send response, close stream.
|
||||
const data = await bytes(stream);
|
||||
strictEqual(decoder.decode(data), 'ping');
|
||||
assert.strictEqual(decoder.decode(data), 'ping');
|
||||
stream.writer.writeSync('pong');
|
||||
stream.writer.endSync();
|
||||
await stream.closed;
|
||||
@@ -57,7 +54,7 @@ const stream = await clientSession.createBidirectionalStream({
|
||||
});
|
||||
|
||||
const response = await bytes(stream);
|
||||
strictEqual(decoder.decode(response), 'pong');
|
||||
assert.strictEqual(decoder.decode(response), 'pong');
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
|
||||
// Wait a tick for any deferred callbacks to fire.
|
||||
|
||||
@@ -14,9 +14,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
const { readKey } = fixtures;
|
||||
|
||||
const { ok, strictEqual, rejects } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
@@ -26,15 +23,15 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
// quic.session.goaway fires when the peer sends GOAWAY.
|
||||
dc.subscribe('quic.session.goaway', mustCall((msg) => {
|
||||
ok(msg.session, 'goaway should include session');
|
||||
strictEqual(typeof msg.lastStreamId, 'bigint', 'goaway should include lastStreamId');
|
||||
assert.ok(msg.session, 'goaway should include session');
|
||||
assert.strictEqual(typeof msg.lastStreamId, 'bigint'); // `goaway` should include lastStreamId
|
||||
}));
|
||||
|
||||
{
|
||||
@@ -74,14 +71,14 @@ dc.subscribe('quic.session.goaway', mustCall((msg) => {
|
||||
verifyPeer: 'manual',
|
||||
// Ongoaway fires when the peer sends GOAWAY.
|
||||
ongoaway: mustCall(function(lastStreamId) {
|
||||
strictEqual(lastStreamId, -1n);
|
||||
assert.strictEqual(lastStreamId, -1n);
|
||||
goawayReceived.resolve();
|
||||
}),
|
||||
});
|
||||
await clientSession.opened;
|
||||
|
||||
const onClientHeaders = mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
if (++clientHeaderCount === 2) {
|
||||
bothHeadersReceived.resolve();
|
||||
}
|
||||
@@ -109,7 +106,7 @@ dc.subscribe('quic.session.goaway', mustCall((msg) => {
|
||||
|
||||
// First stream completes immediately.
|
||||
const body1 = await bytes(stream1);
|
||||
strictEqual(decoder.decode(body1), 'first');
|
||||
assert.strictEqual(decoder.decode(body1), 'first');
|
||||
|
||||
// Wait for both streams' headers to arrive on the client, confirming
|
||||
// the server has processed both requests.
|
||||
@@ -124,7 +121,7 @@ dc.subscribe('quic.session.goaway', mustCall((msg) => {
|
||||
await goawayReceived.promise;
|
||||
|
||||
// After GOAWAY, new stream creation should fail.
|
||||
await rejects(
|
||||
await assert.rejects(
|
||||
clientSession.createBidirectionalStream({
|
||||
headers: {
|
||||
':method': 'GET',
|
||||
@@ -141,7 +138,7 @@ dc.subscribe('quic.session.goaway', mustCall((msg) => {
|
||||
|
||||
// Second stream also completes despite GOAWAY.
|
||||
const body2 = await bytes(stream2);
|
||||
strictEqual(decoder.decode(body2), 'second');
|
||||
assert.strictEqual(decoder.decode(body2), 'second');
|
||||
|
||||
// Both streams close cleanly.
|
||||
await Promise.all([stream1.closed, stream2.closed]);
|
||||
|
||||
@@ -16,8 +16,6 @@ import { hasQuic, skip, mustNotCall } from '../common/index.mjs';
|
||||
import { setTimeout } from 'node:timers/promises';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -25,8 +23,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const serverEndpoint = await listen(async (serverSession) => {
|
||||
await serverSession.closed;
|
||||
|
||||
@@ -17,9 +17,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual, ok } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -28,8 +25,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
// H3V-01: Header names are lowercased on send.
|
||||
@@ -50,19 +47,19 @@ const decoder = new TextDecoder();
|
||||
// H3V-01: All header names should be lowercase regardless
|
||||
// of how the client sent them.
|
||||
for (const name of Object.keys(headers)) {
|
||||
strictEqual(name, name.toLowerCase(),
|
||||
`Header name "${name}" should be lowercase`);
|
||||
assert.strictEqual(name, name.toLowerCase(),
|
||||
`Header name "${name}" should be lowercase`);
|
||||
}
|
||||
|
||||
// Verify specific headers arrived lowercased.
|
||||
strictEqual(headers[':method'], 'GET');
|
||||
strictEqual(headers[':path'], '/test');
|
||||
strictEqual(headers['x-custom-header'], 'Value1');
|
||||
strictEqual(headers['content-type'], 'text/plain');
|
||||
strictEqual(headers['x-mixed-case'], 'MixedValue');
|
||||
assert.strictEqual(headers[':method'], 'GET');
|
||||
assert.strictEqual(headers[':path'], '/test');
|
||||
assert.strictEqual(headers['x-custom-header'], 'Value1');
|
||||
assert.strictEqual(headers['content-type'], 'text/plain');
|
||||
assert.strictEqual(headers['x-mixed-case'], 'MixedValue');
|
||||
|
||||
// Verify values are NOT lowercased — only names are.
|
||||
strictEqual(headers['x-custom-header'], 'Value1');
|
||||
assert.strictEqual(headers['x-custom-header'], 'Value1');
|
||||
|
||||
this.sendHeaders({
|
||||
// Response with mixed-case names — should be lowercased.
|
||||
@@ -94,20 +91,20 @@ const decoder = new TextDecoder();
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
// Client should also receive lowercased response header names.
|
||||
strictEqual(headers[':status'], '200');
|
||||
strictEqual(headers['content-type'], 'text/html');
|
||||
strictEqual(headers['x-response-header'], 'ResponseValue');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers['content-type'], 'text/html');
|
||||
assert.strictEqual(headers['x-response-header'], 'ResponseValue');
|
||||
|
||||
// Verify all names are lowercase.
|
||||
for (const name of Object.keys(headers)) {
|
||||
strictEqual(name, name.toLowerCase(),
|
||||
`Response header name "${name}" should be lowercase`);
|
||||
assert.strictEqual(name, name.toLowerCase(),
|
||||
`Response header name "${name}" should be lowercase`);
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
await clientSession.close();
|
||||
await serverEndpoint.close();
|
||||
@@ -127,10 +124,10 @@ const decoder = new TextDecoder();
|
||||
sni: { '*': { keys: [key], certs: [cert] } },
|
||||
onheaders: mustCall(function(headers) {
|
||||
// All four required pseudo-headers present.
|
||||
ok(headers[':method']);
|
||||
ok(headers[':path']);
|
||||
ok(headers[':scheme']);
|
||||
ok(headers[':authority']);
|
||||
assert.ok(headers[':method']);
|
||||
assert.ok(headers[':path']);
|
||||
assert.ok(headers[':scheme']);
|
||||
assert.ok(headers[':authority']);
|
||||
|
||||
this.sendHeaders({ ':status': '204' });
|
||||
this.writer.endSync();
|
||||
@@ -151,7 +148,7 @@ const decoder = new TextDecoder();
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall((headers) => {
|
||||
strictEqual(headers[':status'], '204');
|
||||
assert.strictEqual(headers[':status'], '204');
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
const { readKey } = fixtures;
|
||||
|
||||
const { throws } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
@@ -19,35 +16,35 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
const serverDone = Promise.withResolvers();
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
// Sending headers on non-H3 stream throws.
|
||||
throws(() => stream.sendHeaders({ ':status': '200' }), { code: 'ERR_INVALID_STATE' });
|
||||
assert.throws(() => stream.sendHeaders({ ':status': '200' }), { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
// Setting onheaders on non-H3 stream throws.
|
||||
throws(() => stream.onheaders = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
assert.throws(() => stream.onheaders = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
// Setting ontrailers on non-H3 stream throws.
|
||||
throws(() => stream.ontrailers = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
assert.throws(() => stream.ontrailers = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
// Setting oninfo on non-H3 stream throws.
|
||||
throws(() => stream.oninfo = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
assert.throws(() => stream.oninfo = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
// Setting onwanttrailers on non-H3 stream throws.
|
||||
throws(() => stream.onwanttrailers = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
assert.throws(() => stream.onwanttrailers = () => {}, { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
// sendInformationalHeaders throws on non-H3.
|
||||
throws(() => stream.sendInformationalHeaders({ ':status': '103' }), {
|
||||
assert.throws(() => stream.sendInformationalHeaders({ ':status': '103' }), {
|
||||
code: 'ERR_INVALID_STATE',
|
||||
});
|
||||
|
||||
// sendTrailers throws on non-H3.
|
||||
throws(() => stream.sendTrailers({ 'x-trailer': 'value' }), { code: 'ERR_INVALID_STATE' });
|
||||
assert.throws(() => stream.sendTrailers({ 'x-trailer': 'value' }), { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
stream.writer.endSync();
|
||||
|
||||
@@ -71,7 +68,7 @@ const stream = await clientSession.createBidirectionalStream({
|
||||
});
|
||||
|
||||
// Client side — sending headers on non-H3 stream throws.
|
||||
throws(() => stream.sendHeaders({ ':method': 'GET' }), { code: 'ERR_INVALID_STATE' });
|
||||
assert.throws(() => stream.sendHeaders({ ':method': 'GET' }), { code: 'ERR_INVALID_STATE' });
|
||||
|
||||
await serverDone.promise;
|
||||
await clientSession.close();
|
||||
|
||||
@@ -15,9 +15,6 @@ import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -26,24 +23,24 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
const responseBody = 'final response';
|
||||
|
||||
// quic.stream.info fires when informational (1xx) headers are received.
|
||||
dc.subscribe('quic.stream.info', mustCall((msg) => {
|
||||
ok(msg.stream, 'stream.info should include stream');
|
||||
ok(msg.session, 'stream.info should include session');
|
||||
ok(msg.headers, 'stream.info should include headers');
|
||||
strictEqual(msg.headers[':status'], '103');
|
||||
assert.ok(msg.stream, 'stream.info should include stream');
|
||||
assert.ok(msg.session, 'stream.info should include session');
|
||||
assert.ok(msg.headers, 'stream.info should include headers');
|
||||
assert.strictEqual(msg.headers[':status'], '103');
|
||||
}));
|
||||
|
||||
// quic.stream.headers also fires for the final response headers.
|
||||
dc.subscribe('quic.stream.headers', mustCall((msg) => {
|
||||
ok(msg.stream, 'stream.headers should include stream');
|
||||
ok(msg.headers, 'stream.headers should include headers');
|
||||
assert.ok(msg.stream, 'stream.headers should include stream');
|
||||
assert.ok(msg.headers, 'stream.headers should include headers');
|
||||
}, 2));
|
||||
|
||||
const serverDone = Promise.withResolvers();
|
||||
@@ -92,13 +89,13 @@ const stream = await clientSession.createBidirectionalStream({
|
||||
':authority': 'localhost',
|
||||
},
|
||||
oninfo: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '103');
|
||||
strictEqual(headers.link, '</style.css>; rel=preload; as=style');
|
||||
assert.strictEqual(headers[':status'], '103');
|
||||
assert.strictEqual(headers.link, '</style.css>; rel=preload; as=style');
|
||||
clientInfoReceived.resolve();
|
||||
}),
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
strictEqual(headers['content-type'], 'text/plain');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers['content-type'], 'text/plain');
|
||||
clientHeadersReceived.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -107,10 +104,10 @@ await Promise.all([clientInfoReceived.promise, clientHeadersReceived.promise]);
|
||||
|
||||
// Read the response body.
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), responseBody);
|
||||
assert.strictEqual(decoder.decode(body), responseBody);
|
||||
|
||||
// stream.headers should return the final (initial) headers, not 1xx.
|
||||
strictEqual(stream.headers[':status'], '200');
|
||||
assert.strictEqual(stream.headers[':status'], '200');
|
||||
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
await clientSession.close();
|
||||
|
||||
@@ -9,9 +9,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual, ok } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -20,8 +17,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
@@ -58,15 +55,15 @@ const decoder = new TextDecoder();
|
||||
verifyPeer: 'manual',
|
||||
// Client receives ORIGIN frame via onorigin callback.
|
||||
onorigin: mustCall(function(origins) {
|
||||
ok(Array.isArray(origins));
|
||||
assert.ok(Array.isArray(origins));
|
||||
// The origins should include the specific SNI hostnames.
|
||||
ok(origins.length >= 2);
|
||||
assert.ok(origins.length >= 2);
|
||||
// The wildcard (*) should NOT be in the list.
|
||||
const originStrings = origins.join(',');
|
||||
ok(originStrings.includes('example.com'), 'should include example.com');
|
||||
ok(originStrings.includes('api.example.com'),
|
||||
'should include api.example.com');
|
||||
ok(!originStrings.includes('*'), 'should not include wildcard');
|
||||
assert.ok(originStrings.includes('example.com'), 'should include example.com');
|
||||
assert.ok(originStrings.includes('api.example.com'),
|
||||
'should include api.example.com');
|
||||
assert.ok(!originStrings.includes('*'), 'should not include wildcard');
|
||||
originReceived.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -80,12 +77,12 @@ const decoder = new TextDecoder();
|
||||
':authority': 'example.com',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
|
||||
await Promise.all([originReceived.promise, stream.closed, serverDone.promise]);
|
||||
await clientSession.close();
|
||||
@@ -135,33 +132,33 @@ const decoder = new TextDecoder();
|
||||
servername: 'custom-port.example.com',
|
||||
verifyPeer: 'manual',
|
||||
onorigin: mustCall(function(origins) {
|
||||
ok(Array.isArray(origins));
|
||||
assert.ok(Array.isArray(origins));
|
||||
|
||||
// Custom port included in origin string.
|
||||
ok(origins.includes('https://custom-port.example.com:8443'),
|
||||
'should include origin with custom port');
|
||||
assert.ok(origins.includes('https://custom-port.example.com:8443'),
|
||||
'should include origin with custom port');
|
||||
|
||||
// Default port 443 omitted from origin string.
|
||||
ok(origins.includes('https://default-port.example.com'),
|
||||
'should include origin without port for 443');
|
||||
assert.ok(origins.includes('https://default-port.example.com'),
|
||||
'should include origin without port for 443');
|
||||
// Verify port 443 is NOT appended.
|
||||
const defaultPortOrigin = origins.find((o) =>
|
||||
o.includes('default-port.example.com'));
|
||||
ok(!defaultPortOrigin.includes(':443'),
|
||||
'default port 443 should be omitted');
|
||||
assert.ok(!defaultPortOrigin.includes(':443'),
|
||||
'default port 443 should be omitted');
|
||||
|
||||
// Non-authoritative entry excluded.
|
||||
const allOrigins = origins.join(',');
|
||||
ok(!allOrigins.includes('not-authoritative'),
|
||||
'non-authoritative entry should be excluded');
|
||||
assert.ok(!allOrigins.includes('not-authoritative'),
|
||||
'non-authoritative entry should be excluded');
|
||||
|
||||
// Explicitly authoritative entry included.
|
||||
ok(allOrigins.includes('authoritative.example.com'),
|
||||
'explicitly authoritative entry should be included');
|
||||
assert.ok(allOrigins.includes('authoritative.example.com'),
|
||||
'explicitly authoritative entry should be included');
|
||||
|
||||
// Default authoritative (true when omitted) included.
|
||||
ok(allOrigins.includes('default-auth.example.com'),
|
||||
'default authoritative entry should be included');
|
||||
assert.ok(allOrigins.includes('default-auth.example.com'),
|
||||
'default authoritative entry should be included');
|
||||
|
||||
originReceived.resolve();
|
||||
}),
|
||||
@@ -176,12 +173,12 @@ const decoder = new TextDecoder();
|
||||
':authority': 'custom-port.example.com',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
|
||||
await Promise.all([originReceived.promise, stream.closed, serverDone.promise]);
|
||||
await clientSession.close();
|
||||
|
||||
@@ -8,9 +8,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual, deepStrictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,8 +16,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
@@ -40,8 +37,8 @@ const decoder = new TextDecoder();
|
||||
onheaders: mustCall(function(headers) {
|
||||
// Headers were enqueued before the stream opened
|
||||
// and should arrive correctly.
|
||||
strictEqual(headers[':method'], 'GET');
|
||||
strictEqual(headers[':path'], '/pending');
|
||||
assert.strictEqual(headers[':method'], 'GET');
|
||||
assert.strictEqual(headers[':path'], '/pending');
|
||||
|
||||
this.sendHeaders({ ':status': '200' });
|
||||
this.writer.writeSync(encoder.encode('ok'));
|
||||
@@ -67,22 +64,22 @@ const decoder = new TextDecoder();
|
||||
priority: 'high',
|
||||
incremental: true,
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
// Priority should reflect what was set even while pending.
|
||||
deepStrictEqual(stream.priority, { level: 'high', incremental: true });
|
||||
assert.deepStrictEqual(stream.priority, { level: 'high', incremental: true });
|
||||
|
||||
// Now wait for the handshake.
|
||||
await clientSession.opened;
|
||||
|
||||
// Priority persists after stream opens.
|
||||
deepStrictEqual(stream.priority, { level: 'high', incremental: true });
|
||||
assert.deepStrictEqual(stream.priority, { level: 'high', incremental: true });
|
||||
|
||||
// Headers were sent and server responded.
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
await clientSession.close();
|
||||
await serverEndpoint.close();
|
||||
|
||||
@@ -13,9 +13,6 @@ import { open } from 'node:fs/promises';
|
||||
|
||||
const tmpdir = await import('../common/tmpdir.js');
|
||||
|
||||
const { strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -24,8 +21,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
const testContent = 'Hello from a file!\nLine two.\n';
|
||||
@@ -41,7 +38,7 @@ writeFileSync(testFile, testContent);
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), testContent);
|
||||
assert.strictEqual(decoder.decode(body), testContent);
|
||||
|
||||
await stream.closed;
|
||||
serverSession.close();
|
||||
@@ -50,8 +47,8 @@ writeFileSync(testFile, testContent);
|
||||
}), {
|
||||
sni: { '*': { keys: [key], certs: [cert] } },
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':method'], 'POST');
|
||||
strictEqual(headers[':path'], '/upload');
|
||||
assert.strictEqual(headers[':method'], 'POST');
|
||||
assert.strictEqual(headers[':path'], '/upload');
|
||||
|
||||
this.sendHeaders({ ':status': '200' });
|
||||
this.writer.writeSync('ok');
|
||||
@@ -65,7 +62,7 @@ writeFileSync(testFile, testContent);
|
||||
});
|
||||
|
||||
const info = await clientSession.opened;
|
||||
strictEqual(info.protocol, 'h3');
|
||||
assert.strictEqual(info.protocol, 'h3');
|
||||
|
||||
const clientHeadersReceived = Promise.withResolvers();
|
||||
|
||||
@@ -79,7 +76,7 @@ writeFileSync(testFile, testContent);
|
||||
},
|
||||
body: fh,
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
clientHeadersReceived.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -87,7 +84,7 @@ writeFileSync(testFile, testContent);
|
||||
await clientHeadersReceived.promise;
|
||||
|
||||
const responseBody = await bytes(stream);
|
||||
strictEqual(decoder.decode(responseBody), 'ok');
|
||||
assert.strictEqual(decoder.decode(responseBody), 'ok');
|
||||
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
clientSession.close();
|
||||
|
||||
@@ -13,9 +13,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -24,8 +21,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
@@ -38,7 +35,7 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
// Read the full request body from the client.
|
||||
const body = await bytes(stream);
|
||||
const text = decoder.decode(body);
|
||||
strictEqual(text, requestBody);
|
||||
assert.strictEqual(text, requestBody);
|
||||
|
||||
await stream.closed;
|
||||
serverSession.close();
|
||||
@@ -47,8 +44,8 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
}), {
|
||||
sni: { '*': { keys: [key], certs: [cert] } },
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':method'], 'POST');
|
||||
strictEqual(headers[':path'], '/submit');
|
||||
assert.strictEqual(headers[':method'], 'POST');
|
||||
assert.strictEqual(headers[':path'], '/submit');
|
||||
|
||||
// Echo the request body back in the response.
|
||||
// At this point, request body hasn't arrived yet — we use onstream
|
||||
@@ -72,7 +69,7 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
});
|
||||
|
||||
const info = await clientSession.opened;
|
||||
strictEqual(info.protocol, 'h3');
|
||||
assert.strictEqual(info.protocol, 'h3');
|
||||
|
||||
const clientHeadersReceived = Promise.withResolvers();
|
||||
|
||||
@@ -87,7 +84,7 @@ const stream = await clientSession.createBidirectionalStream({
|
||||
},
|
||||
body: encoder.encode(requestBody),
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
clientHeadersReceived.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -96,7 +93,7 @@ await clientHeadersReceived.promise;
|
||||
|
||||
// Read the response body.
|
||||
const responseBody = await bytes(stream);
|
||||
strictEqual(decoder.decode(responseBody), 'echo:' + requestBody);
|
||||
assert.strictEqual(decoder.decode(responseBody), 'echo:' + requestBody);
|
||||
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
await clientSession.close();
|
||||
|
||||
@@ -12,9 +12,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
const { readKey } = fixtures;
|
||||
|
||||
const { deepStrictEqual, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
@@ -24,8 +21,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
@@ -37,9 +34,9 @@ const decoder = new TextDecoder();
|
||||
ss.onstream = mustCall((stream) => {
|
||||
// Server sees priority on the stream.
|
||||
const pri = stream.priority;
|
||||
strictEqual(typeof pri, 'object');
|
||||
strictEqual(typeof pri.level, 'string');
|
||||
strictEqual(typeof pri.incremental, 'boolean');
|
||||
assert.strictEqual(typeof pri, 'object');
|
||||
assert.strictEqual(typeof pri.level, 'string');
|
||||
assert.strictEqual(typeof pri.incremental, 'boolean');
|
||||
}, 4);
|
||||
}), {
|
||||
sni: { '*': { keys: [key], certs: [cert] } },
|
||||
@@ -70,12 +67,12 @@ const decoder = new TextDecoder();
|
||||
priority: 'high',
|
||||
incremental: false,
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
// Priority reflects what was set at creation.
|
||||
deepStrictEqual(stream1.priority, { level: 'high', incremental: false });
|
||||
assert.deepStrictEqual(stream1.priority, { level: 'high', incremental: false });
|
||||
|
||||
// Priority 'low' + incremental at creation.
|
||||
const stream2 = await clientSession.createBidirectionalStream({
|
||||
@@ -88,10 +85,10 @@ const decoder = new TextDecoder();
|
||||
priority: 'low',
|
||||
incremental: true,
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
deepStrictEqual(stream2.priority, { level: 'low', incremental: true });
|
||||
assert.deepStrictEqual(stream2.priority, { level: 'low', incremental: true });
|
||||
|
||||
// Default priority at creation.
|
||||
const stream3 = await clientSession.createBidirectionalStream({
|
||||
@@ -102,10 +99,10 @@ const decoder = new TextDecoder();
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
deepStrictEqual(stream3.priority, { level: 'default', incremental: false });
|
||||
assert.deepStrictEqual(stream3.priority, { level: 'default', incremental: false });
|
||||
|
||||
// setPriority after creation.
|
||||
const stream4 = await clientSession.createBidirectionalStream({
|
||||
@@ -116,23 +113,23 @@ const decoder = new TextDecoder();
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
// Default priority initially.
|
||||
deepStrictEqual(stream4.priority, { level: 'default', incremental: false });
|
||||
assert.deepStrictEqual(stream4.priority, { level: 'default', incremental: false });
|
||||
|
||||
// Change to high.
|
||||
stream4.setPriority({ level: 'high' });
|
||||
deepStrictEqual(stream4.priority, { level: 'high', incremental: false });
|
||||
assert.deepStrictEqual(stream4.priority, { level: 'high', incremental: false });
|
||||
|
||||
// Change to incremental.
|
||||
stream4.setPriority({ level: 'low', incremental: true });
|
||||
deepStrictEqual(stream4.priority, { level: 'low', incremental: true });
|
||||
assert.deepStrictEqual(stream4.priority, { level: 'low', incremental: true });
|
||||
|
||||
// Back to default.
|
||||
stream4.setPriority({ level: 'default', incremental: false });
|
||||
deepStrictEqual(stream4.priority, { level: 'default', incremental: false });
|
||||
assert.deepStrictEqual(stream4.priority, { level: 'default', incremental: false });
|
||||
|
||||
// Read all bodies.
|
||||
const allBodies = await Promise.all([
|
||||
@@ -142,10 +139,10 @@ const decoder = new TextDecoder();
|
||||
bytes(stream4),
|
||||
]);
|
||||
|
||||
strictEqual(decoder.decode(allBodies[0]), '/high');
|
||||
strictEqual(decoder.decode(allBodies[1]), '/low-inc');
|
||||
strictEqual(decoder.decode(allBodies[2]), '/default');
|
||||
strictEqual(decoder.decode(allBodies[3]), '/changed');
|
||||
assert.strictEqual(decoder.decode(allBodies[0]), '/high');
|
||||
assert.strictEqual(decoder.decode(allBodies[1]), '/low-inc');
|
||||
assert.strictEqual(decoder.decode(allBodies[2]), '/default');
|
||||
assert.strictEqual(decoder.decode(allBodies[3]), '/changed');
|
||||
|
||||
await Promise.all([stream1.closed,
|
||||
stream2.closed,
|
||||
@@ -173,11 +170,11 @@ const decoder = new TextDecoder();
|
||||
// data in nghttp3, so by the time body arrives the priority
|
||||
// has been updated.
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'signal');
|
||||
assert.strictEqual(decoder.decode(body), 'signal');
|
||||
|
||||
// The server's priority getter should reflect the
|
||||
// client's PRIORITY_UPDATE (high, incremental).
|
||||
deepStrictEqual(stream.priority, { level: 'high', incremental: true });
|
||||
assert.deepStrictEqual(stream.priority, { level: 'high', incremental: true });
|
||||
serverSawHighPriority.resolve();
|
||||
|
||||
await stream.closed;
|
||||
@@ -218,21 +215,21 @@ const decoder = new TextDecoder();
|
||||
},
|
||||
body: encoder.encode('signal'),
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
deepStrictEqual(stream.priority, { level: 'default', incremental: false });
|
||||
assert.deepStrictEqual(stream.priority, { level: 'default', incremental: false });
|
||||
|
||||
// Change priority — this sends a PRIORITY_UPDATE frame on the
|
||||
// control stream. The body data was already provided at creation
|
||||
// but the PRIORITY_UPDATE travels on the control stream which
|
||||
// nghttp3 prioritizes over bidi streams.
|
||||
stream.setPriority({ level: 'high', incremental: true });
|
||||
deepStrictEqual(stream.priority, { level: 'high', incremental: true });
|
||||
assert.deepStrictEqual(stream.priority, { level: 'high', incremental: true });
|
||||
|
||||
// Read the response.
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
|
||||
// Wait for server to confirm it saw the updated priority.
|
||||
await Promise.all([serverSawHighPriority.promise,
|
||||
|
||||
@@ -13,9 +13,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -24,8 +21,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
@@ -38,11 +35,11 @@ async function makeRequest(clientSession, path) {
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), path);
|
||||
assert.strictEqual(decoder.decode(body), path);
|
||||
await stream.closed;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
const { readKey } = fixtures;
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
@@ -24,8 +21,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
@@ -53,14 +50,14 @@ const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
// headers and stream[kHeaders] asserts the callback exists.
|
||||
onheaders: mustCall(function(headers) {
|
||||
// Verify request pseudo-headers.
|
||||
strictEqual(headers[':method'], 'GET');
|
||||
strictEqual(headers[':path'], '/index.html');
|
||||
strictEqual(headers[':scheme'], 'https');
|
||||
strictEqual(headers[':authority'], 'localhost');
|
||||
assert.strictEqual(headers[':method'], 'GET');
|
||||
assert.strictEqual(headers[':path'], '/index.html');
|
||||
assert.strictEqual(headers[':scheme'], 'https');
|
||||
assert.strictEqual(headers[':authority'], 'localhost');
|
||||
|
||||
// After onheaders, stream.headers returns the initial headers.
|
||||
// `this` is the stream (bound by the onheaders setter).
|
||||
strictEqual(this.headers[':method'], 'GET');
|
||||
assert.strictEqual(this.headers[':method'], 'GET');
|
||||
|
||||
// Send response headers (terminal: false is the default — body follows).
|
||||
this.sendHeaders({
|
||||
@@ -82,7 +79,7 @@ const clientSession = await connect(serverEndpoint.address, {
|
||||
});
|
||||
|
||||
const info = await clientSession.opened;
|
||||
strictEqual(info.protocol, 'h3');
|
||||
assert.strictEqual(info.protocol, 'h3');
|
||||
|
||||
const clientHeadersReceived = Promise.withResolvers();
|
||||
|
||||
@@ -96,8 +93,8 @@ const stream = await clientSession.createBidirectionalStream({
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
strictEqual(headers['content-type'], 'text/plain');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers['content-type'], 'text/plain');
|
||||
clientHeadersReceived.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -106,10 +103,10 @@ await clientHeadersReceived.promise;
|
||||
|
||||
// Read the full response body.
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), responseBody);
|
||||
assert.strictEqual(decoder.decode(body), responseBody);
|
||||
|
||||
// stream.headers should return the buffered response headers.
|
||||
strictEqual(stream.headers[':status'], '200');
|
||||
assert.strictEqual(stream.headers[':status'], '200');
|
||||
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
await clientSession.close();
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
const { readKey } = fixtures;
|
||||
|
||||
const { strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
@@ -21,8 +18,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
@@ -43,14 +40,14 @@ const decoder = new TextDecoder();
|
||||
// Allow 5 header pairs: 4 pseudo-headers + 1 custom.
|
||||
application: { maxHeaderPairs: 5 },
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':method'], 'GET');
|
||||
strictEqual(headers[':path'], '/limited');
|
||||
strictEqual(headers[':scheme'], 'https');
|
||||
strictEqual(headers[':authority'], 'localhost');
|
||||
assert.strictEqual(headers[':method'], 'GET');
|
||||
assert.strictEqual(headers[':path'], '/limited');
|
||||
assert.strictEqual(headers[':scheme'], 'https');
|
||||
assert.strictEqual(headers[':authority'], 'localhost');
|
||||
// x-first is the 5th pair — accepted.
|
||||
strictEqual(headers['x-first'], 'one');
|
||||
assert.strictEqual(headers['x-first'], 'one');
|
||||
// x-second would be the 6th pair — dropped.
|
||||
strictEqual(headers['x-second'], undefined);
|
||||
assert.strictEqual(headers['x-second'], undefined);
|
||||
|
||||
this.sendHeaders({ ':status': '200' });
|
||||
this.writer.writeSync(encoder.encode('ok'));
|
||||
@@ -74,12 +71,12 @@ const decoder = new TextDecoder();
|
||||
'x-second': 'two',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
await stream.closed;
|
||||
await serverDone.promise;
|
||||
await clientSession.close();
|
||||
@@ -106,10 +103,10 @@ const decoder = new TextDecoder();
|
||||
// bytes, but adding x-long (6 + 200 = 206 bytes) exceeds it.
|
||||
application: { maxHeaderLength: 100 },
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':method'], 'GET');
|
||||
strictEqual(headers[':path'], '/length-limited');
|
||||
assert.strictEqual(headers[':method'], 'GET');
|
||||
assert.strictEqual(headers[':path'], '/length-limited');
|
||||
// x-long should be dropped — would push total over 100 bytes.
|
||||
strictEqual(headers['x-long'], undefined);
|
||||
assert.strictEqual(headers['x-long'], undefined);
|
||||
|
||||
this.sendHeaders({ ':status': '200' });
|
||||
this.writer.writeSync(encoder.encode('ok'));
|
||||
@@ -132,12 +129,12 @@ const decoder = new TextDecoder();
|
||||
'x-long': longValue,
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
await clientSession.close();
|
||||
await serverEndpoint.close();
|
||||
@@ -163,8 +160,8 @@ const decoder = new TextDecoder();
|
||||
this.writer.endSync();
|
||||
}),
|
||||
onapplication: mustCall((appopt) => {
|
||||
strictEqual(appopt.enableDatagrams, true);
|
||||
strictEqual(appopt.enableConnectProtocol, false);
|
||||
assert.strictEqual(appopt.enableDatagrams, true);
|
||||
assert.strictEqual(appopt.enableConnectProtocol, false);
|
||||
// Must be false, as this is only sent from server side
|
||||
})
|
||||
});
|
||||
@@ -175,8 +172,8 @@ const decoder = new TextDecoder();
|
||||
application: { enableConnectProtocol: true, enableDatagrams: true },
|
||||
});
|
||||
clientSession.onapplication = mustCall((appopt) => {
|
||||
strictEqual(appopt.enableConnectProtocol, true);
|
||||
strictEqual(appopt.enableDatagrams, true);
|
||||
assert.strictEqual(appopt.enableConnectProtocol, true);
|
||||
assert.strictEqual(appopt.enableDatagrams, true);
|
||||
});
|
||||
await clientSession.opened;
|
||||
|
||||
@@ -188,12 +185,12 @@ const decoder = new TextDecoder();
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), 'settings-ok');
|
||||
assert.strictEqual(decoder.decode(body), 'settings-ok');
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
await clientSession.close();
|
||||
await serverEndpoint.close();
|
||||
|
||||
@@ -8,9 +8,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -18,8 +15,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const serverDone = Promise.withResolvers();
|
||||
|
||||
@@ -52,7 +49,7 @@ const stream = await clientSession.createBidirectionalStream({
|
||||
stream.destroy();
|
||||
|
||||
// Verify the stream is destroyed without crash.
|
||||
strictEqual(stream.destroyed, true);
|
||||
assert.strictEqual(stream.destroyed, true);
|
||||
|
||||
// Close everything cleanly.
|
||||
await clientSession.close();
|
||||
|
||||
@@ -13,9 +13,6 @@ import { setTimeout } from 'node:timers/promises';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
import { text } from 'node:stream/iter';
|
||||
|
||||
const { rejects, strictEqual } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -23,8 +20,8 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
@@ -36,7 +33,7 @@ const encoder = new TextEncoder();
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
// Don't read — let the stream sit idle after the initial headers.
|
||||
// The stream idle timeout should destroy it, rejecting stream.closed.
|
||||
await rejects(stream.closed, {
|
||||
await assert.rejects(stream.closed, {
|
||||
code: 'ERR_QUIC_TRANSPORT_ERROR',
|
||||
});
|
||||
streamDestroyed.resolve();
|
||||
@@ -77,7 +74,7 @@ const encoder = new TextEncoder();
|
||||
// The server sent STOP_SENDING / RESET_STREAM when it destroyed the
|
||||
// idle stream. ShutdownStream maps the transport error to the H3
|
||||
// internal error code (0x102) on the wire.
|
||||
await rejects(stream.closed, {
|
||||
await assert.rejects(stream.closed, {
|
||||
code: 'ERR_QUIC_APPLICATION_ERROR',
|
||||
});
|
||||
|
||||
@@ -92,7 +89,7 @@ const encoder = new TextEncoder();
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
const data = await text(stream);
|
||||
strictEqual(data, 'xy');
|
||||
assert.strictEqual(data, 'xy');
|
||||
serverGotData.resolve();
|
||||
await serverSession.close();
|
||||
});
|
||||
@@ -100,7 +97,7 @@ const encoder = new TextEncoder();
|
||||
sni: { '*': { keys: [key], certs: [cert] } },
|
||||
streamIdleTimeout: 500,
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':method'], 'POST');
|
||||
assert.strictEqual(headers[':method'], 'POST');
|
||||
// Send response headers so the stream is fully established.
|
||||
this.sendHeaders({ ':status': '200' }, { terminal: true });
|
||||
}),
|
||||
@@ -142,7 +139,7 @@ const encoder = new TextEncoder();
|
||||
const serverEndpoint = await listen(mustCall(async (serverSession) => {
|
||||
serverSession.onstream = mustCall(async (stream) => {
|
||||
const data = await text(stream);
|
||||
strictEqual(data, 'xy');
|
||||
assert.strictEqual(data, 'xy');
|
||||
streamSurvived.resolve();
|
||||
});
|
||||
|
||||
|
||||
@@ -13,9 +13,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import dc from 'node:diagnostics_channel';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
const { readKey } = fixtures;
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
@@ -25,8 +22,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
@@ -35,17 +32,17 @@ const responseBody = 'body with trailers';
|
||||
// quic.stream.headers fires when initial headers are received.
|
||||
// Fires for both the server (request headers) and client (response headers).
|
||||
dc.subscribe('quic.stream.headers', mustCall((msg) => {
|
||||
ok(msg.stream, 'stream.headers should include stream');
|
||||
ok(msg.session, 'stream.headers should include session');
|
||||
ok(msg.headers, 'stream.headers should include headers');
|
||||
assert.ok(msg.stream, 'stream.headers should include stream');
|
||||
assert.ok(msg.session, 'stream.headers should include session');
|
||||
assert.ok(msg.headers, 'stream.headers should include headers');
|
||||
}, 2));
|
||||
|
||||
// quic.stream.trailers fires when trailing headers are received.
|
||||
dc.subscribe('quic.stream.trailers', mustCall((msg) => {
|
||||
ok(msg.stream, 'stream.trailers should include stream');
|
||||
ok(msg.session, 'stream.trailers should include session');
|
||||
ok(msg.trailers, 'stream.trailers should include trailers');
|
||||
strictEqual(msg.trailers['x-checksum'], 'abc123');
|
||||
assert.ok(msg.stream, 'stream.trailers should include stream');
|
||||
assert.ok(msg.session, 'stream.trailers should include session');
|
||||
assert.ok(msg.trailers, 'stream.trailers should include trailers');
|
||||
assert.strictEqual(msg.trailers['x-checksum'], 'abc123');
|
||||
}));
|
||||
|
||||
const serverDone = Promise.withResolvers();
|
||||
@@ -97,12 +94,12 @@ const stream = await clientSession.createBidirectionalStream({
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
clientHeadersReceived.resolve();
|
||||
}),
|
||||
ontrailers: mustCall(function(trailers) {
|
||||
strictEqual(trailers['x-checksum'], 'abc123');
|
||||
strictEqual(trailers['x-request-id'], '42');
|
||||
assert.strictEqual(trailers['x-checksum'], 'abc123');
|
||||
assert.strictEqual(trailers['x-request-id'], '42');
|
||||
clientTrailersReceived.resolve();
|
||||
}),
|
||||
});
|
||||
@@ -111,13 +108,13 @@ await clientHeadersReceived.promise;
|
||||
|
||||
// Read the response body.
|
||||
const body = await bytes(stream);
|
||||
strictEqual(decoder.decode(body), responseBody);
|
||||
assert.strictEqual(decoder.decode(body), responseBody);
|
||||
|
||||
// Trailers arrive after the body.
|
||||
await clientTrailersReceived.promise;
|
||||
|
||||
// stream.headers should still be the initial headers, not trailers.
|
||||
strictEqual(stream.headers[':status'], '200');
|
||||
assert.strictEqual(stream.headers[':status'], '200');
|
||||
|
||||
await Promise.all([stream.closed, serverDone.promise]);
|
||||
await clientSession.close();
|
||||
|
||||
@@ -9,9 +9,6 @@ import { hasQuic, skip, mustNotCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { rejects } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -19,15 +16,15 @@ if (!hasQuic) {
|
||||
const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey, randomBytes } = await import('node:crypto');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
|
||||
const serverEndpoint = await listen(mustNotCall(), {
|
||||
sni: { '*': { keys: [key], certs: [cert] } },
|
||||
});
|
||||
|
||||
// Bogus ticket data (random bytes) is rejected at the format level.
|
||||
await rejects(
|
||||
await assert.rejects(
|
||||
connect(serverEndpoint.address, {
|
||||
servername: 'localhost',
|
||||
verifyPeer: 'manual',
|
||||
|
||||
@@ -13,9 +13,6 @@ import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
|
||||
const { ok, strictEqual, rejects } = assert;
|
||||
const { readKey } = fixtures;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
}
|
||||
@@ -24,8 +21,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey, randomBytes } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const sni = { '*': { keys: [key], certs: [cert] } };
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
@@ -55,16 +52,16 @@ async function getTicket(endpointOptions) {
|
||||
servername: 'localhost',
|
||||
verifyPeer: 'manual',
|
||||
...endpointOptions,
|
||||
onsessionticket(ticket) {
|
||||
ok(Buffer.isBuffer(ticket));
|
||||
onsessionticket: mustCall((ticket) => {
|
||||
assert.ok(Buffer.isBuffer(ticket));
|
||||
savedTicket = ticket;
|
||||
gotTicket.resolve();
|
||||
},
|
||||
onnewtoken(token) {
|
||||
ok(Buffer.isBuffer(token));
|
||||
}, 2),
|
||||
onnewtoken: mustCall((token) => {
|
||||
assert.ok(Buffer.isBuffer(token));
|
||||
savedToken = token;
|
||||
gotToken.resolve();
|
||||
},
|
||||
}),
|
||||
});
|
||||
await cs.opened;
|
||||
await Promise.all([gotTicket.promise, gotToken.promise]);
|
||||
@@ -77,11 +74,11 @@ async function getTicket(endpointOptions) {
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
const body = await bytes(s);
|
||||
strictEqual(decoder.decode(body), 'ok');
|
||||
assert.strictEqual(decoder.decode(body), 'ok');
|
||||
await Promise.all([s.closed, cs.closed]);
|
||||
await ep.close();
|
||||
|
||||
@@ -122,13 +119,13 @@ async function attemptRejected0RTT(endpointOptions, ticket, token) {
|
||||
':authority': 'localhost',
|
||||
},
|
||||
});
|
||||
await rejects(s.closed, {
|
||||
await assert.rejects(s.closed, {
|
||||
code: 'ERR_QUIC_APPLICATION_ERROR',
|
||||
});
|
||||
|
||||
const info = await cs.opened;
|
||||
strictEqual(info.earlyDataAttempted, true);
|
||||
strictEqual(info.earlyDataAccepted, false);
|
||||
assert.strictEqual(info.earlyDataAttempted, true);
|
||||
assert.strictEqual(info.earlyDataAccepted, false);
|
||||
|
||||
cs.close();
|
||||
ep.close();
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
import { hasQuic, skip, mustCall } from '../common/index.mjs';
|
||||
import assert from 'node:assert';
|
||||
import * as fixtures from '../common/fixtures.mjs';
|
||||
const { readKey } = fixtures;
|
||||
|
||||
const { ok, strictEqual } = assert;
|
||||
|
||||
if (!hasQuic) {
|
||||
skip('QUIC is not enabled');
|
||||
@@ -21,8 +18,8 @@ const { listen, connect } = await import('node:quic');
|
||||
const { createPrivateKey } = await import('node:crypto');
|
||||
const { bytes } = await import('stream/iter');
|
||||
|
||||
const key = createPrivateKey(readKey('agent1-key.pem'));
|
||||
const cert = readKey('agent1-cert.pem');
|
||||
const key = createPrivateKey(fixtures.readKey('agent1-key.pem'));
|
||||
const cert = fixtures.readKey('agent1-cert.pem');
|
||||
const encoder = new TextEncoder();
|
||||
const decoder = new TextDecoder();
|
||||
|
||||
@@ -60,21 +57,21 @@ const cs1 = await connect(serverEndpoint.address, {
|
||||
servername: 'localhost',
|
||||
verifyPeer: 'manual',
|
||||
onsessionticket: mustCall(function(ticket) {
|
||||
ok(Buffer.isBuffer(ticket));
|
||||
ok(ticket.length > 0);
|
||||
assert.ok(Buffer.isBuffer(ticket));
|
||||
assert.ok(ticket.length > 0);
|
||||
savedTicket = ticket;
|
||||
gotTicket.resolve();
|
||||
}, 2),
|
||||
onnewtoken: mustCall(function(token) {
|
||||
ok(Buffer.isBuffer(token));
|
||||
assert.ok(Buffer.isBuffer(token));
|
||||
savedToken = token;
|
||||
gotToken.resolve();
|
||||
}),
|
||||
});
|
||||
|
||||
const info1 = await cs1.opened;
|
||||
strictEqual(info1.earlyDataAttempted, false);
|
||||
strictEqual(info1.earlyDataAccepted, false);
|
||||
assert.strictEqual(info1.earlyDataAttempted, false);
|
||||
assert.strictEqual(info1.earlyDataAccepted, false);
|
||||
|
||||
await Promise.all([gotTicket.promise, gotToken.promise]);
|
||||
|
||||
@@ -86,16 +83,16 @@ const s1 = await cs1.createBidirectionalStream({
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
const body1 = await bytes(s1);
|
||||
strictEqual(decoder.decode(body1), '/first');
|
||||
assert.strictEqual(decoder.decode(body1), '/first');
|
||||
await Promise.all([s1.closed, cs1.closed]);
|
||||
|
||||
// Session ticket should have been received.
|
||||
ok(savedTicket);
|
||||
ok(savedToken);
|
||||
assert.ok(savedTicket);
|
||||
assert.ok(savedToken);
|
||||
|
||||
// --- Second connection: 0-RTT with H3 ---
|
||||
const cs2 = await connect(serverEndpoint.address, {
|
||||
@@ -114,20 +111,20 @@ const s2 = await cs2.createBidirectionalStream({
|
||||
':authority': 'localhost',
|
||||
},
|
||||
onheaders: mustCall(function(headers) {
|
||||
strictEqual(headers[':status'], '200');
|
||||
assert.strictEqual(headers[':status'], '200');
|
||||
}),
|
||||
});
|
||||
|
||||
const info2 = await cs2.opened;
|
||||
strictEqual(info2.earlyDataAttempted, true);
|
||||
strictEqual(info2.earlyDataAccepted, true);
|
||||
assert.strictEqual(info2.earlyDataAttempted, true);
|
||||
assert.strictEqual(info2.earlyDataAccepted, true);
|
||||
|
||||
const body2 = await bytes(s2);
|
||||
strictEqual(decoder.decode(body2), '/early');
|
||||
assert.strictEqual(decoder.decode(body2), '/early');
|
||||
await s2.closed;
|
||||
|
||||
const earlyStream = await secondDone.promise;
|
||||
strictEqual(earlyStream.early, true);
|
||||
assert.strictEqual(earlyStream.early, true);
|
||||
|
||||
await cs2.closed;
|
||||
await serverEndpoint.close();
|
||||
Loaded 100 of 234 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user