Merge pull request #1721 from versity/sis/precondition-ifmatch-obj-not-exist

fix: return NoSuchKey if a precondition header is present and object doesn't exist in PutObject, CompleteMultipartUpload
This commit is contained in:
Ben McClelland
2025-12-31 00:32:02 -08:00
committed by GitHub
4 changed files with 23 additions and 20 deletions
+8 -7
View File
@@ -1377,6 +1377,7 @@ func CompleteMultipartUpload_conditional_writes(s *S3Conf) error {
var etagTrimmed string
incorrectEtag := getPtr("incorrect_etag")
errPrecond := s3err.GetAPIError(s3err.ErrPreconditionFailed)
errNoSuchKey := s3err.GetAPIError(s3err.ErrNoSuchKey)
for i, test := range []struct {
obj string
@@ -1393,13 +1394,13 @@ func CompleteMultipartUpload_conditional_writes(s *S3Conf) error {
{obj, nil, incorrectEtag, nil},
{obj, nil, etag, errPrecond},
{obj, nil, nil, nil},
// should ignore the precondition headers if
// an object with the given name doesn't exist
{"obj-1", incorrectEtag, etag, nil},
{"obj-2", etag, etag, nil},
{"obj-3", etag, incorrectEtag, nil},
{"obj-4", incorrectEtag, nil, nil},
{"obj-5", nil, etag, nil},
// should return NoSuchKey error, if any precondition
// header is present, but object doesn't exist
{"obj-1", incorrectEtag, etag, errNoSuchKey},
{"obj-2", etag, etag, errNoSuchKey},
{"obj-3", etag, incorrectEtag, errNoSuchKey},
{"obj-4", incorrectEtag, nil, errNoSuchKey},
{"obj-5", nil, etag, errNoSuchKey},
// precondtion headers without quotes
{obj, &etagTrimmed, nil, nil},
+8 -7
View File
@@ -316,6 +316,7 @@ func PutObject_conditional_writes(s *S3Conf) error {
etagTrimmed := strings.Trim(*etag, `"`)
incorrectEtag := getPtr("incorrect_etag")
errPrecond := s3err.GetAPIError(s3err.ErrPreconditionFailed)
errNoSuchKey := s3err.GetAPIError(s3err.ErrNoSuchKey)
for i, test := range []struct {
obj string
@@ -340,13 +341,13 @@ func PutObject_conditional_writes(s *S3Conf) error {
{obj, incorrectEtag, &etagTrimmed, errPrecond},
{obj, nil, &etagTrimmed, errPrecond},
// should ignore the precondition headers if
// an object with the given name doesn't exist
{"obj-1", incorrectEtag, etag, nil},
{"obj-2", etag, etag, nil},
{"obj-3", etag, incorrectEtag, nil},
{"obj-4", incorrectEtag, nil, nil},
{"obj-5", nil, etag, nil},
// should return NoSuchKey error, if any precondition
// header is present, but object doesn't exist
{"obj-1", incorrectEtag, etag, errNoSuchKey},
{"obj-2", etag, etag, errNoSuchKey},
{"obj-3", etag, incorrectEtag, errNoSuchKey},
{"obj-4", incorrectEtag, nil, errNoSuchKey},
{"obj-5", nil, etag, errNoSuchKey},
} {
res, err := putObjectWithData(0, &s3.PutObjectInput{
Bucket: &bucket,