fix(canvas): 素材库 - 拒绝空字节数并提供历史数据修复工具
This commit is contained in:
32
backend/internal/canvas/user_asset_document_test.go
Normal file
32
backend/internal/canvas/user_asset_document_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package canvas
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUserAssetBytesRequiresNonNegativeNumber(t *testing.T) {
|
||||
for _, kind := range []string{"image", "video", "audio", "model"} {
|
||||
for _, raw := range []string{"null", " null ", `"12"`, "-1", "true", "{}", "[]", "1e400", "0", "12"} {
|
||||
t.Run(kind+"/"+raw, func(t *testing.T) {
|
||||
data := map[string]json.RawMessage{
|
||||
"dataUrl": json.RawMessage(`"https://example.com/file"`),
|
||||
"url": json.RawMessage(`"https://example.com/file"`),
|
||||
"width": json.RawMessage("1"), "height": json.RawMessage("1"),
|
||||
"mimeType": json.RawMessage(`"application/octet-stream"`),
|
||||
"fileName": json.RawMessage(`"file.glb"`),
|
||||
"bytes": json.RawMessage(raw),
|
||||
}
|
||||
err := validateUserAssetData(kind, data)
|
||||
valid := raw == "0" || raw == "12"
|
||||
if (err == nil) != valid {
|
||||
t.Fatalf("bytes=%s: error=%v, want valid=%v", raw, err, valid)
|
||||
}
|
||||
delete(data, "bytes")
|
||||
if err := validateUserAssetData(kind, data); err == nil {
|
||||
t.Fatal("missing bytes accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user