]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
improve test coverage a bit
authorBrian Warner <warner@allmydata.com>
Wed, 17 Jan 2007 22:34:29 +0000 (15:34 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 17 Jan 2007 22:34:29 +0000 (15:34 -0700)
src/allmydata/filetable.py
src/allmydata/test/test_filetable.py
src/allmydata/test/test_filetree_new.py
src/allmydata/test/test_system.py

index 7b8c0e19173f4b6c4c4492386b80202640cf466d..f0f2b492b170e10356633513bc59e5996c7e72d0 100644 (file)
@@ -13,6 +13,8 @@ class BadDirectoryError(Exception):
     """There was a problem with the directory being referenced."""
 class BadFileError(Exception):
     """The file being referenced does not exist."""
+class BadNameError(Exception):
+    """Bad filename component"""
 
 class MutableDirectoryNode(Referenceable):
     implements(RIMutableDirectoryNode)
@@ -25,7 +27,7 @@ class MutableDirectoryNode(Referenceable):
 
     def validate_name(self, name):
         if name == "." or name == ".." or "/" in name:
-            raise DeadDirectoryNodeError("bad filename component")
+            raise BadNameError("'%s' is not cool" % name)
 
     # these are the public methods, available to anyone who holds a reference
 
index f72a9d31bbad44ef39fd49b35e76a99c59c97cc5..f4a5a66235f0d13df0c822f641239dad39a3e890 100644 (file)
@@ -1,8 +1,8 @@
 
 import os
 from twisted.trial import unittest
-from allmydata.filetable import MutableDirectoryNode, \
-     DeadDirectoryNodeError, BadDirectoryError, BadFileError
+from allmydata.filetable import (MutableDirectoryNode, DeadDirectoryNodeError,
+                                 BadDirectoryError, BadFileError, BadNameError)
 
 
 class FileTable(unittest.TestCase):
@@ -21,6 +21,9 @@ class FileTable(unittest.TestCase):
 
         self.failUnlessEqual(root.get("one"), "vid-one")
         self.failUnlessRaises(BadFileError, root.get, "missing")
+        self.failUnlessRaises(BadNameError, root.get, "/etc/passwd") # evil
+        self.failUnlessRaises(BadNameError, root.get, "..") # sneaky
+        self.failUnlessRaises(BadNameError, root.get, ".") # dumb
 
         # now play with directories
         subdir1 = root.add_directory("subdir1")
index 1ce1432ae04dab1e357ee5a33edc88ae30f27521..a7434376272e6ed2fae9afcf2bfe5f1aa2a92123 100644 (file)
@@ -254,12 +254,12 @@ class MultipleSubTrees(unittest.TestCase):
         o = FakeOpener({("CHK-Directory", "dir_three_uri"): st2})
 
         d = defer.succeed(None)
-        #d.addCallback(lambda res:
-        #              st1.get(["one", "two", "three", "four", "five"], o))
+        d.addCallback(lambda res:
+                      st1.get(["one", "two", "three", "four", "five"], o))
         def _got_five(res):
             self.failUnless(IDirectoryNode.providedBy(res))
             self.failUnlessIdentical(res, five)
-        #d.addCallback(_got_five)
+        d.addCallback(_got_five)
 
         d.addCallback(lambda res:
                       st1.add(["one", "two", "six"],
index f2f531261d533ea4252b7f045e119d72a22c6d28..3ebc49f13d3fe37cda6b283b57aa9019276a5ea4 100644 (file)
@@ -125,10 +125,6 @@ class SystemTest(unittest.TestCase):
             log.msg("download finished")
             self.failUnlessEqual(data, DATA)
         d.addCallback(_download_done)
-        def _oops(res):
-            log.msg("oops, an error orccurred, finishing: %s" % res)
-            return res
-        d.addErrback(_oops)
         return d
     test_upload_and_download.timeout = 20