]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
SFTP: further improve test coverage (paths containing '.', bad data for posix-rename...
authordavid-sarah <david-sarah@jacaranda.org>
Fri, 11 Jun 2010 21:31:42 +0000 (14:31 -0700)
committerdavid-sarah <david-sarah@jacaranda.org>
Fri, 11 Jun 2010 21:31:42 +0000 (14:31 -0700)
src/allmydata/frontends/sftpd.py
src/allmydata/test/test_sftp.py

index a96ae3ec7bc18aa24f2685b31673f5f9fe594f0b..b44879fedea0f3700a7a0c6adb7f0f2310d17fd0 100644 (file)
@@ -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)
 
index 7b69297d99b1a385df77bdc109c13966d6b1df11..40541943f8b4f066c3da169f95a395771d7e324e 100644 (file)
@@ -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