Merge "Allow tempurl to be used to sign /info requests"
This commit is contained in:
@@ -173,7 +173,11 @@ def generate_temp_url(path, seconds, key, method, absolute=False,
|
|||||||
raise ValueError('digest must be one of sha1, sha256, or sha512')
|
raise ValueError('digest must be one of sha1, sha256, or sha512')
|
||||||
|
|
||||||
parts = path_for_body.split('/', 4)
|
parts = path_for_body.split('/', 4)
|
||||||
if len(parts) != 5 or parts[0] or not all(parts[1:(4 if prefix else 5)]):
|
if path_for_body == '/info':
|
||||||
|
# /info signatures do not support prefixes or ip ranges
|
||||||
|
prefix = False
|
||||||
|
ip_range = None
|
||||||
|
elif len(parts) != 5 or parts[0] or not all(parts[1:(4 if prefix else 5)]):
|
||||||
if prefix:
|
if prefix:
|
||||||
raise ValueError('path must at least contain /v1/a/c/')
|
raise ValueError('path must at least contain /v1/a/c/')
|
||||||
else:
|
else:
|
||||||
@@ -220,6 +224,10 @@ def generate_temp_url(path, seconds, key, method, absolute=False,
|
|||||||
expiration = time.strftime(
|
expiration = time.strftime(
|
||||||
EXPIRES_ISO8601_FORMAT, time.gmtime(expiration))
|
EXPIRES_ISO8601_FORMAT, time.gmtime(expiration))
|
||||||
|
|
||||||
|
if path_for_body == '/info':
|
||||||
|
temp_url = '{path}?swiftinfo_sig={sig}&swiftinfo_expires={exp}'.format(
|
||||||
|
path=path_for_body, sig=sig, exp=expiration)
|
||||||
|
else:
|
||||||
temp_url = '{path}?temp_url_sig={sig}&temp_url_expires={exp}'.format(
|
temp_url = '{path}?temp_url_sig={sig}&temp_url_expires={exp}'.format(
|
||||||
path=path_for_body, sig=sig, exp=expiration)
|
path=path_for_body, sig=sig, exp=expiration)
|
||||||
|
|
||||||
|
@@ -508,6 +508,32 @@ class TestTempURLBytesPathAndNonUtf8Key(TestTempURL):
|
|||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
class TestTempURLInfoPath(TestTempURL):
|
||||||
|
url = '/info'.encode('utf-8')
|
||||||
|
expected_body = b'\n'.join([
|
||||||
|
b'GET',
|
||||||
|
b'1400003600',
|
||||||
|
url,
|
||||||
|
])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def expected_url(self):
|
||||||
|
if isinstance(self.url, bytes):
|
||||||
|
return self.url + (b'?swiftinfo_sig=temp_url_signature'
|
||||||
|
b'&swiftinfo_expires=1400003600')
|
||||||
|
return self.url + (u'?swiftinfo_sig=temp_url_signature'
|
||||||
|
u'&swiftinfo_expires=1400003600')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def expected_sha512_url(self):
|
||||||
|
if isinstance(self.url, bytes):
|
||||||
|
return self.url + (
|
||||||
|
b'?swiftinfo_sig=sha512:dGVtcF91cmxfc2lnbmF0dXJl'
|
||||||
|
b'&swiftinfo_expires=1400003600')
|
||||||
|
return self.url + (u'?swiftinfo_sig=sha512:dGVtcF91cmxfc2lnbmF0dXJl'
|
||||||
|
u'&swiftinfo_expires=1400003600')
|
||||||
|
|
||||||
|
|
||||||
class TestReadableToIterable(unittest.TestCase):
|
class TestReadableToIterable(unittest.TestCase):
|
||||||
|
|
||||||
def test_iter(self):
|
def test_iter(self):
|
||||||
|
Reference in New Issue
Block a user