feat: add independent platform modules and multi-provider storage
This commit is contained in:
35
storage/signed_test.go
Normal file
35
storage/signed_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package storage_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.yuntuo.hk/k2safe/go-omni/storage"
|
||||
"git.yuntuo.hk/k2safe/go-omni/storage/local"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestLocalSignedDownload(t *testing.T) {
|
||||
s, _ := local.New(t.TempDir(), 64)
|
||||
s.Put(context.Background(), "file", strings.NewReader("hello"), 5, "text/plain")
|
||||
signer, _ := storage.NewSigner(s, "https://example.test/download", []byte(strings.Repeat("x", 32)))
|
||||
u, err := signer.PresignGet(context.Background(), "file", time.Minute)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request := httptest.NewRequest("GET", u.String(), nil)
|
||||
response := httptest.NewRecorder()
|
||||
signer.ServeHTTP(response, request)
|
||||
if response.Code != 200 || response.Body.String() != "hello" || response.Header().Get("Content-Disposition") != "attachment" {
|
||||
t.Fatal(response)
|
||||
}
|
||||
q := u.Query()
|
||||
q.Set("key", "another")
|
||||
u.RawQuery = q.Encode()
|
||||
response = httptest.NewRecorder()
|
||||
signer.ServeHTTP(response, httptest.NewRequest("GET", u.String(), nil))
|
||||
if response.Code != 403 {
|
||||
t.Fatal(response.Code)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user