From ff15f9f28a0e17eff2f424cd552c082d34785a5c Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 16 Feb 2024 11:09:54 +0300 Subject: [PATCH] [#306] Fix update settings for buckets without owner key in tree Signed-off-by: Denis Kirillov --- api/handler/put_test.go | 15 +++++++++++++++ pkg/service/tree/tree.go | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/api/handler/put_test.go b/api/handler/put_test.go index a96c28ea..889bdef6 100644 --- a/api/handler/put_test.go +++ b/api/handler/put_test.go @@ -379,6 +379,21 @@ func TestCreateBucket(t *testing.T) { createBucketAssertS3Error(hc, bktName, box2, s3errors.ErrBucketAlreadyExists) } +func TestCreateOldBucketPutVersioning(t *testing.T) { + hc := prepareHandlerContext(t) + hc.config.aclEnabled = true + bktName := "bkt-name" + + info := createBucket(hc, bktName) + settings, err := hc.tree.GetSettingsNode(hc.Context(), info.BktInfo) + require.NoError(t, err) + settings.OwnerKey = nil + err = hc.tree.PutSettingsNode(hc.Context(), info.BktInfo, settings) + require.NoError(t, err) + + putBucketVersioning(t, hc, bktName, true) +} + func TestCreateNamespacedBucket(t *testing.T) { hc := prepareHandlerContext(t) bktName := "bkt-name" diff --git a/pkg/service/tree/tree.go b/pkg/service/tree/tree.go index 50fc3114..ceacb1e6 100644 --- a/pkg/service/tree/tree.go +++ b/pkg/service/tree/tree.go @@ -1397,7 +1397,9 @@ func metaFromSettings(settings *data.BucketSettings) map[string]string { results[versioningKV] = settings.Versioning results[lockConfigurationKV] = encodeLockConfiguration(settings.LockConfiguration) results[cannedACLKV] = settings.CannedACL - results[ownerKeyKV] = hex.EncodeToString(settings.OwnerKey.Bytes()) + if settings.OwnerKey != nil { + results[ownerKeyKV] = hex.EncodeToString(settings.OwnerKey.Bytes()) + } return results }