db02f0058d
* Regression tests for telling a refused PDU from a failed session * Export PduRefusedError so a refusal can be told from a session failure * Document telling a refused PDU from a session failure * Share the malformed-PDU fixtures and pin that a dead stream is no refusal * Say once what a refusal is, and why the header type is published * Fold the refused-response test into the one that already staged it * Drop the refusal-rate claim the interop finding does not support * Build a raw PDU one way, sequence number included * Follow PduRefusedError into pdu-refusal.ts
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import type { PduObjectInput } from '../src/pdu.ts';
|
|
import { objToPdu } from '../src/pdu.ts';
|
|
|
|
/** The octets a test writes straight to a socket, which objToPdu builds for every valid PDU. */
|
|
export function pduBytes(input: PduObjectInput): Buffer {
|
|
const { buffer } = objToPdu(input);
|
|
|
|
assert.ok(buffer);
|
|
|
|
return buffer;
|
|
}
|
|
|
|
/** The same, wearing a command id the command table defines nothing for. */
|
|
export function withUnknownCmdId(input: PduObjectInput): Buffer {
|
|
const buffer = pduBytes(input);
|
|
|
|
buffer.writeUInt32BE(0x00010001, 4);
|
|
|
|
return buffer;
|
|
}
|
|
|
|
/** command_length honoured, so the stream stays in sync, with the declared body cut short. */
|
|
export function shortened(input: PduObjectInput, octets: number): Buffer {
|
|
const buffer = pduBytes(input);
|
|
const cut = buffer.subarray(0, buffer.length - octets);
|
|
|
|
cut.writeUInt32BE(cut.length, 0);
|
|
|
|
return cut;
|
|
}
|
|
|
|
/** The same, with a message_state TLV declaring four octets of value and carrying one. */
|
|
export function truncatedTlv(input: PduObjectInput): Buffer {
|
|
const appended = Buffer.concat([pduBytes(input), Buffer.from('0427000401', 'hex')]);
|
|
|
|
appended.writeUInt32BE(appended.length, 0);
|
|
|
|
return appended;
|
|
}
|