]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
added unit test to webish's rename function
authorrobk-org <robk-org@allmydata.com>
Tue, 17 Jul 2007 00:05:01 +0000 (17:05 -0700)
committerrobk-org <robk-org@allmydata.com>
Tue, 17 Jul 2007 00:05:01 +0000 (17:05 -0700)
added unit tests to test various permutations of the rename function, and
some sanity checks on the rename-form function.

also added a guard to prevent '/' in from_/to_name in rename calls.

src/allmydata/test/test_web.py
src/allmydata/webish.py

index d8914b0fa0110739c436a33999c7d755b713fcd7..f39e00cefc3ccfc611c745234e66b7aa0cdcc7dd 100644 (file)
@@ -843,6 +843,57 @@ class Web(unittest.TestCase):
         d.addCallback(_check)
         return d
 
+    def test_POST_rename_file(self): # YES
+        d = self.POST("/vdrive/global/foo", t="rename",
+                      from_name="bar.txt", to_name='wibble.txt')
+        def _check(res):
+            self.failIf("bar.txt" in self._foo_node.children)
+            self.failUnless("wibble.txt" in self._foo_node.children)
+        d.addCallback(_check)
+        d.addCallback(lambda res: self.GET("/vdrive/global/foo/wibble.txt"))
+        d.addCallback(self.failUnlessIsBarDotTxt)
+        d.addCallback(lambda res: self.GET("/vdrive/global/foo/wibble.txt?t=json"))
+        d.addCallback(self.failUnlessIsBarJSON)
+        return d
+
+    def test_POST_rename_file_slash_fail(self): # YES
+        d = self.POST("/vdrive/global/foo", t="rename",
+                      from_name="bar.txt", to_name='kirk/spock.txt')
+        d.addBoth(self.shouldFail, error.Error,
+                  "test_POST_rename_file_slash_fail",
+                  "400 Bad Request",
+                  "to_name= may not contain a slash",
+                  )
+        def _check1(res):
+            self.failUnless("bar.txt" in self._foo_node.children)
+        d.addCallback(_check1)
+        d.addCallback(lambda res: self.POST("/vdrive/global", t="rename",
+                      from_name="foo/bar.txt", to_name='george.txt'))
+        d.addBoth(self.shouldFail, error.Error,
+                  "test_POST_rename_file_slash_fail",
+                  "400 Bad Request",
+                  "from_name= may not contain a slash",
+                  )
+        def _check2(res):
+            self.failUnless("foo" in self.public_root.children)
+            self.failIf("george.txt" in self.public_root.children)
+            self.failUnless("bar.txt" in self._foo_node.children)
+        d.addCallback(_check2)
+        d.addCallback(lambda res: self.GET("/vdrive/global/foo?t=json"))
+        d.addCallback(self.failUnlessIsFooJSON)
+        return d
+
+    def test_POST_rename_dir(self): # YES
+        d = self.POST("/vdrive/global", t="rename",
+                      from_name="foo", to_name='plunk')
+        def _check(res):
+            self.failIf("foo" in self.public_root.children)
+            self.failUnless("plunk" in self.public_root.children)
+        d.addCallback(_check)
+        d.addCallback(lambda res: self.GET("/vdrive/global/plunk?t=json"))
+        d.addCallback(self.failUnlessIsFooJSON)
+        return d
+
     def shouldRedirect(self, res, target):
         if not isinstance(res, failure.Failure):
             self.fail("we were expecting to get redirected to %s, not get an"
@@ -874,6 +925,15 @@ class Web(unittest.TestCase):
 
         return d
 
+    def test_GET_rename_form(self): # YES
+        d = self.GET("/vdrive/global/foo?t=rename-form&name=bar.txt",
+                     followRedirect=True) # XXX [ ] todo: figure out why '.../foo' doesn't work
+        def _check(res):
+            self.failUnless(re.search(r'name="when_done" value=".*vdrive/global/foo/', res))
+            self.failUnless(re.search(r'name="from_name" value="bar\.txt"', res))
+        d.addCallback(_check)
+        return d
+
     def log(self, res, msg):
         #print "MSG: %s  RES: %s" % (msg, res)
         log.msg(msg)
index eba44991d73fe6f107e660205e843ba2ff3068d1..2283d591e819e8d7aae88b1af87b214aa7b1f55b 100644 (file)
@@ -545,6 +545,11 @@ class POSTHandler(rend.Page):
                 raise RuntimeError("rename requires from_name and to_name")
             if not IDirectoryNode.providedBy(self._node):
                 raise RuntimeError("rename must only be called on directories")
+            for k,v in [ ('from_name', from_name), ('to_name', to_name) ]:
+                if v and "/" in v:
+                    req.setResponseCode(http.BAD_REQUEST)
+                    req.setHeader("content-type", "text/plain")
+                    return "%s= may not contain a slash" % (k,)
             d = self._node.get(from_name)
             def add_dest(child):
                 uri = child.get_uri()