mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
test(firmware): share the short positional read fixture (#16953)
This commit is contained in:
1 parent
47443f4c64
commit
2ddfb362ff
3 files changed
+35
-56
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { shortReadAfterStreamFileSystem } from "../../../tests/fixtures/firmwareShortReadFileSystem.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { lstat, open, realpath, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
@@ -211,34 +212,7 @@ describe("FirmwareMmioProvider", () => {
|
||||
expect(cancelled.error.cause).toBe(abortReason);
|
||||
|
||||
const shortReadProvider = new FirmwareMmioProvider({
|
||||
fileSystem: {
|
||||
lstat: (path) => lstat(path, { bigint: true }),
|
||||
realpath,
|
||||
open: async (path, flags, mode) => {
|
||||
const handle = await open(path, flags, mode);
|
||||
const originalRead = handle.read.bind(handle);
|
||||
let streamed = false;
|
||||
handle.read = (async (
|
||||
buffer: Buffer,
|
||||
bufOffset?: number | null,
|
||||
length?: number | null,
|
||||
position?: number | bigint | null,
|
||||
) => {
|
||||
const res = await originalRead(
|
||||
buffer,
|
||||
bufOffset ?? 0,
|
||||
length ?? buffer.length,
|
||||
position ?? null,
|
||||
);
|
||||
if (res.bytesRead === 0) streamed = true;
|
||||
else if (streamed && typeof position === "number" && position > 0) {
|
||||
return { bytesRead: 0, buffer };
|
||||
}
|
||||
return res;
|
||||
}) as typeof handle.read;
|
||||
return handle;
|
||||
},
|
||||
},
|
||||
fileSystem: shortReadAfterStreamFileSystem(),
|
||||
});
|
||||
const integrityRes = await shortReadProvider.inspect(
|
||||
inspectFirmwareMmioInputSchema.parse({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { shortReadAfterStreamFileSystem } from "../../../tests/fixtures/firmwareShortReadFileSystem.js";
|
||||
import { expectXmlElementDepthRefusal } from "../../../tests/support/expectXmlElementDepthRefusal.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { lstat, open, realpath, writeFile } from "node:fs/promises";
|
||||
@@ -237,34 +238,7 @@ describe("FirmwareVectorTableProvider", () => {
|
||||
|
||||
// 5. Short positional read at non-zero offset classifies as changed-target integrity failure
|
||||
const shortReadProvider = new FirmwareVectorTableProvider({
|
||||
fileSystem: {
|
||||
lstat: (path) => lstat(path, { bigint: true }),
|
||||
realpath,
|
||||
open: async (path, flags, mode) => {
|
||||
const handle = await open(path, flags, mode);
|
||||
const originalRead = handle.read.bind(handle);
|
||||
let streamed = false;
|
||||
handle.read = (async (
|
||||
buffer: Buffer,
|
||||
bufOffset?: number | null,
|
||||
length?: number | null,
|
||||
position?: number | bigint | null,
|
||||
) => {
|
||||
const res = await originalRead(
|
||||
buffer,
|
||||
bufOffset ?? 0,
|
||||
length ?? buffer.length,
|
||||
position ?? null,
|
||||
);
|
||||
if (res.bytesRead === 0) streamed = true;
|
||||
else if (streamed && typeof position === "number" && position > 0) {
|
||||
return { bytesRead: 0, buffer };
|
||||
}
|
||||
return res;
|
||||
}) as typeof handle.read;
|
||||
return handle;
|
||||
},
|
||||
},
|
||||
fileSystem: shortReadAfterStreamFileSystem(),
|
||||
});
|
||||
const integrityRes = await shortReadProvider.inspect(
|
||||
inspectFirmwareVectorTableInputSchema.parse({
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import { lstat, open, realpath } from "node:fs/promises";
|
||||
import type { StableArtifactFileSystem } from "../../src/resources/readStableArtifact.js";
|
||||
|
||||
export const shortReadAfterStreamFileSystem = (): StableArtifactFileSystem => ({
|
||||
lstat: (path) => lstat(path, { bigint: true }),
|
||||
realpath,
|
||||
open: async (path, flags, mode) => {
|
||||
const handle = await open(path, flags, mode);
|
||||
const originalRead = handle.read.bind(handle);
|
||||
let streamed = false;
|
||||
handle.read = (async (
|
||||
buffer: Buffer,
|
||||
bufOffset?: number | null,
|
||||
length?: number | null,
|
||||
position?: number | bigint | null,
|
||||
) => {
|
||||
const res = await originalRead(
|
||||
buffer,
|
||||
bufOffset ?? 0,
|
||||
length ?? buffer.length,
|
||||
position ?? null,
|
||||
);
|
||||
if (res.bytesRead === 0) streamed = true;
|
||||
else if (streamed && typeof position === "number" && position > 0) {
|
||||
return { bytesRead: 0, buffer };
|
||||
}
|
||||
return res;
|
||||
}) as typeof handle.read;
|
||||
return handle;
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user