Merge "TempURL: Fixed bug with \r or \n in disposition."
This commit is contained in:
@@ -1,4 +1,19 @@
|
|||||||
# Copyright (c) 2010-2012 OpenStack Foundation
|
# Copyright (c) 2011-2014 Greg Holt
|
||||||
|
# Copyright (c) 2012-2013 John Dickinson
|
||||||
|
# Copyright (c) 2012 Felipe Reyes
|
||||||
|
# Copyright (c) 2012 Peter Portante
|
||||||
|
# Copyright (c) 2012 Victor Rodionov
|
||||||
|
# Copyright (c) 2013-2014 Samuel Merritt
|
||||||
|
# Copyright (c) 2013 Chuck Thier
|
||||||
|
# Copyright (c) 2013 David Goetz
|
||||||
|
# Copyright (c) 2013 Dirk Mueller
|
||||||
|
# Copyright (c) 2013 Donagh McCabe
|
||||||
|
# Copyright (c) 2013 Fabien Boucher
|
||||||
|
# Copyright (c) 2013 Greg Lange
|
||||||
|
# Copyright (c) 2013 Kun Huang
|
||||||
|
# Copyright (c) 2013 Richard Hawkins
|
||||||
|
# Copyright (c) 2013 Tong Li
|
||||||
|
# Copyright (c) 2013 ZhiQiang Fan
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -106,7 +121,7 @@ from urlparse import parse_qs
|
|||||||
from swift.proxy.controllers.base import get_account_info
|
from swift.proxy.controllers.base import get_account_info
|
||||||
from swift.common.swob import HeaderKeyDict, HTTPUnauthorized
|
from swift.common.swob import HeaderKeyDict, HTTPUnauthorized
|
||||||
from swift.common.utils import split_path, get_valid_utf8_str, \
|
from swift.common.utils import split_path, get_valid_utf8_str, \
|
||||||
register_swift_info, get_hmac, streq_const_time
|
register_swift_info, get_hmac, streq_const_time, quote
|
||||||
|
|
||||||
|
|
||||||
#: Default headers to remove from incoming requests. Simply a whitespace
|
#: Default headers to remove from incoming requests. Simply a whitespace
|
||||||
@@ -147,6 +162,10 @@ def get_tempurl_keys_from_metadata(meta):
|
|||||||
if key.lower() in ('temp-url-key', 'temp-url-key-2')]
|
if key.lower() in ('temp-url-key', 'temp-url-key-2')]
|
||||||
|
|
||||||
|
|
||||||
|
def disposition_format(filename):
|
||||||
|
return 'attachment; filename="%s"' % quote(filename, safe='/ ')
|
||||||
|
|
||||||
|
|
||||||
class TempURL(object):
|
class TempURL(object):
|
||||||
"""
|
"""
|
||||||
WSGI Middleware to grant temporary URLs specific access to Swift
|
WSGI Middleware to grant temporary URLs specific access to Swift
|
||||||
@@ -319,14 +338,12 @@ class TempURL(object):
|
|||||||
if inline_disposition:
|
if inline_disposition:
|
||||||
disposition_value = 'inline'
|
disposition_value = 'inline'
|
||||||
elif filename:
|
elif filename:
|
||||||
disposition_value = 'attachment; filename="%s"' % (
|
disposition_value = disposition_format(filename)
|
||||||
filename.replace('"', '\\"'))
|
|
||||||
elif existing_disposition:
|
elif existing_disposition:
|
||||||
disposition_value = existing_disposition
|
disposition_value = existing_disposition
|
||||||
else:
|
else:
|
||||||
name = basename(env['PATH_INFO'].rstrip('/'))
|
name = basename(env['PATH_INFO'].rstrip('/'))
|
||||||
disposition_value = 'attachment; filename="%s"' % (
|
disposition_value = disposition_format(name)
|
||||||
name.replace('"', '\\"'))
|
|
||||||
out_headers.append(('Content-Disposition', disposition_value))
|
out_headers.append(('Content-Disposition', disposition_value))
|
||||||
headers = out_headers
|
headers = out_headers
|
||||||
return start_response(status, headers, exc_info)
|
return start_response(status, headers, exc_info)
|
||||||
|
@@ -1,4 +1,19 @@
|
|||||||
# Copyright (c) 2011 OpenStack Foundation
|
# Copyright (c) 2011-2014 Greg Holt
|
||||||
|
# Copyright (c) 2012-2013 Peter Portante
|
||||||
|
# Copyright (c) 2012 Iryoung Jeong
|
||||||
|
# Copyright (c) 2012 Michael Barton
|
||||||
|
# Copyright (c) 2013 Alex Gaynor
|
||||||
|
# Copyright (c) 2013 Chuck Thier
|
||||||
|
# Copyright (c) 2013 David Goetz
|
||||||
|
# Copyright (c) 2013 Donagh McCabe
|
||||||
|
# Copyright (c) 2013 Greg Lange
|
||||||
|
# Copyright (c) 2013 John Dickinson
|
||||||
|
# Copyright (c) 2013 Kun Huang
|
||||||
|
# Copyright (c) 2013 Richard Hawkins
|
||||||
|
# Copyright (c) 2013 Samuel Merritt
|
||||||
|
# Copyright (c) 2013 Shri Javadekar
|
||||||
|
# Copyright (c) 2013 Tong Li
|
||||||
|
# Copyright (c) 2013 ZhiQiang Fan
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -142,7 +157,7 @@ class TestTempURL(unittest.TestCase):
|
|||||||
resp = req.get_response(self.tempurl)
|
resp = req.get_response(self.tempurl)
|
||||||
self.assertEquals(resp.status_int, 200)
|
self.assertEquals(resp.status_int, 200)
|
||||||
self.assertEquals(resp.headers['content-disposition'],
|
self.assertEquals(resp.headers['content-disposition'],
|
||||||
'attachment; filename="bob \\\"killer\\\".txt"')
|
'attachment; filename="bob %22killer%22.txt"')
|
||||||
self.assertEquals(req.environ['swift.authorize_override'], True)
|
self.assertEquals(req.environ['swift.authorize_override'], True)
|
||||||
self.assertEquals(req.environ['REMOTE_USER'], '.wsgi.tempurl')
|
self.assertEquals(req.environ['REMOTE_USER'], '.wsgi.tempurl')
|
||||||
|
|
||||||
@@ -195,6 +210,24 @@ class TestTempURL(unittest.TestCase):
|
|||||||
self.assertEquals(req.environ['swift.authorize_override'], True)
|
self.assertEquals(req.environ['swift.authorize_override'], True)
|
||||||
self.assertEquals(req.environ['REMOTE_USER'], '.wsgi.tempurl')
|
self.assertEquals(req.environ['REMOTE_USER'], '.wsgi.tempurl')
|
||||||
|
|
||||||
|
def test_obj_odd_chars(self):
|
||||||
|
method = 'GET'
|
||||||
|
expires = int(time() + 86400)
|
||||||
|
path = '/v1/a/c/a\r\nb'
|
||||||
|
key = 'abc'
|
||||||
|
hmac_body = '%s\n%s\n%s' % (method, expires, path)
|
||||||
|
sig = hmac.new(key, hmac_body, sha1).hexdigest()
|
||||||
|
req = self._make_request(path, keys=[key], environ={
|
||||||
|
'QUERY_STRING': 'temp_url_sig=%s&temp_url_expires=%s' % (
|
||||||
|
sig, expires)})
|
||||||
|
self.tempurl.app = FakeApp(iter([('200 Ok', (), '123')]))
|
||||||
|
resp = req.get_response(self.tempurl)
|
||||||
|
self.assertEquals(resp.status_int, 200)
|
||||||
|
self.assertEquals(resp.headers['content-disposition'],
|
||||||
|
'attachment; filename="a%0D%0Ab"')
|
||||||
|
self.assertEquals(req.environ['swift.authorize_override'], True)
|
||||||
|
self.assertEquals(req.environ['REMOTE_USER'], '.wsgi.tempurl')
|
||||||
|
|
||||||
def test_obj_trailing_slash(self):
|
def test_obj_trailing_slash(self):
|
||||||
method = 'GET'
|
method = 'GET'
|
||||||
expires = int(time() + 86400)
|
expires = int(time() + 86400)
|
||||||
|
Reference in New Issue
Block a user