[#641] Remove old CORS versions after putting new one
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
This commit is contained in:
parent
c0c4bdb366
commit
01d95d8cf4
3 changed files with 39 additions and 30 deletions
|
@ -228,33 +228,6 @@ func TestPreflightWildcardOrigin(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteAllCORSVersions(t *testing.T) {
|
|
||||||
body := `
|
|
||||||
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
|
||||||
<CORSRule>
|
|
||||||
<AllowedMethod>GET</AllowedMethod>
|
|
||||||
<AllowedMethod>PUT</AllowedMethod>
|
|
||||||
<AllowedOrigin>*</AllowedOrigin>
|
|
||||||
<AllowedHeader>*</AllowedHeader>
|
|
||||||
</CORSRule>
|
|
||||||
</CORSConfiguration>
|
|
||||||
`
|
|
||||||
hc := prepareHandlerContext(t)
|
|
||||||
|
|
||||||
bktName := "bucket-delete-all-cors-version"
|
|
||||||
createBucket(hc, bktName)
|
|
||||||
require.Len(t, hc.tp.Objects(), 0)
|
|
||||||
|
|
||||||
for range 5 {
|
|
||||||
putBucketCORS(hc, bktName, body)
|
|
||||||
}
|
|
||||||
|
|
||||||
require.Len(t, hc.tp.Objects(), 5)
|
|
||||||
|
|
||||||
deleteBucketCORS(hc, bktName)
|
|
||||||
require.Len(t, hc.tp.Objects(), 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetLatestCORSVersion(t *testing.T) {
|
func TestGetLatestCORSVersion(t *testing.T) {
|
||||||
bodyTree := `
|
bodyTree := `
|
||||||
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
|
@ -295,7 +268,7 @@ func TestGetLatestCORSVersion(t *testing.T) {
|
||||||
requireEqualCORS(hc.t, bodyTree, w.Body.String())
|
requireEqualCORS(hc.t, bodyTree, w.Body.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteTreeCORSVersions(t *testing.T) {
|
func TestDeleteCORSVersions(t *testing.T) {
|
||||||
body := `
|
body := `
|
||||||
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
<CORSRule>
|
<CORSRule>
|
||||||
|
@ -305,6 +278,15 @@ func TestDeleteTreeCORSVersions(t *testing.T) {
|
||||||
<AllowedHeader>*</AllowedHeader>
|
<AllowedHeader>*</AllowedHeader>
|
||||||
</CORSRule>
|
</CORSRule>
|
||||||
</CORSConfiguration>
|
</CORSConfiguration>
|
||||||
|
`
|
||||||
|
newBody := `
|
||||||
|
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||||
|
<CORSRule>
|
||||||
|
<AllowedMethod>HEAD</AllowedMethod>
|
||||||
|
<AllowedOrigin>*</AllowedOrigin>
|
||||||
|
<AllowedHeader>*</AllowedHeader>
|
||||||
|
</CORSRule>
|
||||||
|
</CORSConfiguration>
|
||||||
`
|
`
|
||||||
hc := prepareHandlerContext(t)
|
hc := prepareHandlerContext(t)
|
||||||
|
|
||||||
|
@ -317,10 +299,19 @@ func TestDeleteTreeCORSVersions(t *testing.T) {
|
||||||
|
|
||||||
putBucketCORS(hc, bktName, body)
|
putBucketCORS(hc, bktName, body)
|
||||||
require.Len(t, hc.tp.Objects(), 1)
|
require.Len(t, hc.tp.Objects(), 1)
|
||||||
|
require.Equal(t, body, string(hc.tp.Objects()[0].Payload()))
|
||||||
|
|
||||||
|
hc.tp.AddCORSObject(info.BktInfo, hc.corsCnrID, body)
|
||||||
|
require.Len(t, hc.tp.Objects(), 2)
|
||||||
|
|
||||||
|
putBucketCORS(hc, bktName, newBody)
|
||||||
|
require.Len(t, hc.tp.Objects(), 1)
|
||||||
|
require.Equal(t, newBody, string(hc.tp.Objects()[0].Payload()))
|
||||||
|
|
||||||
addCORSToTree(hc, body, info.BktInfo, info.BktInfo.CID)
|
addCORSToTree(hc, body, info.BktInfo, info.BktInfo.CID)
|
||||||
addCORSToTree(hc, body, info.BktInfo, hc.corsCnrID)
|
addCORSToTree(hc, body, info.BktInfo, hc.corsCnrID)
|
||||||
require.Len(t, hc.tp.Objects(), 3)
|
hc.tp.AddCORSObject(info.BktInfo, hc.corsCnrID, body)
|
||||||
|
require.Len(t, hc.tp.Objects(), 4)
|
||||||
|
|
||||||
deleteBucketCORS(hc, bktName)
|
deleteBucketCORS(hc, bktName)
|
||||||
require.Len(t, hc.tp.Objects(), 0)
|
require.Len(t, hc.tp.Objects(), 0)
|
||||||
|
|
|
@ -45,6 +45,11 @@ func (n *Layer) PutBucketCORS(ctx context.Context, p *PutCORSParams) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
corsVersions, err := n.getCORSVersions(ctx, p.BktInfo)
|
||||||
|
if err != nil {
|
||||||
|
n.reqLogger(ctx).Error(logs.CouldntGetCORSObjectVersions, zap.Error(err), logs.TagField(logs.TagExternalStorage))
|
||||||
|
}
|
||||||
|
|
||||||
prm := frostfs.PrmObjectCreate{
|
prm := frostfs.PrmObjectCreate{
|
||||||
Container: n.corsCnrInfo.CID,
|
Container: n.corsCnrInfo.CID,
|
||||||
Payload: &buf,
|
Payload: &buf,
|
||||||
|
@ -56,7 +61,7 @@ func (n *Layer) PutBucketCORS(ctx context.Context, p *PutCORSParams) error {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := n.objectPutAndHash(ctx, prm, n.corsCnrInfo)
|
_, err = n.objectPutAndHash(ctx, prm, n.corsCnrInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("put cors object: %w", err)
|
return fmt.Errorf("put cors object: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -76,6 +81,15 @@ func (n *Layer) PutBucketCORS(ctx context.Context, p *PutCORSParams) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if corsVersions != nil {
|
||||||
|
var addr oid.Address
|
||||||
|
addr.SetContainer(n.corsCnrInfo.CID)
|
||||||
|
for _, obj := range corsVersions.GetObjects() {
|
||||||
|
addr.SetObject(obj.ObjID)
|
||||||
|
n.deleteCORSObject(ctx, p.BktInfo, addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,10 @@ func (v *ObjectVersions) GetSorted() []*ObjectVersion {
|
||||||
return v.objects
|
return v.objects
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (v *ObjectVersions) GetObjects() []*ObjectVersion {
|
||||||
|
return v.objects
|
||||||
|
}
|
||||||
|
|
||||||
func (v *ObjectVersions) SetLessFunc(less func(*ObjectVersion, *ObjectVersion) bool) {
|
func (v *ObjectVersions) SetLessFunc(less func(*ObjectVersion, *ObjectVersion) bool) {
|
||||||
v.less = less
|
v.less = less
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue