Files
hfb_sys/backend/internal/modules/file/storage_test.go
T
yml2213 69774458b0 fix(file): 修复商品详情截图与提现打款凭证等私有图片 403 权限问题
- 放宽公开商品截图 key 提取规则,支持任意合规 object key 转换为免鉴权公开端点
- 补充后台截图上传 listing_screenshot 与 operating-expense 场景识别
- dependencies 授权器支持已审核上架商品截图兜底放行、提现人打款凭证鉴权及变体后缀匹配
- /api/files 路由组支持用户与管理员双重鉴权 (AuthUserOrAdmin)
- 前端收款账号凭证与提现详情凭证统一升级为 AuthImage 组件并支持大图预览
2026-09-16 20:33:09 +08:00

95 lines
3.0 KiB
Go

package file
import (
"strings"
"testing"
"github.com/minio/minio-go/v7"
)
func TestSanitizeObjectMetadataEscapesNonASCII(t *testing.T) {
got := sanitizeObjectMetadata(map[string]string{
"original-filename": "游戏ID截图 1.png",
})
if got["original-filename"] != "%E6%B8%B8%E6%88%8FID%E6%88%AA%E5%9B%BE+1.png" {
t.Fatalf("metadata filename = %q", got["original-filename"])
}
}
func TestParseBucketLookup(t *testing.T) {
tests := []struct {
name string
raw string
want minio.BucketLookupType
}{
{name: "auto", raw: "auto", want: minio.BucketLookupAuto},
{name: "dns", raw: "dns", want: minio.BucketLookupDNS},
{name: "path", raw: "path", want: minio.BucketLookupPath},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseBucketLookup(tt.raw)
if err != nil || got != tt.want {
t.Fatalf("parseBucketLookup(%q) = %v, %v", tt.raw, got, err)
}
})
}
if _, err := parseBucketLookup("invalid"); err == nil {
t.Fatal("invalid bucket lookup should fail")
}
}
func TestAnnouncementSceneUsesPublicFileURL(t *testing.T) {
key := "announcement/2026/06/15/example.webp"
got := fileURLForScene("announcement", key)
if !strings.HasPrefix(got, "/api/public/files/object?") {
t.Fatalf("announcement file url = %q, want public file endpoint", got)
}
}
func TestNormalizeSceneAllowsAnnouncement(t *testing.T) {
if got := normalizeScene("announcement"); got != "announcement" {
t.Fatalf("normalize announcement scene = %q", got)
}
}
func TestAWRecycleSceneUsesPublicFileURL(t *testing.T) {
if got := normalizeScene("aw-recycle"); got != "aw-recycle" {
t.Fatalf("normalize aw-recycle scene = %q", got)
}
key := "aw-recycle/2026/07/19/example.webp"
got := fileURLForScene("aw-recycle", key)
if !strings.HasPrefix(got, "/api/public/files/object?") {
t.Fatalf("aw-recycle file url = %q, want public file endpoint", got)
}
}
func TestCooperationFeedbackSceneUsesPublicFileURL(t *testing.T) {
if got := normalizeScene("cooperation-feedback"); got != "cooperation-feedback" {
t.Fatalf("normalize cooperation-feedback scene = %q", got)
}
key := "cooperation-feedback/2026/07/19/example.webp"
got := fileURLForScene("cooperation-feedback", key)
if !strings.HasPrefix(got, "/api/public/files/object?") {
t.Fatalf("cooperation-feedback file url = %q, want public file endpoint", got)
}
}
func TestNormalizeSceneListingScreenshotAndOperatingExpense(t *testing.T) {
if got := normalizeScene("listing_screenshot"); got != "listing" {
t.Fatalf("normalize listing_screenshot scene = %q, want listing", got)
}
if got := normalizeScene("listing-screenshot"); got != "listing" {
t.Fatalf("normalize listing-screenshot scene = %q, want listing", got)
}
if got := normalizeScene("operating-expense"); got != "operating-expense" {
t.Fatalf("normalize operating-expense scene = %q, want operating-expense", got)
}
if got := normalizeScene("operating_expense"); got != "operating-expense" {
t.Fatalf("normalize operating_expense scene = %q, want operating-expense", got)
}
}