]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Fix prefix inclusion, so authentication works.
authorItamar Turner-Trauring <itamar@futurefoundries.com>
Thu, 21 Mar 2013 18:36:33 +0000 (14:36 -0400)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 4 Aug 2015 17:20:42 +0000 (18:20 +0100)
src/allmydata/storage/backends/cloud/msazure/msazure_container.py
src/allmydata/test/test_storage.py

index fb5c5d40e3d8c9ac3224bf033a35c0d5e71bf409..f99b0510201eb07d4ada03c10fde45f530aecc4f 100644 (file)
@@ -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()
index 09d93b0c79a3a328cdfb5851e4fe326465aeb048..4bdbb51eddef808b72568750d335b3ae3d985a8d 100644 (file)
@@ -1224,6 +1224,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