From 8633b754e604830c4909a9434fc4fc57a8d7a41d Mon Sep 17 00:00:00 2001 From: Aleksey Kravchenko Date: Thu, 26 Dec 2024 13:15:50 +0300 Subject: [PATCH] [#598] Fix response code for invalid Content-Md5 header Signed-off-by: Aleksey Kravchenko --- api/handler/encryption_test.go | 8 +++++++- api/handler/put_test.go | 2 +- api/layer/object.go | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/handler/encryption_test.go b/api/handler/encryption_test.go index 94a06de..2c3a728 100644 --- a/api/handler/encryption_test.go +++ b/api/handler/encryption_test.go @@ -65,10 +65,16 @@ func TestMD5HeaderBadOrEmpty(t *testing.T) { putEncryptedObjectWithHeadersErr(t, tc, bktName, objName, content, headers, errors.ErrInvalidDigest) headers = map[string]string{ - api.ContentMD5: "YWJjMTIzIT8kKiYoKSctPUB+", + api.ContentMD5: "yZRvHQZYwL5V7+k2pcwHLg==", } putEncryptedObjectWithHeadersErr(t, tc, bktName, objName, content, headers, errors.ErrBadDigest) + + headers = map[string]string{ + api.ContentMD5: "dGhlIHF1aWNrIGJyb3dF", + } + + putEncryptedObjectWithHeadersErr(t, tc, bktName, objName, content, headers, errors.ErrInvalidDigest) } func TestGetEncryptedRange(t *testing.T) { diff --git a/api/handler/put_test.go b/api/handler/put_test.go index 53968a6..dd85b8d 100644 --- a/api/handler/put_test.go +++ b/api/handler/put_test.go @@ -285,7 +285,7 @@ func TestPutObjectWithInvalidContentMD5(t *testing.T) { w, r := prepareTestPayloadRequest(tc, bktName, objName, bytes.NewReader(content)) r.Header.Set(api.ContentMD5, base64.StdEncoding.EncodeToString([]byte("invalid"))) tc.Handler().PutObjectHandler(w, r) - assertS3Error(t, w, apierr.GetAPIError(apierr.ErrBadDigest)) + assertS3Error(t, w, apierr.GetAPIError(apierr.ErrInvalidDigest)) content = []byte("content") w, r = prepareTestPayloadRequest(tc, bktName, objName, bytes.NewReader(content)) diff --git a/api/layer/object.go b/api/layer/object.go index 555a0cb..571a120 100644 --- a/api/layer/object.go +++ b/api/layer/object.go @@ -289,7 +289,7 @@ func (n *Layer) PutObject(ctx context.Context, p *PutObjectParams) (*data.Extend return nil, apierr.GetAPIError(apierr.ErrInvalidDigest) } headerMd5Hash, err := base64.StdEncoding.DecodeString(*p.ContentMD5) - if err != nil { + if err != nil || len(headerMd5Hash) != md5.Size { return nil, apierr.GetAPIError(apierr.ErrInvalidDigest) } if !bytes.Equal(headerMd5Hash, createdObj.MD5Sum) {