From 622953396b4eb08af0f0e63acfbd9356ddd76dc9 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Tue, 10 Sep 2024 18:13:11 +1200 Subject: [PATCH] miniogw: return 404 for GetObjectLockConfig if no lock found This endpoint should return a 404 for when lock config is not found, instead of a 400. Additionally, fix tests to use the object API layer for testing GetObjectLockConfig. Gateway tests should not be testing the metaclient endpoints, since that's uplink domain. Updates storj/edge#498 Change-Id: Ic7cbb3f217acf086884c8ebe935bd9fc976c1680 --- miniogw/gateway.go | 3 +++ testsuite/miniogw/gateway_test.go | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/miniogw/gateway.go b/miniogw/gateway.go index 34f8d90..281408b 100644 --- a/miniogw/gateway.go +++ b/miniogw/gateway.go @@ -295,6 +295,9 @@ func (layer *gatewayLayer) GetObjectLockConfig(ctx context.Context, bucketName s enabled, err := bucket.GetBucketObjectLockConfiguration(ctx, project, bucketName) if err != nil { + if errors.Is(err, bucket.ErrBucketNoLock) { + return &objectlock.Config{}, minio.BucketObjectLockConfigNotFound{Bucket: bucketName} + } return &objectlock.Config{}, ConvertError(err, bucketName, "") } diff --git a/testsuite/miniogw/gateway_test.go b/testsuite/miniogw/gateway_test.go index 630b886..fa632ce 100644 --- a/testsuite/miniogw/gateway_test.go +++ b/testsuite/miniogw/gateway_test.go @@ -39,7 +39,6 @@ import ( "storj.io/storj/private/testplanet" "storj.io/storj/satellite" "storj.io/uplink" - "storj.io/uplink/private/bucket" ) const ( @@ -85,8 +84,8 @@ func TestMakeBucketWithObjectLock(t *testing.T) { err := layer.MakeBucketWithLocation(ctx, testBucket, minio.BucketOptions{}) require.NoError(t, err) - _, err = bucket.GetBucketObjectLockConfiguration(ctx, project, testBucket) - require.ErrorIs(t, err, bucket.ErrBucketNoLock) + _, err = layer.GetObjectLockConfig(ctx, testBucket) + require.ErrorIs(t, err, minio.BucketObjectLockConfigNotFound{Bucket: testBucket}) // Create a bucket with object lock enabled err = layer.MakeBucketWithLocation(ctx, testBucket+"2", minio.BucketOptions{ @@ -94,9 +93,9 @@ func TestMakeBucketWithObjectLock(t *testing.T) { }) require.NoError(t, err) - enabled, err := bucket.GetBucketObjectLockConfiguration(ctx, project, testBucket+"2") + lockConfig, err := layer.GetObjectLockConfig(ctx, testBucket+"2") require.NoError(t, err) - require.True(t, enabled) + require.Equal(t, "Enabled", lockConfig.ObjectLockEnabled) }) }