已完成用户APP首期功能开发
交付用户端首期页面、配套接口、后台资源及测试文档。用户APP构建、静态分析和三个管理后台构建通过;完整测试仍有2项失败,后端模型注释检查未通过,详见交付记录。
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -24,6 +25,33 @@ func pngBytes(t *testing.T, width, height int) []byte {
|
||||
return buffer.Bytes()
|
||||
}
|
||||
|
||||
// TestAvatarOwnership 拒绝跨用户、跨客户端及穿越伪造路径,兼容读取旧头像路径。
|
||||
func TestAvatarOwnership(t *testing.T) {
|
||||
t.Setenv("HEQI_UPLOAD_DIR", t.TempDir())
|
||||
uri := "/uploads/avatars/" + avatarOwnerDirectory("user_app", "alice") + "/2026/09/07/avatar.png"
|
||||
path, err := avatarPathFromURI(uri)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o750); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(path, pngBytes(t, 2, 2), 0o640); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !OwnsAvatar("user_app", "alice", uri) {
|
||||
t.Fatal("当前用户上传资源未识别")
|
||||
}
|
||||
if OwnsAvatar("user_app", "bob", uri) || OwnsAvatar("platform_admin", "alice", uri) {
|
||||
t.Fatal("允许跨账户引用")
|
||||
}
|
||||
for _, unsafe := range []string{uri + "/../avatar.png", strings.ReplaceAll(uri, "/", "\\"), "/uploads/avatars/2026/09/07/avatar.png"} {
|
||||
if OwnsAvatar("user_app", "alice", unsafe) {
|
||||
t.Fatalf("接受未绑定 URI:%s", unsafe)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestValidateAvatarAcceptsRealPNG 验证真实 PNG 可通过并规范化类型。
|
||||
func TestValidateAvatarAcceptsRealPNG(t *testing.T) {
|
||||
extension, contentType, err := validateAvatar("头像.PNG", pngBytes(t, 2, 2))
|
||||
|
||||
Reference in New Issue
Block a user