Feat: enable using LAN endpoint in serverside request of OSS policy (#399)

This commit is contained in:
HFO4
2020-11-29 19:15:35 +08:00
parent 0d210e87b3
commit a5805b022a
5 changed files with 47 additions and 13 deletions

View File

@@ -30,13 +30,19 @@ func TestDriver_InitOSSClient(t *testing.T) {
// 成功
{
asserts.NoError(handler.InitOSSClient())
asserts.NoError(handler.InitOSSClient(false))
}
// 使用内网Endpoint
{
handler.Policy.OptionsSerialized.ServerSideEndpoint = "endpoint2"
asserts.NoError(handler.InitOSSClient(false))
}
// 未指定存储策略
{
handler := Driver{}
asserts.Error(handler.InitOSSClient())
asserts.Error(handler.InitOSSClient(false))
}
}
@@ -182,6 +188,19 @@ func TestDriver_Source(t *testing.T) {
asserts.Empty(query.Get("Signature"))
asserts.Contains(resURL.String(), handler.Policy.BaseURL)
}
// 强制使用公网 Endpoint
{
handler.Policy.BaseURL = ""
handler.Policy.OptionsSerialized.ServerSideEndpoint = "endpoint.com"
res, err := handler.Source(context.WithValue(context.Background(), fsctx.ForceUsePublicEndpoint, false), "/123", url.URL{}, 10, false, 0)
asserts.NoError(err)
resURL, err := url.Parse(res)
asserts.NoError(err)
query := resURL.Query()
asserts.Empty(query.Get("Signature"))
asserts.Contains(resURL.String(), "endpoint.com")
}
}
func TestDriver_Thumb(t *testing.T) {