From: Itamar Turner-Trauring Date: Thu, 21 Mar 2013 18:36:33 +0000 (-0400) Subject: Fix prefix inclusion, so authentication works. X-Git-Url: https://git.rkrishnan.org/a?a=commitdiff_plain;h=f19689628186c0e801ce7cc4785eac7b2838bde3;p=tahoe-lafs%2Ftahoe-lafs.git Fix prefix inclusion, so authentication works. --- diff --git a/src/allmydata/storage/backends/cloud/msazure/msazure_container.py b/src/allmydata/storage/backends/cloud/msazure/msazure_container.py index fb5c5d40..f99b0510 100644 --- a/src/allmydata/storage/backends/cloud/msazure/msazure_container.py +++ b/src/allmydata/storage/backends/cloud/msazure/msazure_container.py @@ -158,7 +158,9 @@ class MSAzureStorageContainer(CommonContainerMixin): List objects in this container with the given prefix. """ url = self._make_container_url(self.URI) - url += "?comp=list&restype=container&prefix=" + urllib.quote(prefix, safe='') + url += "?comp=list&restype=container" + if prefix: + url += "&prefix=" + urllib.quote(prefix, safe='') d = self._authorized_http_request("MS Azure list objects", 'GET', url, {}, body=None, @@ -219,3 +221,32 @@ def configure_msazure_container(storedir, config): container_name = config.get_config("storage", "msazure.container_name") account_key = config.get_private_config("msazure_account_key") return MSAzureStorageContainer(account_name, account_key, container_name) + + +if __name__ == '__main__': + from twisted.internet import reactor, defer + from twisted.python import log + import sys + msc = MSAzureStorageContainer(sys.argv[1], sys.argv[2], sys.argv[3]) + + @defer.inlineCallbacks + def testtransactions(): + yield msc.put_object("key", "the value") + print "Uploaded key:'the value'" + print + print "Get contents:" + result = yield msc.list_objects() + print [item.key for item in result.contents] + print "Get key, value is:" + print (yield msc.get_object("key")) + print + print "Delete item:" + yield msc.delete_object("key") + print + print "Get contents:" + result = yield msc.list_objects() + print [item.key for item in result.contents] + reactor.stop() + + testtransactions().addErrback(log.err) + reactor.run() diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 4a5312bc..ef4ad1db 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -1217,6 +1217,23 @@ class MSAzureStorageBackendTests(unittest.TestCase, CloudStorageBackendMixin): self.container._time = lambda: 123 self.date = "Thu, 01 Jan 1970 00:02:03 GMT" + def test_list_objects_no_prefix(self): + """ + MSAzureStorageContainer.list_objects() with no prefix omits it from + the query. + """ + self.mock_http_request() + self.container.list_objects() + self.container._http_request.assert_called_once_with( + "MS Azure list objects", "GET", + "https://theaccount.blob.core.windows.net/thebucket?comp=list&restype=container", + {"Authorization": [self.authorization], + "x-ms-version": ["2012-02-12"], + "x-ms-date": [self.date], + }, + body=None, + need_response_body=True) + def test_list_objects(self): """ MSAzureStorageContainer.list_objects() sends the appropriate HTTP