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`.
This commit is contained in:
niksis02
2025-05-14 00:04:36 +04:00
committed by Ben McClelland
parent 1e91d901e7
commit 3e50e29306
3 changed files with 44 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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 {