mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:10:43 +00:00
test: share msteams attachment fixtures
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { mockPinnedHostnameResolution } from "../../../src/test-helpers/ssrf.js";
|
||||
import type { PluginRuntime } from "../runtime-api.js";
|
||||
import { readRemoteMediaResponse } from "./attachments.test-helpers.js";
|
||||
import { downloadMSTeamsGraphMedia } from "./attachments/graph.js";
|
||||
import { resolveRequestUrl } from "./attachments/shared.js";
|
||||
import { setMSTeamsRuntime } from "./runtime.js";
|
||||
@@ -23,23 +24,6 @@ const saveMediaBufferMock = vi.fn(async () => ({
|
||||
size: Buffer.byteLength(PNG_BUFFER),
|
||||
contentType: CONTENT_TYPE_IMAGE_PNG,
|
||||
}));
|
||||
const readRemoteMediaResponse = async (
|
||||
res: Response,
|
||||
params: { maxBytes?: number; filePathHint?: string },
|
||||
) => {
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP ${res.status}`);
|
||||
}
|
||||
const buffer = Buffer.from(await res.arrayBuffer());
|
||||
if (typeof params.maxBytes === "number" && buffer.byteLength > params.maxBytes) {
|
||||
throw new Error(`payload exceeds maxBytes ${params.maxBytes}`);
|
||||
}
|
||||
return {
|
||||
buffer,
|
||||
contentType: res.headers.get("content-type") ?? undefined,
|
||||
fileName: params.filePathHint,
|
||||
};
|
||||
};
|
||||
const fetchRemoteMediaMock = vi.fn(
|
||||
async (params: {
|
||||
url: string;
|
||||
|
||||
17
extensions/msteams/src/attachments.test-helpers.ts
Normal file
17
extensions/msteams/src/attachments.test-helpers.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export async function readRemoteMediaResponse(
|
||||
res: Response,
|
||||
params: { maxBytes?: number; filePathHint?: string },
|
||||
) {
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP ${res.status}`);
|
||||
}
|
||||
const buffer = Buffer.from(await res.arrayBuffer());
|
||||
if (typeof params.maxBytes === "number" && buffer.byteLength > params.maxBytes) {
|
||||
throw new Error(`payload exceeds maxBytes ${params.maxBytes}`);
|
||||
}
|
||||
return {
|
||||
buffer,
|
||||
contentType: res.headers.get("content-type") ?? undefined,
|
||||
fileName: params.filePathHint,
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { PluginRuntime, SsrFPolicy } from "../runtime-api.js";
|
||||
import { readRemoteMediaResponse } from "./attachments.test-helpers.js";
|
||||
import { downloadMSTeamsAttachments } from "./attachments/download.js";
|
||||
import { resolveRequestUrl } from "./attachments/shared.js";
|
||||
import { setMSTeamsRuntime } from "./runtime.js";
|
||||
@@ -46,24 +47,6 @@ const saveMediaBufferMock = vi.fn(async () => ({
|
||||
size: Buffer.byteLength(PNG_BUFFER),
|
||||
contentType: CONTENT_TYPE_IMAGE_PNG,
|
||||
}));
|
||||
const readRemoteMediaResponse = async (
|
||||
res: Response,
|
||||
params: Pick<RemoteMediaFetchParams, "maxBytes" | "filePathHint">,
|
||||
) => {
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP ${res.status}`);
|
||||
}
|
||||
const buffer = Buffer.from(await res.arrayBuffer());
|
||||
if (typeof params.maxBytes === "number" && buffer.byteLength > params.maxBytes) {
|
||||
throw new Error(`payload exceeds maxBytes ${params.maxBytes}`);
|
||||
}
|
||||
return {
|
||||
buffer,
|
||||
contentType: res.headers.get("content-type") ?? undefined,
|
||||
fileName: params.filePathHint,
|
||||
};
|
||||
};
|
||||
|
||||
function isHostnameAllowedByPattern(hostname: string, pattern: string): boolean {
|
||||
if (pattern.startsWith("*.")) {
|
||||
const suffix = pattern.slice(2);
|
||||
|
||||
Reference in New Issue
Block a user