Commit af1e9331 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki

pithos: Fix failing upload with matching preconditions

Refs: #5186
parent babc7544
......@@ -658,6 +658,24 @@ class ObjectPut(PithosAPITest):
r = self.put(url, data=data, HTTP_ETAG='123')
self.assertEqual(r.status_code, 422)
def test_upload_if_none_match(self):
cname = self.container
oname = get_random_name()
data = get_random_data()
url = join_urls(self.pithos_path, self.user, cname, oname)
r = self.put(url, data=data, HTTP_IF_NONE_MATCH='*')
self.assertEqual(r.status_code, 201)
r = self.get(url)
self.assertEqual(r.status_code, 200)
self.assertEqual(r.content, data)
self.assertTrue('ETag' in r)
etag = r['ETag']
url = join_urls(self.pithos_path, self.user, cname, oname)
r = self.put(url, data=data, HTTP_IF_NONE_MATCH=etag)
self.assertEqual(r.status_code, 412)
# def test_chunked_transfer(self):
# cname = self.container
# oname = '/%s' % get_random_name()
......
......@@ -438,9 +438,7 @@ def validate_modification_preconditions(request, meta):
def validate_matching_preconditions(request, meta):
"""Check that the ETag conforms with the preconditions set."""
etag = meta['hash'] if not UPDATE_MD5 else meta['checksum']
if not etag:
etag = None
etag = meta.get('hash') if not UPDATE_MD5 else meta.get('checksum')
if_match = request.META.get('HTTP_IF_MATCH')
if if_match is not None:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment