- CHANGELOG.md:v2.8.0 条目(中英双语); - README.md:版本行 2.7.1→2.8.0 + 愿景第 6 条(知识可证明); - doc/releases/v2.8.0.md:双语发版说明(亮点/用法/已知限制); - skills/marqdo-dev/index.mq.md:新增 prove 任务(路径/目录模式/ require_lean/json;参数用 + 行声明升参,check 与 narrative-ratio 通过); - 设计文档 §12.5 标记已合入;发版链接统一指向 doc/releases/v2.8.0.md。
46 lines
1.1 KiB
Go
Executable File
46 lines
1.1 KiB
Go
Executable File
package httpx
|
|
|
|
import (
|
|
"bytes"
|
|
"mime/multipart"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestHandleUploadRejectsOversizedBeforeFullBuffer(t *testing.T) {
|
|
st := &state{
|
|
uploadRoutes: map[string]any{
|
|
"/upload": map[string]any{
|
|
"field": "file",
|
|
"storage_url": "memory://t",
|
|
"prefix": "u",
|
|
"max_bytes": float64(64),
|
|
},
|
|
},
|
|
}
|
|
cfg := parseUploadRoute(st.uploadRoutes["/upload"])
|
|
var body bytes.Buffer
|
|
w := multipart.NewWriter(&body)
|
|
part, err := w.CreateFormFile("file", "big.txt")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := part.Write([]byte(strings.Repeat("x", 200))); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_ = w.Close()
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/upload", &body)
|
|
req.Header.Set("Content-Type", w.FormDataContentType())
|
|
rr := httptest.NewRecorder()
|
|
st.handleUpload(rr, req, "/upload", cfg)
|
|
if rr.Code == http.StatusOK {
|
|
t.Fatalf("expected reject for oversized upload, got %d body=%s", rr.Code, rr.Body.String())
|
|
}
|
|
if rr.Code != http.StatusRequestEntityTooLarge && rr.Code != http.StatusBadRequest {
|
|
t.Fatalf("expected 413 or 400, got %d body=%s", rr.Code, rr.Body.String())
|
|
}
|
|
}
|