From b4e074d2501c7f792e4b13f270b55ffeecfdef49 Mon Sep 17 00:00:00 2001 From: david-sarah Date: Fri, 11 Jun 2010 14:31:42 -0700 Subject: [PATCH] SFTP: further improve test coverage (paths containing '.', bad data for posix-rename extension, and error in test of openShell). --- src/allmydata/frontends/sftpd.py | 1 + src/allmydata/test/test_sftp.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/allmydata/frontends/sftpd.py b/src/allmydata/frontends/sftpd.py index a96ae3ec..b44879fe 100644 --- a/src/allmydata/frontends/sftpd.py +++ b/src/allmydata/frontends/sftpd.py @@ -1786,6 +1786,7 @@ class SFTPUserHandler(ConchUser, PrefixingLogMixin): if extensionName == 'posix-rename@openssh.com': def _bad(): raise SFTPError(FX_BAD_MESSAGE, "could not parse posix-rename@openssh.com request") + if 4 > len(extensionData): return defer.execute(_bad) (fromPathLen,) = struct.unpack('>L', extensionData[0:4]) if 8 + fromPathLen > len(extensionData): return defer.execute(_bad) diff --git a/src/allmydata/test/test_sftp.py b/src/allmydata/test/test_sftp.py index 7b69297d..40541943 100644 --- a/src/allmydata/test/test_sftp.py +++ b/src/allmydata/test/test_sftp.py @@ -169,6 +169,8 @@ class Handler(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, unittest.TestCas self.failUnlessReallyEqual(self.handler._path_from_string("/foo/bar"), [u"foo", u"bar"]) self.failUnlessReallyEqual(self.handler._path_from_string("foo/bar//"), [u"foo", u"bar"]) self.failUnlessReallyEqual(self.handler._path_from_string("/foo/bar//"), [u"foo", u"bar"]) + self.failUnlessReallyEqual(self.handler._path_from_string("foo/./bar"), [u"foo", u"bar"]) + self.failUnlessReallyEqual(self.handler._path_from_string("./foo/./bar"), [u"foo", u"bar"]) self.failUnlessReallyEqual(self.handler._path_from_string("foo/../bar"), [u"bar"]) self.failUnlessReallyEqual(self.handler._path_from_string("/foo/../bar"), [u"bar"]) self.failUnlessReallyEqual(self.handler._path_from_string("../bar"), [u"bar"]) @@ -188,6 +190,8 @@ class Handler(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, unittest.TestCas self.failUnlessReallyEqual(self.handler.realPath("/foo/bar"), "/foo/bar") self.failUnlessReallyEqual(self.handler.realPath("foo/bar//"), "/foo/bar") self.failUnlessReallyEqual(self.handler.realPath("/foo/bar//"), "/foo/bar") + self.failUnlessReallyEqual(self.handler.realPath("foo/./bar"), "/foo/bar") + self.failUnlessReallyEqual(self.handler.realPath("./foo/./bar"), "/foo/bar") self.failUnlessReallyEqual(self.handler.realPath("foo/../bar"), "/bar") self.failUnlessReallyEqual(self.handler.realPath("/foo/../bar"), "/bar") self.failUnlessReallyEqual(self.handler.realPath("../bar"), "/bar") @@ -1323,7 +1327,7 @@ class Handler(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, unittest.TestCas d2.addCallback(lambda ign: self.failUnlessEqual(protocol.reason.value.exitCode, 1)) d2.addCallback(lambda ign: session.closed()) return d2 - d.addCallback(_exec_error) + d.addCallback(_openShell) return d @@ -1340,4 +1344,14 @@ class Handler(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, unittest.TestCas self.shouldFailWithSFTPError(sftp.FX_OP_UNSUPPORTED, "extendedRequest foo bar", self.handler.extendedRequest, "foo", "bar")) + d.addCallback(lambda ign: + self.shouldFailWithSFTPError(sftp.FX_BAD_MESSAGE, "extendedRequest posix-rename@openssh.com invalid 1", + self.handler.extendedRequest, 'posix-rename@openssh.com', '')) + d.addCallback(lambda ign: + self.shouldFailWithSFTPError(sftp.FX_BAD_MESSAGE, "extendedRequest posix-rename@openssh.com invalid 2", + self.handler.extendedRequest, 'posix-rename@openssh.com', '\x00\x00\x00\x01')) + d.addCallback(lambda ign: + self.shouldFailWithSFTPError(sftp.FX_BAD_MESSAGE, "extendedRequest posix-rename@openssh.com invalid 3", + self.handler.extendedRequest, 'posix-rename@openssh.com', '\x00\x00\x00\x01_\x00\x00\x00\x01')) + return d -- 2.45.2