mirror of
https://github.com/morluto/rea
synced 2026-10-28 06:46:47 -04:00
fix(pcap): preserve metadata on duration overflow
This commit is contained in:
@@ -581,6 +581,25 @@ it("accepts exact machine packet counts and rejects scaled human counts", () =>
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["0", 0],
|
||||
["1.250 seconds", 1.25],
|
||||
["2 second", 2],
|
||||
["n/a", null],
|
||||
["-1 seconds", null],
|
||||
[`${"9".repeat(309)} seconds`, null],
|
||||
] as const)(
|
||||
"retains finite capinfos duration %s and preserves other metadata",
|
||||
(duration, expected) => {
|
||||
const metadata = parseCapinfosOutput(
|
||||
`File type: pcap\nFile encapsulation: Ethernet\nNumber of packets: 2\nCapture duration: ${duration}\nPacket size limit: file hdr: 65535 bytes\n`,
|
||||
);
|
||||
expect(metadata.captureDurationSeconds).toBe(expected);
|
||||
expect(metadata.packetCount).toBe(2);
|
||||
expect(metadata.snapshotLength).toBe(65535);
|
||||
},
|
||||
);
|
||||
|
||||
it("excludes transport credentials without normalizing observed URL bytes", async () => {
|
||||
const result = await parseTsharkJsonOutput(
|
||||
capture([
|
||||
|
||||
@@ -104,6 +104,7 @@ export const parseCapinfosOutput = (stdout: string): CapinfosMetadata => {
|
||||
durationText === undefined
|
||||
? null
|
||||
: /^(\d+(?:\.\d+)?)(?:\s+seconds?)?$/u.exec(durationText);
|
||||
const durationSeconds = duration === null ? null : Number(duration[1]);
|
||||
const snapshot = /^file hdr:\s*(\d+) bytes$/u.exec(
|
||||
lines.get("Packet size limit") ?? "",
|
||||
);
|
||||
@@ -121,7 +122,10 @@ export const parseCapinfosOutput = (stdout: string): CapinfosMetadata => {
|
||||
captureEnd: captureInstant(
|
||||
lines.get("Latest packet time") ?? lines.get("Last packet time"),
|
||||
),
|
||||
captureDurationSeconds: duration === null ? null : Number(duration[1]),
|
||||
captureDurationSeconds:
|
||||
durationSeconds !== null && Number.isFinite(durationSeconds)
|
||||
? durationSeconds
|
||||
: null,
|
||||
snapshotLength:
|
||||
snapshotLength !== null &&
|
||||
Number.isSafeInteger(snapshotLength) &&
|
||||
|
||||
Reference in New Issue
Block a user