mirror of
https://github.com/versity/versitygw.git
synced 2026-04-21 13:10:29 +00:00
fix: Makes the crc64nvme checksum as default for PutObject, even if no checksum is provided
Fixes #1182 S3 calculates the `CRC64NVME` checksum of an object on object upload(`PutObject`), when no checksum algorithm or precalculated checksum header is provided. Makes the `CRC64NVME` checksum as default for `PutObject`, when no checksum is provided.
This commit is contained in:
@@ -2668,6 +2668,10 @@ func (p *Posix) PutObject(ctx context.Context, po s3response.PutObjectInput) (s3
|
||||
if po.Key == nil {
|
||||
return s3response.PutObjectOutput{}, s3err.GetAPIError(s3err.ErrNoSuchKey)
|
||||
}
|
||||
// Override the checksum algorithm with default: CRC64NVME
|
||||
if po.ChecksumAlgorithm == "" {
|
||||
po.ChecksumAlgorithm = types.ChecksumAlgorithmCrc64nvme
|
||||
}
|
||||
_, err := os.Stat(*po.Bucket)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return s3response.PutObjectOutput{}, s3err.GetAPIError(s3err.ErrNoSuchBucket)
|
||||
|
||||
@@ -148,6 +148,7 @@ func TestPutObject(s *S3Conf) {
|
||||
PutObject_multiple_checksum_headers(s)
|
||||
PutObject_invalid_checksum_header(s)
|
||||
PutObject_incorrect_checksums(s)
|
||||
PutObject_default_checksum(s)
|
||||
PutObject_checksums_success(s)
|
||||
}
|
||||
PutObject_success(s)
|
||||
@@ -811,6 +812,7 @@ func GetIntTests() IntTests {
|
||||
"PutObject_multiple_checksum_headers": PutObject_multiple_checksum_headers,
|
||||
"PutObject_invalid_checksum_header": PutObject_invalid_checksum_header,
|
||||
"PutObject_incorrect_checksums": PutObject_incorrect_checksums,
|
||||
"PutObject_default_checksum": PutObject_default_checksum,
|
||||
"PutObject_checksums_success": PutObject_checksums_success,
|
||||
"PresignedAuth_Put_GetObject_with_data": PresignedAuth_Put_GetObject_with_data,
|
||||
"PresignedAuth_Put_GetObject_with_UTF8_chars": PresignedAuth_Put_GetObject_with_UTF8_chars,
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3/types"
|
||||
"github.com/versity/versitygw/s3err"
|
||||
@@ -3139,6 +3140,46 @@ func PutObject_incorrect_checksums(s *S3Conf) error {
|
||||
})
|
||||
}
|
||||
|
||||
func PutObject_default_checksum(s *S3Conf) error {
|
||||
testName := "PutObject_default_checksum"
|
||||
return actionHandler(s, testName, func(_ *s3.Client, bucket string) error {
|
||||
customClient := s3.NewFromConfig(s.Config(), func(o *s3.Options) {
|
||||
o.RequestChecksumCalculation = aws.RequestChecksumCalculationUnset
|
||||
})
|
||||
|
||||
obj := "my-obj"
|
||||
|
||||
out, err := putObjectWithData(100, &s3.PutObjectInput{
|
||||
Bucket: &bucket,
|
||||
Key: &obj,
|
||||
}, customClient)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if out.res.ChecksumCRC64NVME == nil {
|
||||
return fmt.Errorf("expected non nil default crc64nvme checksum")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), shortTimeout)
|
||||
res, err := customClient.HeadObject(ctx, &s3.HeadObjectInput{
|
||||
Bucket: &bucket,
|
||||
Key: &obj,
|
||||
ChecksumMode: types.ChecksumModeEnabled,
|
||||
})
|
||||
cancel()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if getString(res.ChecksumCRC64NVME) != getString(out.res.ChecksumCRC64NVME) {
|
||||
return fmt.Errorf("expected the object crc64nvme checksum to be %v, instead got %v", getString(res.ChecksumCRC64NVME), getString(out.res.ChecksumCRC64NVME))
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func PutObject_checksums_success(s *S3Conf) error {
|
||||
testName := "PutObject_checksums_success"
|
||||
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
|
||||
|
||||
Reference in New Issue
Block a user