[#648] fix: Prevent InternalError response in PostObject handler
All checks were successful
/ DCO (pull_request) Successful in 39s
/ Vulncheck (pull_request) Successful in 51s
/ Builds (pull_request) Successful in 1m5s
/ Lint (pull_request) Successful in 2m6s
/ Tests (pull_request) Successful in 1m23s
/ OCI image (pull_request) Successful in 2m27s
All checks were successful
/ DCO (pull_request) Successful in 39s
/ Vulncheck (pull_request) Successful in 51s
/ Builds (pull_request) Successful in 1m5s
/ Lint (pull_request) Successful in 2m6s
/ Tests (pull_request) Successful in 1m23s
/ OCI image (pull_request) Successful in 2m27s
Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
This commit is contained in:
parent
955608c3ca
commit
cb0b4a2e28
2 changed files with 22 additions and 4 deletions
|
@ -498,7 +498,8 @@ func (h *handler) PostObject(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
policy, err := checkPostPolicy(r, reqInfo, metadata)
|
||||
if err != nil {
|
||||
h.logAndSendError(ctx, w, "failed check policy", reqInfo, err)
|
||||
h.logAndSendError(ctx, w, "failed check policy", reqInfo,
|
||||
fmt.Errorf("%w: %v", apierr.GetAPIError(apierr.ErrInvalidArgument), err))
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -548,7 +549,8 @@ func (h *handler) PostObject(w http.ResponseWriter, r *http.Request) {
|
|||
if reqInfo.ObjectName == "" || strings.Contains(reqInfo.ObjectName, "${filename}") {
|
||||
_, head, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
h.logAndSendError(ctx, w, "could not parse file field", reqInfo, err)
|
||||
h.logAndSendError(ctx, w, "could not parse file field", reqInfo,
|
||||
fmt.Errorf("%w: %v", apierr.GetAPIError(apierr.ErrInvalidArgument), err))
|
||||
return
|
||||
}
|
||||
filename = head.Filename
|
||||
|
@ -557,7 +559,8 @@ func (h *handler) PostObject(w http.ResponseWriter, r *http.Request) {
|
|||
var head *multipart.FileHeader
|
||||
contentReader, head, err = r.FormFile("file")
|
||||
if err != nil {
|
||||
h.logAndSendError(ctx, w, "could not parse file field", reqInfo, err)
|
||||
h.logAndSendError(ctx, w, "could not parse file field", reqInfo,
|
||||
fmt.Errorf("%w: %v", apierr.GetAPIError(apierr.ErrInvalidArgument), err))
|
||||
return
|
||||
}
|
||||
size = uint64(head.Size)
|
||||
|
|
|
@ -159,6 +159,21 @@ func TestPostObject(t *testing.T) {
|
|||
objName: "user/user1/object",
|
||||
tagging: "<Tagging xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><TagSet><Tag><Key>Environment</Key><Value>Production</Value></Tag></TagSet></Tagging>",
|
||||
},
|
||||
{
|
||||
key: "user/user1/${filename}",
|
||||
filename: "object",
|
||||
content: "content",
|
||||
objName: "user/user1/object",
|
||||
tagging: "wrong tagging",
|
||||
err: true,
|
||||
},
|
||||
{
|
||||
key: "user/user1/${filename}",
|
||||
filename: "object",
|
||||
content: "content",
|
||||
objName: "user/user1/object",
|
||||
tagging: "<Tagging xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><TagSet></TagSet></Tagging>",
|
||||
},
|
||||
{
|
||||
key: "user/user1/${filename}",
|
||||
filename: "object",
|
||||
|
@ -218,7 +233,7 @@ func TestPostObject(t *testing.T) {
|
|||
t.Run(tc.key+";"+tc.filename, func(t *testing.T) {
|
||||
w := postObjectBase(hc, ns, bktName, tc.key, tc.filename, tc.content, tc.tagging)
|
||||
if tc.err {
|
||||
assertS3Error(hc.t, w, apierr.GetAPIError(apierr.ErrInternalError))
|
||||
assertStatus(hc.t, w, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
assertStatus(hc.t, w, http.StatusNoContent)
|
||||
|
|
Loading…
Add table
Reference in a new issue