Skip to content

Commit

Permalink
fix bug for invalid Content-MD5 header and add test cases for chunked…
Browse files Browse the repository at this point in the history
… upload

All of these should be BadRequest response for upload job and chunk requests:
- mismatched MD5
- valid base64 but invalid MD5
- invalid base64
  • Loading branch information
karlcz committed Apr 18, 2016
1 parent a662553 commit b6273ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion hatrac/rest/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def PUT(self, path, name, job, chunk):
except:
raise LengthRequired()
if 'HTTP_CONTENT_MD5' in web.ctx.env:
content_md5 = base64.b64decode(web.ctx.env.get('HTTP_CONTENT_MD5').strip())
try:
content_md5 = base64.b64decode(web.ctx.env.get('HTTP_CONTENT_MD5').strip())
except TypeError, e:
raise BadRequest('Content-MD5 invalid header "%s": %s' % (web.ctx.env.get('HTTP_CONTENT_MD5').strip(), e))
else:
content_md5 = None
upload = self.resolve_upload(path, name, job)
Expand Down
11 changes: 10 additions & 1 deletion test/rest-smoketest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,17 @@ dotest "200::application/json::*" "${upload}"
dotest "204::*::*" /ns-${RUNKEY}/foo/obj4 -X DELETE
dotest "404::*::*" "${upload}"

# check upload job with mismatched MD5
# check upload job with mismatched, invalid MD5, invalid base64
douploadtest "/ns-${RUNKEY}/foo2/obj2bad" "$(echo "" | mymd5sum)" "201::text/uri-list::*" "204::*::*" "204::*::*" "409::*::*"
douploadtest "/ns-${RUNKEY}/foo2/obj2bad" "YmFkX21kNQo=" "400::*::*"
douploadtest "/ns-${RUNKEY}/foo2/obj2bad" "bad_md5" "400::*::*"

# check upload job with mismatched, invalid MD5, invalid base64 in final chunk
douploadtest "/ns-${RUNKEY}/foo2/obj2bad" "${upload_md5}" "201::text/uri-list::*" "204::*::*" "204::*::*"
parts=( /tmp/parts-${RUNKEY}-* )
dotest "400::*::*" "${upload}/0" -T "${parts[0]}" -H "Content-MD5: $(echo "" | mymd5sum)"
dotest "400::*::*" "${upload}/0" -T "${parts[0]}" -H "Content-MD5: YmFkX21kNQo="
dotest "400::*::*" "${upload}/0" -T "${parts[0]}" -H "Content-MD5: bad_md5"

# check object conditional updates
dotest "412::*::*" /ns-${RUNKEY}/foo2/obj1 \
Expand Down

0 comments on commit b6273ad

Please sign in to comment.