From 56df1a48f425605ff6bd6591d3f94f38103eb7a2 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 17 Jan 2007 15:34:29 -0700 Subject: [PATCH] improve test coverage a bit --- src/allmydata/filetable.py | 4 +++- src/allmydata/test/test_filetable.py | 7 +++++-- src/allmydata/test/test_filetree_new.py | 6 +++--- src/allmydata/test/test_system.py | 4 ---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/allmydata/filetable.py b/src/allmydata/filetable.py index 7b8c0e19..f0f2b492 100644 --- a/src/allmydata/filetable.py +++ b/src/allmydata/filetable.py @@ -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 diff --git a/src/allmydata/test/test_filetable.py b/src/allmydata/test/test_filetable.py index f72a9d31..f4a5a662 100644 --- a/src/allmydata/test/test_filetable.py +++ b/src/allmydata/test/test_filetable.py @@ -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") diff --git a/src/allmydata/test/test_filetree_new.py b/src/allmydata/test/test_filetree_new.py index 1ce1432a..a7434376 100644 --- a/src/allmydata/test/test_filetree_new.py +++ b/src/allmydata/test/test_filetree_new.py @@ -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"], diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index f2f53126..3ebc49f1 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -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 -- 2.45.2