From 3e50e29306efd9e8c8f042edc5743ed0c69bc25c Mon Sep 17 00:00:00 2001 From: niksis02 Date: Wed, 14 May 2025 00:04:36 +0400 Subject: [PATCH] fix: overrides empty checksum type and algorithm with 'null' for ListParts Fixes #1288 If the checksum algorithm/type is not specified during multipart upload initialization, it is considered `null`, and the `ListParts` result should also set it to `null`. --- backend/posix/posix.go | 6 ++++++ tests/integration/group-tests.go | 2 ++ tests/integration/tests.go | 36 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/backend/posix/posix.go b/backend/posix/posix.go index d8bf78c8..7014c15c 100644 --- a/backend/posix/posix.go +++ b/backend/posix/posix.go @@ -2200,6 +2200,12 @@ func (p *Posix) ListParts(ctx context.Context, input *s3.ListPartsInput) (s3resp if err != nil && !errors.Is(err, meta.ErrNoSuchKey) { return lpr, fmt.Errorf("get mp checksum: %w", err) } + if checksum.Algorithm == "" { + checksum.Algorithm = types.ChecksumAlgorithm("null") + } + if checksum.Type == "" { + checksum.Type = types.ChecksumType("null") + } parts := make([]s3response.Part, 0, len(ents)) for i, e := range ents { diff --git a/tests/integration/group-tests.go b/tests/integration/group-tests.go index 74e37482..6c8195f3 100644 --- a/tests/integration/group-tests.go +++ b/tests/integration/group-tests.go @@ -386,6 +386,7 @@ func TestListParts(s *S3Conf) { //TODO: remove the condition after implementing checksums in azure if !s.azureTests { ListParts_with_checksums(s) + ListParts_null_checksums(s) } ListParts_success(s) } @@ -1111,6 +1112,7 @@ func GetIntTests() IntTests { "ListParts_default_max_parts": ListParts_default_max_parts, "ListParts_truncated": ListParts_truncated, "ListParts_with_checksums": ListParts_with_checksums, + "ListParts_null_checksums": ListParts_null_checksums, "ListParts_success": ListParts_success, "ListMultipartUploads_non_existing_bucket": ListMultipartUploads_non_existing_bucket, "ListMultipartUploads_empty_result": ListMultipartUploads_empty_result, diff --git a/tests/integration/tests.go b/tests/integration/tests.go index 7c99f3db..777a2db1 100644 --- a/tests/integration/tests.go +++ b/tests/integration/tests.go @@ -9650,6 +9650,42 @@ func ListParts_with_checksums(s *S3Conf) error { }) } +func ListParts_null_checksums(s *S3Conf) error { + testName := "ListParts_null_checksums" + return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { + obj := "my-obj" + mp, err := createMp(s3client, bucket, obj) + if err != nil { + return err + } + + _, _, err = uploadParts(s3client, 20*1024*1024, 3, bucket, obj, *mp.UploadId) + if err != nil { + return err + } + + ctx, cancel := context.WithTimeout(context.Background(), shortTimeout) + res, err := s3client.ListParts(ctx, &s3.ListPartsInput{ + Bucket: &bucket, + Key: &obj, + UploadId: mp.UploadId, + }) + cancel() + if err != nil { + return err + } + + if res.ChecksumType != types.ChecksumType("null") { + return fmt.Errorf("expected the checksum type to be null, instead got %v", res.ChecksumType) + } + if res.ChecksumAlgorithm != types.ChecksumAlgorithm("null") { + return fmt.Errorf("expected the checksum algorithm to be null, instead got %v", res.ChecksumAlgorithm) + } + + return nil + }) +} + func ListParts_success(s *S3Conf) error { testName := "ListParts_success" return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {