Skip to content

Commit

Permalink
utf8 encode tempurl key
Browse files Browse the repository at this point in the history
In tempurl middleware, hmac uses the value of account metadata to
generate HMAC-SHA1 signature and hmac must accept a str-type string, not
a unicode string. The meta dict returned from get_info stroges special
chars as unicode however. So just encode it for tempurl using.

Closes-Bug: #1242644
Change-Id: I4be62eea014a573efc4748470de57dccf00e431d
  • Loading branch information
pyKun committed Oct 23, 2013
1 parent d7dcb48 commit abcecd2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 3 additions & 4 deletions swift/common/middleware/tempurl.py
Expand Up @@ -97,9 +97,8 @@
from urlparse import parse_qs

from swift.proxy.controllers.base import get_account_info
from swift.common.swob import HeaderKeyDict
from swift.common.utils import split_path
from swift.common.swob import HTTPUnauthorized
from swift.common.swob import HeaderKeyDict, HTTPUnauthorized
from swift.common.utils import split_path, get_valid_utf8_str


#: Default headers to remove from incoming requests. Simply a whitespace
Expand Down Expand Up @@ -136,7 +135,7 @@ def get_tempurl_keys_from_metadata(meta):
meta = get_account_info(...)['meta']
keys = get_tempurl_keys_from_metadata(meta)
"""
return [value for key, value in meta.iteritems()
return [get_valid_utf8_str(value) for key, value in meta.iteritems()
if key.lower() in ('temp-url-key', 'temp-url-key-2')]


Expand Down
6 changes: 6 additions & 0 deletions test/unit/common/middleware/test_tempurl.py
Expand Up @@ -803,6 +803,12 @@ def test_clean_outgoing_headers(self):
self.assertTrue('test-header-yes' not in hdrs)
self.assertTrue('test-header-yes-this' in hdrs)

def test_unicode_metadata_value(self):
meta = {"temp-url-key": "test", "temp-url-key-2": u"test2"}
results = tempurl.get_tempurl_keys_from_metadata(meta)
for str_value in results:
self.assertTrue(isinstance(str_value, str))


if __name__ == '__main__':
unittest.main()

0 comments on commit abcecd2

Please sign in to comment.