From 52674ab0c5fd4412b75d6fc74c163ddd6fa47bb8 Mon Sep 17 00:00:00 2001 From: jonaustin09 Date: Tue, 10 Oct 2023 18:36:32 -0400 Subject: [PATCH] feat: Closes #282, created a new integration test group and test cases for posix specific behaviours testing --- cmd/versitygw/test.go | 5 ++ .../{action-tests.go => group-tests.go} | 9 ++- integration/tests.go | 70 +++++++++++++------ s3api/controllers/base.go | 5 ++ 4 files changed, 65 insertions(+), 24 deletions(-) rename integration/{action-tests.go => group-tests.go} (97%) diff --git a/cmd/versitygw/test.go b/cmd/versitygw/test.go index 1bcfcd9..5b97d60 100644 --- a/cmd/versitygw/test.go +++ b/cmd/versitygw/test.go @@ -73,6 +73,11 @@ func initTestCommands() []*cli.Command { Description: `Runs all the available tests to test the full flow of the gateway.`, Action: getAction(integration.TestFullFlow), }, + { + Name: "posix", + Usage: "Tests posix specific features", + Action: getAction(integration.TestPosix), + }, { Name: "bench", Usage: "Runs download/upload performance test on the gateway", diff --git a/integration/action-tests.go b/integration/group-tests.go similarity index 97% rename from integration/action-tests.go rename to integration/group-tests.go index 8a0694f..028acab 100644 --- a/integration/action-tests.go +++ b/integration/group-tests.go @@ -49,8 +49,6 @@ func TestDeleteBucket(s *S3Conf) { func TestPutObject(s *S3Conf) { PutObject_non_existing_bucket(s) PutObject_special_chars(s) - PutObject_existing_dir_obj(s) - PutObject_obj_parent_is_file(s) PutObject_invalid_long_tags(s) PutObject_success(s) } @@ -217,3 +215,10 @@ func TestFullFlow(s *S3Conf) { TestPutBucketAcl(s) TestGetBucketAcl(s) } + +func TestPosix(s *S3Conf) { + PutObject_overwrite_dir_obj(s) + PutObject_overwrite_file_obj(s) + PutObject_dir_obj_with_data(s) + CreateMultipartUpload_dir_obj(s) +} diff --git a/integration/tests.go b/integration/tests.go index 6918724..f4fa5ec 100644 --- a/integration/tests.go +++ b/integration/tests.go @@ -1035,28 +1035,6 @@ func PutObject_special_chars(s *S3Conf) { }) } -func PutObject_existing_dir_obj(s *S3Conf) { - testName := "PutObject_existing_dir_obj" - actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { - err := putObjects(s3client, []string{"foo/bar", "foo"}, bucket) - if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrExistingObjectIsDirectory)); err != nil { - return err - } - return nil - }) -} - -func PutObject_obj_parent_is_file(s *S3Conf) { - testName := "PutObject_obj_parent_is_file" - actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { - err := putObjects(s3client, []string{"foo", "foo/bar/"}, bucket) - if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrObjectParentIsFile)); err != nil { - return err - } - return nil - }) -} - func PutObject_invalid_long_tags(s *S3Conf) { testName := "PutObject_invalid_long_tags" actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { @@ -3869,3 +3847,51 @@ func TestPerformance(s *S3Conf, upload, download bool, files int, objectSize int return nil } + +// Posix related tests +func PutObject_overwrite_dir_obj(s *S3Conf) { + testName := "PutObject_overwrite_dir_obj" + actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { + err := putObjects(s3client, []string{"foo/", "foo"}, bucket) + if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrExistingObjectIsDirectory)); err != nil { + return err + } + return nil + }) +} + +func PutObject_overwrite_file_obj(s *S3Conf) { + testName := "PutObject_overwrite_file_obj" + actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { + err := putObjects(s3client, []string{"foo", "foo/"}, bucket) + if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrObjectParentIsFile)); err != nil { + return err + } + return nil + }) +} + +func PutObject_dir_obj_with_data(s *S3Conf) { + testName := "PutObject_dir_obj_with_data" + actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { + _, _, err := putObjectWithData(int64(20), &s3.PutObjectInput{ + Bucket: &bucket, + Key: getPtr("obj/"), + }, s3client) + if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrDirectoryObjectContainsData)); err != nil { + return err + } + return nil + }) +} + +func CreateMultipartUpload_dir_obj(s *S3Conf) { + testName := "CreateMultipartUpload_dir_obj" + actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { + _, err := createMp(s3client, bucket, "obj/") + if err := checkApiErr(err, s3err.GetAPIError(s3err.ErrDirectoryObjectContainsData)); err != nil { + return err + } + return nil + }) +} diff --git a/s3api/controllers/base.go b/s3api/controllers/base.go index 5b3a308..13d05dc 100644 --- a/s3api/controllers/base.go +++ b/s3api/controllers/base.go @@ -849,6 +849,11 @@ func (c S3ApiController) CreateActions(ctx *fiber.Ctx) error { key = strings.Join([]string{key, keyEnd}, "/") } + path := ctx.Path() + if path[len(path)-1:] == "/" && key[len(key)-1:] != "/" { + key = key + "/" + } + var restoreRequest s3.RestoreObjectInput if ctx.Request().URI().QueryArgs().Has("restore") { err := xml.Unmarshal(ctx.Body(), &restoreRequest)