fix(storage): COS 资源下载 - 公开 CDN 模式使用附件响应头 (#718)
This commit is contained in:
1 parent
c3dc8c8038
commit
37b44444f0
5 files changed
+88
-7
No files matched your search
@@ -140,15 +140,11 @@ func TestResolveAccessVariantAndExpiryContract(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveDownloadUsesObjectOriginAttachmentInsteadOfCDNOrProxy(t *testing.T) {
|
||||
func TestResolveDownloadUsesPublicCDNAttachment(t *testing.T) {
|
||||
now := time.Date(2026, time.January, 2, 3, 4, 5, 0, time.UTC)
|
||||
resource := testReadyResource("aliyun")
|
||||
setting := storage.Settings{
|
||||
// A public IP keeps the test deterministic: PublicOrigin intentionally
|
||||
// resolves hostnames to reject private DNS answers, so a made-up OSS host
|
||||
// would depend on the machine's DNS configuration.
|
||||
Provider: "aliyun", Endpoint: "https://1.1.1.1", Bucket: "private-bucket",
|
||||
AccessKeyID: "access-id", AccessKeySecret: "secret-value", CDNBaseURL: "https://media.example.com",
|
||||
Provider: "aliyun", CDNBaseURL: "https://media.example.com",
|
||||
Delivery: storage.DeliverySettings{CDNAuthMode: "public"},
|
||||
}
|
||||
access, err := ResolveAccess(resource, setting, AccessOptions{Purpose: PurposeDownload, DownloadName: "画布_镜头01.mp4"}, now, testPlatformURL(&[]ResourceVariant{}))
|
||||
@@ -160,7 +156,7 @@ func TestResolveDownloadUsesObjectOriginAttachmentInsteadOfCDNOrProxy(t *testing
|
||||
t.Fatal(err)
|
||||
}
|
||||
disposition := parsed.Query().Get("response-content-disposition")
|
||||
if access.Delivery != DeliveryOrigin || parsed.Host != "1.1.1.1" || !strings.HasPrefix(disposition, "attachment") || !strings.Contains(strings.ToLower(disposition), "utf-8''") {
|
||||
if access.Delivery != DeliveryCDN || access.ExpiresAt != nil || parsed.Host != "media.example.com" || !strings.HasPrefix(disposition, "attachment") || !strings.Contains(strings.ToLower(disposition), "utf-8''") {
|
||||
t.Fatalf("download access = %#v, disposition=%q", access, disposition)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user