release: WRNexusJS 0.8.0
This commit is contained in:
@@ -61,3 +61,30 @@ test("signed file tokens reject tampering and expired payloads", async () => {
|
||||
expect(await verifySignedFileToken(`${token}x`, secret, 1_000)).toBeNull();
|
||||
expect(await verifySignedFileToken(token, secret, 2_000)).toBeNull();
|
||||
});
|
||||
|
||||
test("upload scanning rejects unsafe bytes before storage", async () => {
|
||||
const form = new FormData();
|
||||
form.set("file", new File(["virus"], "bad.txt", { type: "text/plain" }));
|
||||
await expect(
|
||||
upload("public", new Request("http://test/upload", { method: "POST", body: form }), {
|
||||
scan: async () => ({ safe: false, scanner: "test-av", reason: "signature" }),
|
||||
}),
|
||||
).rejects.toMatchObject({ status: 422 });
|
||||
expect(await getStore("public").driver.get("bad.txt")).toBeNull();
|
||||
});
|
||||
|
||||
test("post-storage processor failure rolls back the object", async () => {
|
||||
const form = new FormData();
|
||||
form.set("file", new File(["image"], "photo.png", { type: "image/png" }));
|
||||
let key = "";
|
||||
await expect(
|
||||
upload("public", new Request("http://test/upload", { method: "POST", body: form }), {
|
||||
afterStore(file) {
|
||||
key = file.key;
|
||||
throw new Error("transform failed");
|
||||
},
|
||||
}),
|
||||
).rejects.toMatchObject({ status: 422 });
|
||||
expect(key).not.toBe("");
|
||||
expect(await getStore("public").driver.get(key)).toBeNull();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user