2023-02-20 09:18:29 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"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)
|
2023-07-05 14:05:45 +00:00
|
|
|
ctx := context.WithValue(r.Context(), middleware.BoxData, 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))
|
2023-07-05 14:05:45 +00:00
|
|
|
ctx = context.WithValue(r.Context(), middleware.BoxData, 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)
|
|
|
|
}
|