[#641] Remove old CORS versions after putting new one

Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
This commit is contained in:
Marina Biryukova 2025-03-17 17:41:07 +03:00 committed by Alexey Vanin
parent c0c4bdb366
commit 01d95d8cf4
3 changed files with 39 additions and 30 deletions

View file

@ -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) {
bodyTree := `
<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())
}
func TestDeleteTreeCORSVersions(t *testing.T) {
func TestDeleteCORSVersions(t *testing.T) {
body := `
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
@ -305,6 +278,15 @@ func TestDeleteTreeCORSVersions(t *testing.T) {
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</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)
@ -317,10 +299,19 @@ func TestDeleteTreeCORSVersions(t *testing.T) {
putBucketCORS(hc, bktName, body)
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, 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)
require.Len(t, hc.tp.Objects(), 0)