Ticket #4909: diff.patch

File diff.patch, 2.3 KB (added by bigjools, 5 years ago)
  • twisted/test/test_ftp.py

     
    422422        d2.addErrback(eb)
    423423        return defer.gatherResults([d1, d2])
    424424
     425    def test_STORwriteError(self):
     426        """
     427        Any errors during writing a file inside a STOR should be returned to
     428        the client.
     429        """
     430        # Make a failing file writer.
     431        class FailingFileWriter(ftp._FileWriter):
     432            def receive(self):
     433                return defer.fail(ftp.IsNotADirectoryError("blah"))
    425434
     435        def failing_stor(a, b):
     436            return defer.succeed(FailingFileWriter(None))
     437
     438        # Monkey patch the shell so it returns a file writer that will
     439        # fail.
     440        self.patch(ftp.FTPAnonymousShell, 'openForWriting', failing_stor)
     441
     442        def eb(res):
     443            self.flushLoggedErrors()
     444            res.trap(ftp.CommandFailed)
     445            self.assertEquals(
     446                res.value.args[0][0],
     447                "550 Cannot rmd, ('blah',) is not a directory")
     448        d1, d2 = self.client.storeFile('failing_file')
     449        d2.addErrback(eb)
     450        return defer.gatherResults([d1, d2])
     451
     452
    426453class FTPServerPasvDataConnectionTestCase(FTPServerTestCase):
    427454    def _makeDataConnection(self, ignored=None):
    428455        # Establish a passive data connection (i.e. client connecting to
  • twisted/protocols/ftp.py

     
    11121112        def ebSent(err):
    11131113            log.msg("Unexpected error receiving file from client:")
    11141114            log.err(err)
     1115            if err.check(FTPCmdError):
     1116                return (err.value.errorCode, err.value.errorMessage)
    11151117            return (CNX_CLOSED_TXFR_ABORTED,)
    11161118
    11171119        def cbConsumer(cons):
  • twisted/topfiles/4909.feature

     
     1twisted.protocols.ftp.FTP.ftp_STOR now catches `FTPCmdError`s raised by
     2the file writer, and returns the error back to the client.