Files
geo/server/internal/shared/objectstorage/url_test.go
T

54 lines
1.6 KiB
Go
Raw 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)
}
}