Files

74 lines
2.3 KiB
Go
Raw Permalink Normal View History

2026-05-25 19:23:49 +08:00
package objectstorage
import (
"testing"
"github.com/geo-platform/tenant-api/internal/shared/config"
)
func TestBuildPublicURLDoesNotDoubleEscapeEncodedObjectKey(t *testing.T) {
t.Parallel()
got, err := buildPublicURL(config.ObjectStorageConfig{
Endpoint: "https://oss-cn-shanghai.aliyuncs.com",
Bucket: "shengxintui",
UseSSL: true,
}, "desktop-client/releases/stable/darwin/arm64/0.1.1/20260525015204-%E7%9C%81%E5%BF%83%E6%8E%A8-mac-0.1.19.zip", true)
if err != nil {
t.Fatal(err)
}
want := "https://shengxintui.oss-cn-shanghai.aliyuncs.com/desktop-client/releases/stable/darwin/arm64/0.1.1/20260525015204-%E7%9C%81%E5%BF%83%E6%8E%A8-mac-0.1.19.zip"
if got != want {
t.Fatalf("url = %q, want %q", got, want)
}
}
func TestBuildPublicURLEscapesRawUnicodeObjectKeyOnce(t *testing.T) {
t.Parallel()
got, err := buildPublicURL(config.ObjectStorageConfig{
Endpoint: "https://oss-cn-shanghai.aliyuncs.com",
Bucket: "shengxintui",
UseSSL: true,
}, "desktop-client/releases/stable/darwin/arm64/0.1.1/20260525015204-省心推-mac-0.1.19.zip", true)
if err != nil {
t.Fatal(err)
}
want := "https://shengxintui.oss-cn-shanghai.aliyuncs.com/desktop-client/releases/stable/darwin/arm64/0.1.1/20260525015204-%E7%9C%81%E5%BF%83%E6%8E%A8-mac-0.1.19.zip"
if got != want {
t.Fatalf("url = %q, want %q", got, want)
}
}
func TestNormalizeObjectKeyPathDecodesEncodedSegments(t *testing.T) {
t.Parallel()
got := normalizeObjectKeyPath("/desktop-client/releases/%E7%9C%81%E5%BF%83%E6%8E%A8.zip")
want := "desktop-client/releases/省心推.zip"
if got != want {
t.Fatalf("object key = %q, want %q", got, want)
}
}
func TestDownloadContentDispositionUsesRFC5987FileName(t *testing.T) {
t.Parallel()
got := DownloadContentDisposition("reports/省心推 安装包.zip")
want := `attachment; filename="object.zip"; filename*=UTF-8''%E7%9C%81%E5%BF%83%E6%8E%A8%20%E5%AE%89%E8%A3%85%E5%8C%85.zip`
if got != want {
t.Fatalf("content disposition = %q, want %q", got, want)
}
}
func TestDownloadContentDispositionKeepsASCIIFileNameFallback(t *testing.T) {
t.Parallel()
got := DownloadContentDisposition(`reports/report "final".csv`)
want := `attachment; filename="report final.csv"; filename*=UTF-8''report%20final.csv`
if got != want {
t.Fatalf("content disposition = %q, want %q", got, want)
}
}