7d8e82c69f
Ship the Ops backstage 对象存储 page (browse / upload / move / delete / folder ops) backed by a new object-storage service + handler, with the shared storage client extended with List/Stat/Copy/Usage/DownloadURL so both MinIO and Aliyun providers cover the new surface. Add ForcePathStyle to the object-storage config and treat r2/s3/custom_s3 as external providers so Cloudflare R2 and other S3-compatibles can share the MinIO client path without spinning up the bundled MinIO. Also add CSV import/export + template download to the site-domain mappings page, raise gin MaxMultipartMemory to 8 MiB for the new multipart endpoints, register Ops swagger routes, and extend the descriptions-parity test to cover the ops router. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
74 lines
2.3 KiB
Go
74 lines
2.3 KiB
Go
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)
|
|
}
|
|
}
|