oss请求处理
This commit is contained in:
1 parent
18cb51670c
commit
a9a4cdf125
18 files changed
+450
-29
No files matched your search
@@ -48,6 +48,36 @@ func TestOSSHTTPClientSignsPutAndBuildsVirtualHostURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSSHTTPClientPresignsPrivateGetURL(t *testing.T) {
|
||||
client := newTestOSSHTTPClient(t, func(*http.Request) *http.Response {
|
||||
t.Fatal("presigning must not perform a network request")
|
||||
return nil
|
||||
})
|
||||
|
||||
signed, err := client.SignGetURL(OSSObjectRequest{
|
||||
Endpoint: "https://oss-cn-test.aliyuncs.com",
|
||||
Bucket: "bucket-a",
|
||||
Key: "photos/cat.png",
|
||||
}, time.Hour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parsed, err := url.Parse(signed)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if parsed.Scheme != "https" || parsed.Host != "bucket-a.oss-cn-test.aliyuncs.com" || parsed.EscapedPath() != "/photos/cat.png" {
|
||||
t.Fatalf("signed URL target = %s", parsed)
|
||||
}
|
||||
query := parsed.Query()
|
||||
if query.Get("OSSAccessKeyId") != "access-key" || query.Get("Expires") != "1786582800" || query.Get("Signature") != "uA2xP4TwgB6YB17MaALkharfEmM=" {
|
||||
t.Fatalf("signed URL query = %#v", query)
|
||||
}
|
||||
if _, err := client.SignGetURL(OSSObjectRequest{Endpoint: "https://oss-cn-test.aliyuncs.com", Bucket: "bucket-a", Key: "photos/cat.png"}, 10*time.Hour); err == nil {
|
||||
t.Fatal("expected excessive signed URL lifetime to fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOSSHTTPClientSignsACLGetDeleteAndStreamsGetMetadata(t *testing.T) {
|
||||
var calls int
|
||||
client := newTestOSSHTTPClient(t, func(r *http.Request) *http.Response {
|
||||
|
||||
Reference in new issue
Block a user