"""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)
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
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):
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")
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"],
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