fix: Added VersioningNotConfigured error in Put/GetBucketVersioning acitons

This commit is contained in:
jonaustin09
2024-10-04 20:52:31 -04:00
parent d4fdbdd113
commit 768983be34
6 changed files with 102 additions and 12 deletions

View File

@@ -448,8 +448,7 @@ func (p *Posix) DeleteBucketOwnershipControls(_ context.Context, bucket string)
func (p *Posix) PutBucketVersioning(ctx context.Context, bucket string, status types.BucketVersioningStatus) error {
if !p.versioningEnabled() {
//TODO: Maybe we need to return our custom error here?
return nil
return s3err.GetAPIError(s3err.ErrVersioningNotConfigured)
}
_, err := os.Stat(bucket)
if errors.Is(err, fs.ErrNotExist) {
@@ -491,9 +490,7 @@ func (p *Posix) PutBucketVersioning(ctx context.Context, bucket string, status t
func (p *Posix) GetBucketVersioning(_ context.Context, bucket string) (s3response.GetBucketVersioningOutput, error) {
if !p.versioningEnabled() {
// AWS returns empty response, if versioning is not set
//TODO: Maybe we need to return our custom error here?
return s3response.GetBucketVersioningOutput{}, nil
return s3response.GetBucketVersioningOutput{}, s3err.GetAPIError(s3err.ErrVersioningNotConfigured)
}
_, err := os.Stat(bucket)
@@ -529,7 +526,10 @@ func (p *Posix) GetBucketVersioning(_ context.Context, bucket string) (s3respons
// Returns the specified bucket versioning status
func (p *Posix) isBucketVersioningEnabled(ctx context.Context, bucket string) (bool, error) {
res, err := p.GetBucketVersioning(ctx, bucket)
if err != nil {
if errors.Is(err, s3err.GetAPIError(s3err.ErrVersioningNotConfigured)) {
return false, nil
}
if err != nil && !errors.Is(err, s3err.GetAPIError(s3err.ErrVersioningNotConfigured)) {
return false, err
}

View File

@@ -108,6 +108,14 @@ func initTestCommands() []*cli.Command {
Name: "posix",
Usage: "Tests posix specific features",
Action: getAction(integration.TestPosix),
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "versioning-enabled",
Usage: "Test posix when versioning is enabled",
Destination: &versioningEnabled,
Aliases: []string{"vs"},
},
},
},
{
Name: "iam",

View File

@@ -5,17 +5,19 @@ rm -rf /tmp/gw
mkdir /tmp/gw
rm -rf /tmp/covdata
mkdir /tmp/covdata
rm -rf /tmp/versioing.covdata
mkdir /tmp/versioning.covdata
rm -rf /tmp/versioningdir
mkdir /tmp/versioningdir
# run server in background
GOCOVERDIR=/tmp/covdata ./versitygw -a user -s pass --iam-dir /tmp/gw posix --versioning-dir /tmp/versioningdir /tmp/gw &
# run server in background not versioning-enabled
# port: 7070(default)
GOCOVERDIR=/tmp/covdata ./versitygw -a user -s pass --iam-dir /tmp/gw posix /tmp/gw &
GW_PID=$!
# wait a second for server to start up
sleep 1
# check if server is still running
# check if versioning-enabled gateway process is still running
if ! kill -0 $GW_PID; then
echo "server no longer running"
exit 1
@@ -23,7 +25,7 @@ fi
# run tests
# full flow tests
if ! ./versitygw test -a user -s pass -e http://127.0.0.1:7070 full-flow -vs; then
if ! ./versitygw test -a user -s pass -e http://127.0.0.1:7070 full-flow; then
echo "full flow tests failed"
kill $GW_PID
exit 1
@@ -41,8 +43,39 @@ if ! ./versitygw test -a user -s pass -e http://127.0.0.1:7070 iam; then
exit 1
fi
# kill off server
kill $GW_PID
# run server in background versioning-enabled
# port: 7071
GOCOVERDIR=/tmp/versioning.covdata ./versitygw -p :7071 -a user -s pass --iam-dir /tmp/gw posix --versioning-dir /tmp/versioningdir /tmp/gw &
GW_VS_PID=$!
# wait a second for server to start up
sleep 1
# check if versioning-enabled gateway process is still running
if ! kill -0 $GW_VS_PID; then
echo "versioning-enabled server no longer running"
exit 1
fi
# run tests
# full flow tests
if ! ./versitygw test -a user -s pass -e http://127.0.0.1:7071 full-flow -vs; then
echo "versioning-enabled full-flow tests failed"
kill $GW_VS_PID
exit 1
fi
# posix tests
if ! ./versitygw test -a user -s pass -e http://127.0.0.1:7071 posix -vs; then
echo "versiongin-enabled posix tests failed"
kill $GW_VS_PID
exit 1
fi
# kill off server
kill $GW_VS_PID
exit 0
# if the above binary was built with -cover enabled (make testbin),

View File

@@ -141,6 +141,7 @@ const (
ErrObjectParentIsFile
ErrDirectoryObjectContainsData
ErrQuotaExceeded
ErrVersioningNotConfigured
)
var errorCodeResponse = map[ErrorCode]APIError{
@@ -565,6 +566,11 @@ var errorCodeResponse = map[ErrorCode]APIError{
Description: "Your request was denied due to quota exceeded.",
HTTPStatusCode: http.StatusForbidden,
},
ErrVersioningNotConfigured: {
Code: "VersioningNotConfigured",
Description: "Versioning has not been configured for the gateway.",
HTTPStatusCode: http.StatusNotImplemented,
},
}
// GetAPIError provides API Error for input API error code.

View File

@@ -490,6 +490,10 @@ func TestPosix(s *S3Conf) {
PutObject_name_too_long(s)
HeadObject_name_too_long(s)
DeleteObject_name_too_long(s)
// posix specific versioning tests
if !s.versioningEnabled {
TestVersioningDisabled(s)
}
}
func TestIAM(s *S3Conf) {
@@ -571,6 +575,11 @@ func TestVersioning(s *S3Conf) {
Versioning_WORM_obj_version_locked_with_compliance_retention(s)
}
func TestVersioningDisabled(s *S3Conf) {
VersioningDisabled_GetBucketVersioning_not_configured(s)
VersioningDisabled_PutBucketVersioning_not_configured(s)
}
type IntTests map[string]func(s *S3Conf) error
func GetIntTests() IntTests {

View File

@@ -12170,3 +12170,37 @@ func Versioning_WORM_obj_version_locked_with_compliance_retention(s *S3Conf) err
return nil
}, withLock(), withVersioning())
}
func VersioningDisabled_GetBucketVersioning_not_configured(s *S3Conf) error {
testName := "VersioningDisabled_GetBucketVersioning_not_configured"
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
_, err := s3client.PutBucketVersioning(ctx, &s3.PutBucketVersioningInput{
Bucket: &bucket,
VersioningConfiguration: &types.VersioningConfiguration{
Status: types.BucketVersioningStatusEnabled,
},
})
cancel()
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrVersioningNotConfigured)); err != nil {
return err
}
return nil
})
}
func VersioningDisabled_PutBucketVersioning_not_configured(s *S3Conf) error {
testName := "VersioningDisabled_PutBucketVersioning_not_configured"
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
_, err := s3client.GetBucketVersioning(ctx, &s3.GetBucketVersioningInput{
Bucket: &bucket,
})
cancel()
if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrVersioningNotConfigured)); err != nil {
return err
}
return nil
})
}