forked from TrueCloudLab/frostfs-s3-gw
[#667] Use separate copies numbers for system containers
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
42d6fc3fc6
commit
949fc0b484
15 changed files with 311 additions and 125 deletions
|
@ -1,6 +1,8 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
"encoding/xml"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
|
@ -364,6 +366,30 @@ func addCORSToTree(hc *handlerContext, cors string, bkt *data.BucketInfo, corsCn
|
|||
require.NoError(hc.t, err)
|
||||
}
|
||||
|
||||
func TestPutBucketCORSCopiesNumbers(t *testing.T) {
|
||||
hc := prepareHandlerContext(t)
|
||||
|
||||
bktName := "bucket-cors"
|
||||
createBucket(hc, bktName)
|
||||
|
||||
cfg := &data.CORSConfiguration{
|
||||
CORSRules: []data.CORSRule{{
|
||||
AllowedHeaders: []string{"*"},
|
||||
AllowedMethods: []string{"GET"},
|
||||
AllowedOrigins: []string{"*"},
|
||||
}},
|
||||
}
|
||||
|
||||
hc.config.corsCopiesNumbers = []uint32{1}
|
||||
hc.config.copiesNumbers = map[string][]uint32{"default": {2}}
|
||||
|
||||
putBucketCORSConfiguration(hc, bktName, cfg, map[string]string{"X-Amz-Meta-Frostfs-Copies-Number": "3"}, true)
|
||||
|
||||
objs := hc.tp.Objects()
|
||||
require.Len(t, objs, 1)
|
||||
require.EqualValues(t, hc.config.corsCopiesNumbers, hc.tp.CopiesNumbers(addrFromObject(objs[0]).EncodeToString()))
|
||||
}
|
||||
|
||||
func requireEqualCORS(t *testing.T, expected string, actual string) {
|
||||
expectedCORS := &data.CORSConfiguration{}
|
||||
err := xml.NewDecoder(strings.NewReader(expected)).Decode(expectedCORS)
|
||||
|
@ -398,3 +424,28 @@ func getBucketCORS(hc *handlerContext, bktName string) *httptest.ResponseRecorde
|
|||
assertStatus(hc.t, w, http.StatusOK)
|
||||
return w
|
||||
}
|
||||
|
||||
func putBucketCORSConfiguration(hc *handlerContext, bktName string, cfg *data.CORSConfiguration, headers map[string]string, addMD5 bool) {
|
||||
w := putBucketCORSConfigurationBase(hc, bktName, cfg, headers, addMD5)
|
||||
assertStatus(hc.t, w, http.StatusOK)
|
||||
}
|
||||
|
||||
func putBucketCORSConfigurationBase(hc *handlerContext, bktName string, cfg *data.CORSConfiguration, headers map[string]string, addMD5 bool) *httptest.ResponseRecorder {
|
||||
w, r := prepareTestRequest(hc, bktName, "", cfg)
|
||||
|
||||
for k, v := range headers {
|
||||
r.Header.Set(k, v)
|
||||
}
|
||||
|
||||
if addMD5 {
|
||||
rawBody, err := xml.Marshal(cfg)
|
||||
require.NoError(hc.t, err)
|
||||
|
||||
hash := md5.New()
|
||||
hash.Write(rawBody)
|
||||
r.Header.Set(api.ContentMD5, base64.StdEncoding.EncodeToString(hash.Sum(nil)))
|
||||
}
|
||||
|
||||
hc.Handler().PutBucketCorsHandler(w, r)
|
||||
return w
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue