Merge "Always fetch temp URL key before generation" into stable/juno

This commit is contained in:
Jenkins 2015-11-13 20:48:44 +00:00 committed by Gerrit Code Review
commit 79147fc305
2 changed files with 17 additions and 10 deletions

View File

@ -88,11 +88,12 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
Return a Swift TempURL.
'''
key_header = 'x-account-meta-temp-url-key'
if key_header in self.client().head_account():
key = self.client().head_account()[key_header]
else:
key = hashlib.sha224(str(random.getrandbits(256))).hexdigest()[:32]
self.client().post_account({key_header: key})
if key_header not in self.client().head_account():
self.client().post_account({
key_header: hashlib.sha224(
str(random.getrandbits(256))).hexdigest()[:32]})
key = self.client().head_account()[key_header]
path = '/v1/AUTH_%s/%s/%s' % (self.context.tenant_id, container_name,
obj_name)

View File

@ -82,17 +82,23 @@ class SwiftUtilsTests(SwiftClientPluginTestCase):
def test_get_temp_url_no_account_key(self):
self.swift_client.url = ("http://fake-host.com:8080/v1/"
"AUTH_test_tenant_id")
self.swift_client.head_account = mock.Mock(return_value={})
self.swift_client.post_account = mock.Mock()
self.assertFalse(self.swift_client.post_account.called)
"AUTH_demo")
head_account = {}
def post_account(data):
head_account.update(data)
self.swift_client.head_account = mock.Mock(return_value=head_account)
self.swift_client.post_account = post_account
container_name = '1234' # from stack.id
stack_name = 'test'
handle_name = 'foo'
obj_name = '%s-%s' % (stack_name, handle_name)
self.assertNotIn('x-account-meta-temp-url-key', head_account)
self.swift_plugin.get_temp_url(container_name, obj_name)
self.assertTrue(self.swift_client.post_account.called)
self.assertIn('x-account-meta-temp-url-key', head_account)
def test_get_signal_url(self):
self.swift_client.url = ("http://fake-host.com:8080/v1/"