Files
versitygw/backend/posix/versioning_test.go
T
HeonJe Lee b83f5d903b fix(posix): return empty config for GetBucketVersioning when unconfigured
Validate bucket existence before checking the versioning state so a
missing bucket still yields 404 NoSuchBucket. When no versioning
directory is configured, respond with 200 and an empty configuration
instead of VersioningNotConfigured, matching AWS semantics. GUI clients
(e.g. S3 Browser) poll this API while browsing buckets and were
failing on default deployments. PutBucketVersioning still rejects with
VersioningNotConfigured.

Fix a swapped test body between the Get/Put "not configured" cases,
add integration coverage for GetBucketVersioning on a non-existent
bucket, and add backend/posix unit tests guarding the validation order
and the empty 200 response.

Ref: exastor/versitygw!3
2026-08-25 11:42:03 +09:00

103 lines
3.3 KiB
Go

// Copyright 2026 Versity Software
// This file is licensed under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package posix
import (
"context"
"errors"
"os"
"testing"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/stretchr/testify/assert"
"github.com/versity/versitygw/backend/meta"
"github.com/versity/versitygw/s3err"
)
// newUnversionedGateway creates a Posix backend over a temporary root
// directory with no versioning directory configured, i.e. gateway-level
// versioning disabled, matching the default gateway configuration.
func newUnversionedGateway(t *testing.T) *Posix {
t.Helper()
p, err := New(t.TempDir(), meta.XattrMeta{}, PosixOpts{
ValidateBucketNames: true,
})
if err != nil {
t.Fatalf("init posix backend: %v", err)
}
return p
}
// TestVersioningUnconfigured covers the bucket versioning behavior when the
// gateway has no versioning directory configured: bucket validation still
// applies first, GetBucketVersioning returns an empty configuration, and
// PutBucketVersioning is rejected.
func TestVersioningUnconfigured(t *testing.T) {
// New() chdirs into the gateway root; restore the original working
// directory when the test completes.
t.Chdir(t.TempDir())
t.Run("get bucket versioning invalid bucket name", func(t *testing.T) {
p := newUnversionedGateway(t)
_, err := p.GetBucketVersioning(context.Background(), "bad/bucket")
if !errors.Is(err, s3err.GetAPIError(s3err.ErrInvalidBucketName)) {
t.Errorf("expected InvalidBucketName, got %v", err)
}
})
t.Run("get bucket versioning no such bucket", func(t *testing.T) {
p := newUnversionedGateway(t)
_, err := p.GetBucketVersioning(context.Background(), "does-not-exist")
if !errors.Is(err, s3err.GetAPIError(s3err.ErrNoSuchBucket)) {
t.Errorf("expected NoSuchBucket, got %v", err)
}
})
t.Run("get bucket versioning returns empty config", func(t *testing.T) {
p := newUnversionedGateway(t)
err := os.Mkdir("bucket", 0o755)
assert.NoError(t, err)
res, err := p.GetBucketVersioning(context.Background(), "bucket")
assert.NoError(t, err)
assert.Nil(t, res.Status)
})
t.Run("put bucket versioning invalid bucket name", func(t *testing.T) {
p := newUnversionedGateway(t)
err := p.PutBucketVersioning(context.Background(), "bad/bucket", types.BucketVersioningStatusEnabled)
if !errors.Is(err, s3err.GetAPIError(s3err.ErrInvalidBucketName)) {
t.Errorf("expected InvalidBucketName, got %v", err)
}
})
t.Run("put bucket versioning not configured", func(t *testing.T) {
p := newUnversionedGateway(t)
err := os.Mkdir("bucket", 0o755)
assert.NoError(t, err)
err = p.PutBucketVersioning(context.Background(), "bucket", types.BucketVersioningStatusEnabled)
if !errors.Is(err, s3err.GetAPIError(s3err.ErrVersioningNotConfigured)) {
t.Errorf("expected VersioningNotConfigured, got %v", err)
}
})
}