forked from TrueCloudLab/frostfs-s3-gw
[#598] Fix response code for invalid Content-Md5 header
Signed-off-by: Aleksey Kravchenko <al.kravchenko@yadro.com>
This commit is contained in:
parent
bc975989de
commit
d150f8ddcb
3 changed files with 19 additions and 4 deletions
|
@ -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) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"crypto/rand"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
|
@ -282,12 +283,20 @@ func TestPutObjectWithInvalidContentMD5(t *testing.T) {
|
|||
createTestBucket(tc, bktName)
|
||||
|
||||
content := []byte("content")
|
||||
md5HeaderContent := make([]byte, md5.Size)
|
||||
n, err := rand.Read(md5HeaderContent)
|
||||
require.Equal(t, md5.Size, n)
|
||||
require.NoError(t, err)
|
||||
w, r := prepareTestPayloadRequest(tc, bktName, objName, bytes.NewReader(content))
|
||||
r.Header.Set(api.ContentMD5, base64.StdEncoding.EncodeToString([]byte("invalid")))
|
||||
r.Header.Set(api.ContentMD5, base64.StdEncoding.EncodeToString(md5HeaderContent))
|
||||
tc.Handler().PutObjectHandler(w, r)
|
||||
assertS3Error(t, w, apierr.GetAPIError(apierr.ErrBadDigest))
|
||||
|
||||
content = []byte("content")
|
||||
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.ErrInvalidDigest))
|
||||
|
||||
w, r = prepareTestPayloadRequest(tc, bktName, objName, bytes.NewReader(content))
|
||||
r.Header.Set(api.ContentMD5, base64.StdEncoding.EncodeToString([]byte("")))
|
||||
tc.Handler().PutObjectHandler(w, r)
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue