Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
fixed skipped tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias committed Jul 4, 2009
1 parent 37f7bfa commit 35da20b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 33 deletions.
1 change: 1 addition & 0 deletions filesystem/__init__.py
Expand Up @@ -11,5 +11,6 @@
StatWrappersMixin,
InsecurePathError,
CrossDeviceRenameError,
raise_on_insecure_file_name
)

20 changes: 13 additions & 7 deletions filesystem/_base.py
Expand Up @@ -24,6 +24,18 @@ class CrossDeviceRenameError(Exception):
"""
pass

## utility function for checking for safe file names.
## TODO: should it be encapsulated within a class?
def raise_on_insecure_file_name(name):
if u'/' in name:
raise InsecurePathError(
'child name contains directory separator')
# this may be too naive
if name == u'..':
raise InsecurePathError(
'child trying to climb out of directory')



## TODO: RFC: Is there any presedence for this naming convention? As
## I understand it, "Mixin" means that this class can be mixed into
Expand Down Expand Up @@ -203,13 +215,7 @@ def child(self, *segments):
"""
p = self
for segment in segments:
if u'/' in segment:
raise InsecurePathError(
'child name contains directory separator')
# this may be too naive
if segment == u'..':
raise InsecurePathError(
'child trying to climb out of directory')
raise_on_insecure_file_name(segment)
p = p.join(segment)
return p

Expand Down
1 change: 1 addition & 0 deletions filesystem/inmem.py
Expand Up @@ -134,6 +134,7 @@ def child(self, segment=None, *segments):
return self

if not self._children.has_key(segment):
filesystem.raise_on_insecure_file_name(segment)
child = self.__class__(name=segment, parent=self)
self._children[segment] = child

Expand Down
2 changes: 0 additions & 2 deletions filesystem/test/test_roundtrip_copyonwrite.py
Expand Up @@ -14,5 +14,3 @@ def setUp(self):
self.path = filesystem.copyonwrite.path(real_path)
assert self.path.exists()

def test_child_bad_slash(self):
raise nose.SkipTest('TODO temporary pardon')
6 changes: 0 additions & 6 deletions filesystem/test/test_roundtrip_inmem.py
Expand Up @@ -10,9 +10,3 @@ def setUp(self):
assert not self.path.exists()
self.path.mkdir(create_parents=True, may_exist=True)
assert self.path.exists()

def test_child_bad_slash(self):
raise nose.SkipTest('TODO temporary pardon')

def test_child_bad_dotdot(self):
raise nose.SkipTest('TODO temporary pardon')
8 changes: 0 additions & 8 deletions filesystem/test/test_roundtrip_multiplexing.py
Expand Up @@ -15,19 +15,11 @@ def setUp(self):
self.path.mkdir(create_parents=True, may_exist=True)
assert self.path.exists()

def test_child_bad_slash(self):
raise nose.SkipTest('TODO temporary pardon')

def test_child_bad_dotdot(self):
raise nose.SkipTest('TODO temporary pardon')

class MultiPlexingLocalFS_Tests(test_roundtrip.OperationsMixin):
def setUp(self):
real_path = filesystem.path(maketemp())
self.path = filesystem.multiplexing.path()
self.path.bind(real_path)
assert self.path.exists()

def test_child_bad_slash(self):
raise nose.SkipTest('TODO temporary pardon')

23 changes: 13 additions & 10 deletions filesystem/test/util.py
Expand Up @@ -39,16 +39,19 @@ def get_nose_name(its_self):
return its_self.moduleName

i = 0
while True:
i += 1
frame = sys._getframe(i)
# kludge, hunt callers upwards until we find our nose
if (frame.f_code.co_varnames
and frame.f_code.co_varnames[0] == 'self'):
its_self = frame.f_locals['self']
name = get_nose_name(its_self)
if name is not None:
return name
try:
while True:
i += 1
frame = sys._getframe(i)
# kludge, hunt callers upwards until we find our nose
if (frame.f_code.co_varnames
and frame.f_code.co_varnames[0] == 'self'):
its_self = frame.f_locals['self']
name = get_nose_name(its_self)
if name is not None:
return name
except ValueError:
return 'undefined'

def maketemp():
tmp = os.path.join(os.path.dirname(__file__), 'tmp')
Expand Down

0 comments on commit 35da20b

Please sign in to comment.