42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
// @vitest-environment node
|
|
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
loadRequiredWebConfig: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("@hivegrid/config", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("@hivegrid/config")>()),
|
|
loadRequiredWebConfig: mocks.loadRequiredWebConfig,
|
|
}));
|
|
|
|
const { storeFile } = await import("./storageService");
|
|
|
|
describe("storeFile fail-closed upload behavior", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
mocks.loadRequiredWebConfig.mockReturnValue({ storage: {} });
|
|
});
|
|
|
|
test("rejects scanned user content when no storage provider is configured", async () => {
|
|
await expect(
|
|
storeFile({
|
|
bucket: "users-icons",
|
|
content: "data:image/png;base64,iVBORw0KGgo=",
|
|
id: "user_1",
|
|
scan: { context: "avatar", requireMalwareScan: true, filename: "user_1.png" },
|
|
}),
|
|
).rejects.toMatchObject({ name: "StorageAdapterError", code: "config_missing" });
|
|
});
|
|
|
|
test("preserves the legacy soft fallback only for server-trusted content", async () => {
|
|
await expect(
|
|
storeFile({
|
|
bucket: "internal",
|
|
content: "data:text/plain;base64,aGVsbG8=",
|
|
id: "generated.txt",
|
|
}),
|
|
).resolves.toBe("data:text/plain;base64,aGVsbG8=");
|
|
});
|
|
});
|