]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
web: make sure that PUT /uri?mutable=false really means immutable, fixes #675
authorBrian Warner <warner@lothar.com>
Wed, 8 Apr 2009 02:13:40 +0000 (19:13 -0700)
committerBrian Warner <warner@lothar.com>
Wed, 8 Apr 2009 02:13:40 +0000 (19:13 -0700)
src/allmydata/test/test_web.py
src/allmydata/web/root.py

index 9bca752170d6d600f286dccc7b5c91eeb255009f..ad3fa40b4877e60ae2a6dee4e5bb3d82df62729e 100644 (file)
@@ -717,6 +717,17 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, unittest.TestCase):
                                                       self.NEWFILE_CONTENTS))
         return d
 
+    def test_PUT_NEWFILEURL_not_mutable(self):
+        d = self.PUT(self.public_url + "/foo/new.txt?mutable=false",
+                     self.NEWFILE_CONTENTS)
+        # TODO: we lose the response code, so we can't check this
+        #self.failUnlessEqual(responsecode, 201)
+        d.addCallback(self.failUnlessURIMatchesChild, self._foo_node, u"new.txt")
+        d.addCallback(lambda res:
+                      self.failUnlessChildContentsAre(self._foo_node, u"new.txt",
+                                                      self.NEWFILE_CONTENTS))
+        return d
+
     def test_PUT_NEWFILEURL_range_bad(self):
         headers = {"content-range": "bytes 1-10/%d" % len(self.NEWFILE_CONTENTS)}
         target = self.public_url + "/foo/new.txt"
@@ -2309,6 +2320,21 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, unittest.TestCase):
         d.addCallback(_check2)
         return d
 
+    def test_PUT_NEWFILE_URI_not_mutable(self):
+        file_contents = "New file contents here\n"
+        d = self.PUT("/uri?mutable=false", file_contents)
+        def _check(uri):
+            assert isinstance(uri, str), uri
+            self.failUnless(uri in FakeCHKFileNode.all_contents)
+            self.failUnlessEqual(FakeCHKFileNode.all_contents[uri],
+                                 file_contents)
+            return self.GET("/uri/%s" % uri)
+        d.addCallback(_check)
+        def _check2(res):
+            self.failUnlessEqual(res, file_contents)
+        d.addCallback(_check2)
+        return d
+
     def test_PUT_NEWFILE_URI_only_PUT(self):
         d = self.PUT("/uri?t=bogus", "")
         d.addBoth(self.shouldFail, error.Error,
index 196506e4a7c88cc05e5f89b6a011308772be6a5e..4d8d2c2dc272a48134c5452a2300e76c86f374c6 100644 (file)
@@ -16,7 +16,7 @@ from allmydata.interfaces import IFileNode
 from allmydata.web import filenode, directory, unlinked, status, operations
 from allmydata.web import reliability, storage
 from allmydata.web.common import abbreviate_size, getxmlfile, WebError, \
-     get_arg, RenderMixin
+     get_arg, RenderMixin, boolean_of_arg
 
 
 class URIHandler(RenderMixin, rend.Page):
@@ -45,7 +45,7 @@ class URIHandler(RenderMixin, rend.Page):
         # "PUT /uri?t=mkdir" to create an unlinked directory
         t = get_arg(req, "t", "").strip()
         if t == "":
-            mutable = bool(get_arg(req, "mutable", "").strip())
+            mutable = boolean_of_arg(get_arg(req, "mutable", "false").strip())
             if mutable:
                 return unlinked.PUTUnlinkedSSK(req, self.client)
             else: