fix(est): reject oversized attachments early
This commit is contained in:
@@ -2,7 +2,7 @@ const fs = require("node:fs");
|
||||
const path = require("node:path");
|
||||
const vm = require("node:vm");
|
||||
const base = path.resolve(__dirname, "../../tools/est-test");
|
||||
const context = vm.createContext({ structuredClone, console });
|
||||
const context = vm.createContext({ structuredClone, console, Blob });
|
||||
for (const file of [
|
||||
"native-math.js",
|
||||
"native-formula.js",
|
||||
@@ -19,6 +19,7 @@ for (const file of [
|
||||
"native-resources.js",
|
||||
"native-schedule.js",
|
||||
"native-issues.js",
|
||||
"native-attachments.js",
|
||||
"native-model.js",
|
||||
"native-c3r.js",
|
||||
"native-exchange.js",
|
||||
|
||||
@@ -3,6 +3,21 @@ import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_attachment_size_prediction_includes_utf8_and_base64_overhead():
|
||||
result = run(
|
||||
"math",
|
||||
"""(()=>{
|
||||
const p=EstNative.empty();p.name='한글';const file={name:'파일.bin',type:'',size:4};
|
||||
const expected={...p,id:'0'.repeat(24),attachments:[{id:'0'.repeat(36),...file,data:'AAECAw=='}]};
|
||||
return {predicted:EstAttachments.requiredBytes(p,[file]),actual:new Blob([JSON.stringify(expected)]).size,
|
||||
large:EstAttachments.requiredBytes(p,[{name:'large',type:'',size:210000000}]),count:p.attachments.length};
|
||||
})()""",
|
||||
)
|
||||
assert result["predicted"] == result["actual"]
|
||||
assert result["large"] > 256 * 1024 * 1024
|
||||
assert result["count"] == 0
|
||||
|
||||
|
||||
def test_attachment_validation_keeps_valid_data_and_rejects_malformed_content():
|
||||
result = run(
|
||||
"math",
|
||||
|
||||
Reference in New Issue
Block a user