mirror of https://github.com/openclaw/openclaw.git
test: stabilize media attachment cache path assertions
This commit is contained in:
parent
4c45fc3575
commit
555a4d896c
|
|
@ -125,6 +125,7 @@ describe("media understanding attachments SSRF", () => {
|
|||
const attachmentPath = path.join(allowedRoot, "voice-note.m4a");
|
||||
await fs.mkdir(allowedRoot, { recursive: true });
|
||||
await fs.writeFile(attachmentPath, "ok");
|
||||
const canonicalAttachmentPath = await fs.realpath(attachmentPath).catch(() => attachmentPath);
|
||||
|
||||
const cache = new MediaAttachmentCache([{ index: 0, path: attachmentPath }], {
|
||||
localPathRoots: [allowedRoot],
|
||||
|
|
@ -134,7 +135,9 @@ describe("media understanding attachments SSRF", () => {
|
|||
|
||||
openSpy.mockImplementation(async (filePath, flags) => {
|
||||
const handle = await originalOpen(filePath, flags);
|
||||
if (filePath !== attachmentPath) {
|
||||
const candidatePath =
|
||||
(await fs.realpath(String(filePath)).catch(() => String(filePath))) ?? String(filePath);
|
||||
if (candidatePath !== canonicalAttachmentPath) {
|
||||
return handle;
|
||||
}
|
||||
const mockedHandle = handle as typeof handle & {
|
||||
|
|
@ -159,6 +162,7 @@ describe("media understanding attachments SSRF", () => {
|
|||
const attachmentPath = path.join(allowedRoot, "voice-note.m4a");
|
||||
await fs.mkdir(allowedRoot, { recursive: true });
|
||||
await fs.writeFile(attachmentPath, "ok");
|
||||
const canonicalAttachmentPath = await fs.realpath(attachmentPath).catch(() => attachmentPath);
|
||||
|
||||
const cache = new MediaAttachmentCache([{ index: 0, path: attachmentPath }], {
|
||||
localPathRoots: [allowedRoot],
|
||||
|
|
@ -167,10 +171,12 @@ describe("media understanding attachments SSRF", () => {
|
|||
|
||||
await cache.getBuffer({ attachmentIndex: 0, maxBytes: 1024, timeoutMs: 1000 });
|
||||
|
||||
expect(openSpy).toHaveBeenCalledWith(
|
||||
attachmentPath,
|
||||
fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW,
|
||||
expect(openSpy).toHaveBeenCalled();
|
||||
const [openedPath, openedFlags] = openSpy.mock.calls[0] ?? [];
|
||||
expect(await fs.realpath(String(openedPath)).catch(() => String(openedPath))).toBe(
|
||||
canonicalAttachmentPath,
|
||||
);
|
||||
expect(openedFlags).toBe(fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue