add restrictions on file handler

This commit is contained in:
KingKDot
2026-07-16 23:51:20 -05:00
parent 755626a315
commit 10ec62cf95
13 changed files with 919 additions and 45 deletions
@@ -0,0 +1,51 @@
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
import { getConfig, updateFileTransfersConfig, type Config } from "./config";
import { getFileTransferLimits } from "./server/file-transfer-state";
let original: Config["fileTransfers"];
beforeAll(() => {
original = { ...getConfig().fileTransfers };
});
afterAll(async () => {
await updateFileTransfersConfig(original);
});
describe("file transfer settings", () => {
test("saved limits are visible to transfer handlers immediately", async () => {
await updateFileTransfersConfig({
maxFileBytes: 25 * 1024 * 1024,
maxStagedBytes: 100 * 1024 * 1024,
maxActiveGlobal: 8,
maxActivePerUser: 2,
uploadIntentTtlMs: 5 * 60_000,
uploadPullTtlMs: 10 * 60_000,
});
expect(getFileTransferLimits()).toEqual({
maxFileBytes: 25 * 1024 * 1024,
maxStagedBytes: 100 * 1024 * 1024,
maxActiveGlobal: 8,
maxActivePerUser: 2,
uploadIntentTtlMs: 5 * 60_000,
uploadPullTtlMs: 10 * 60_000,
});
});
test("dependent limits are clamped to safe relationships", async () => {
const updated = await updateFileTransfersConfig({
maxFileBytes: 20 * 1024 * 1024,
maxStagedBytes: 10 * 1024 * 1024,
maxActiveGlobal: 3,
maxActivePerUser: 20,
uploadIntentTtlMs: 1,
uploadPullTtlMs: 1,
});
expect(updated.maxStagedBytes).toBe(updated.maxFileBytes);
expect(updated.maxActivePerUser).toBe(updated.maxActiveGlobal);
expect(updated.uploadIntentTtlMs).toBe(60_000);
expect(updated.uploadPullTtlMs).toBe(60_000);
});
});