From b6273adcbffc4f792d2715c91ade0cfe05c2f8ff Mon Sep 17 00:00:00 2001 From: Karl Czajkowski Date: Mon, 18 Apr 2016 15:26:26 -0700 Subject: [PATCH] fix bug for invalid Content-MD5 header and add test cases for chunked upload All of these should be BadRequest response for upload job and chunk requests: - mismatched MD5 - valid base64 but invalid MD5 - invalid base64 --- hatrac/rest/transfer.py | 5 ++++- test/rest-smoketest.sh | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hatrac/rest/transfer.py b/hatrac/rest/transfer.py index cfef869..1ada0ba 100644 --- a/hatrac/rest/transfer.py +++ b/hatrac/rest/transfer.py @@ -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) diff --git a/test/rest-smoketest.sh b/test/rest-smoketest.sh index ae23aa7..b93c742 100644 --- a/test/rest-smoketest.sh +++ b/test/rest-smoketest.sh @@ -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 \