Browse Source

Merge "tempurl: Fix PUT upload to temp url on py3" into stable/ussuri

stable/ussuri
Zuul 3 weeks ago
committed by Gerrit Code Review
parent
commit
91e5a9525c
2 changed files with 37 additions and 1 deletions
  1. +1
    -1
      swift/common/middleware/tempurl.py
  2. +36
    -0
      test/unit/common/middleware/test_tempurl.py

+ 1
- 1
swift/common/middleware/tempurl.py View File

@ -839,7 +839,7 @@ class TempURL(object):
if h.startswith(p):
del headers[h]
break
return headers.items()
return list(headers.items())
def filter_factory(global_conf, **local_conf):


+ 36
- 0
test/unit/common/middleware/test_tempurl.py View File

@ -476,6 +476,42 @@ class TestTempURL(unittest.TestCase):
self.assertEqual(req.environ['swift.authorize_override'], True)
self.assertEqual(req.environ['REMOTE_USER'], '.wsgi.tempurl')
def test_put_response_headers_in_list(self):
class Validator(object):
def __init__(self, app):
self.app = app
self.status = None
self.headers = None
self.exc_info = None
def start_response(self, status, headers, exc_info=None):
self.status = status
self.headers = headers
self.exc_info = exc_info
def __call__(self, env, start_response):
resp_iter = self.app(env, self.start_response)
start_response(self.status, self.headers, self.exc_info)
return resp_iter
method = 'PUT'
expires = int(time() + 86400)
path = '/v1/a/c/o'
key = b'abc'
hmac_body = ('%s\n%i\n%s' % (method, expires, path)).encode('utf-8')
sig = hmac.new(key, hmac_body, hashlib.sha1).hexdigest()
req = self._make_request(
path, keys=[key],
environ={'REQUEST_METHOD': 'PUT',
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
sig, expires)})
validator = Validator(self.tempurl)
resp = req.get_response(validator)
self.assertIsInstance(validator.headers, list)
self.assertEqual(resp.status_int, 404)
self.assertEqual(req.environ['swift.authorize_override'], True)
self.assertEqual(req.environ['REMOTE_USER'], '.wsgi.tempurl')
def test_get_not_allowed_by_put(self):
method = 'PUT'
expires = int(time() + 86400)


Loading…
Cancel
Save