oss请求处理
This commit is contained in:
1 parent
18cb51670c
commit
a9a4cdf125
18 files changed
+450
-29
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -132,6 +133,25 @@ func TestDownloadUsesBlobBeforeRemoteFetcher(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderAssetURLSignsStoredObjectWithoutPersistingSignature(t *testing.T) {
|
||||
cat := &memoryCatalog{assets: []Asset{{
|
||||
ID: "asset-private", OwnerID: "owner-a", URL: "https://private-bucket.test/uploads/a.png", StoragePath: "uploads/a.png",
|
||||
}}}
|
||||
blobs := &signedMemoryBlobs{memoryBlobs: &memoryBlobs{}, signedURL: "https://private-bucket.test/uploads/a.png?Signature=temporary"}
|
||||
svc := NewService(cat, blobs, nil, time.Now, nil)
|
||||
|
||||
sourceURL, accessURL, err := svc.ResolveProviderAssetURL(context.Background(), "owner-a", "asset-private", time.Hour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if sourceURL != cat.assets[0].URL || accessURL != blobs.signedURL || blobs.signedKey != "uploads/a.png" || blobs.signedTTL != time.Hour {
|
||||
t.Fatalf("resolved URLs = %q / %q, signer = %q / %s", sourceURL, accessURL, blobs.signedKey, blobs.signedTTL)
|
||||
}
|
||||
if strings.Contains(cat.assets[0].URL, "Signature=") {
|
||||
t.Fatalf("temporary signature was persisted: %q", cat.assets[0].URL)
|
||||
}
|
||||
}
|
||||
|
||||
type memoryCatalog struct {
|
||||
assets []Asset
|
||||
createErr error
|
||||
@@ -205,6 +225,18 @@ type memoryBlobs struct {
|
||||
deleteErr error
|
||||
}
|
||||
|
||||
type signedMemoryBlobs struct {
|
||||
*memoryBlobs
|
||||
signedURL string
|
||||
signedKey string
|
||||
signedTTL time.Duration
|
||||
}
|
||||
|
||||
func (m *signedMemoryBlobs) SignReadURL(key string, ttl time.Duration) (string, error) {
|
||||
m.signedKey, m.signedTTL = key, ttl
|
||||
return m.signedURL, nil
|
||||
}
|
||||
|
||||
func (m *memoryBlobs) Put(_ context.Context, key string, body io.Reader, _ int64, contentType string) (StoredObject, error) {
|
||||
m.putKey = key
|
||||
m.putBody, _ = io.ReadAll(body)
|
||||
|
||||
Reference in new issue
Block a user