2023-02-20 09:18:29 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 14:38:08 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
2023-07-05 14:05:45 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/middleware"
|
2023-02-20 09:18:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCORSOriginWildcard(t *testing.T) {
|
|
|
|
body := `
|
|
|
|
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
|
|
|
<CORSRule>
|
|
|
|
<AllowedMethod>GET</AllowedMethod>
|
|
|
|
<AllowedOrigin>*</AllowedOrigin>
|
|
|
|
</CORSRule>
|
|
|
|
</CORSConfiguration>
|
|
|
|
`
|
|
|
|
hc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName := "bucket-for-cors"
|
|
|
|
box, _ := createAccessBox(t)
|
|
|
|
w, r := prepareTestRequest(hc, bktName, "", nil)
|
2024-04-16 08:20:35 +00:00
|
|
|
ctx := middleware.SetBox(r.Context(), &middleware.Box{AccessBox: box})
|
2023-02-20 09:18:29 +00:00
|
|
|
r = r.WithContext(ctx)
|
|
|
|
r.Header.Add(api.AmzACL, "public-read")
|
|
|
|
hc.Handler().CreateBucketHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusOK)
|
|
|
|
|
|
|
|
w, r = prepareTestPayloadRequest(hc, bktName, "", strings.NewReader(body))
|
2024-04-16 08:20:35 +00:00
|
|
|
ctx = middleware.SetBox(r.Context(), &middleware.Box{AccessBox: box})
|
2023-02-20 09:18:29 +00:00
|
|
|
r = r.WithContext(ctx)
|
|
|
|
hc.Handler().PutBucketCorsHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusOK)
|
|
|
|
|
|
|
|
w, r = prepareTestPayloadRequest(hc, bktName, "", nil)
|
|
|
|
hc.Handler().GetBucketCorsHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusOK)
|
|
|
|
}
|