Ticket #4913: 4913-ftp-stor-err-1.diff

File 4913-ftp-stor-err-1.diff, 2.1 KB (added by adiroiban, 4 years ago)
  • twisted/test/test_ftp.py

     
    448448        d2.addErrback(eb)
    449449        return defer.gatherResults([d1, d2])
    450450
     451    def test_RETRreadError(self):
     452        """
     453        Any errors during reading a file inside a RETR should be returned to
     454        the client.
     455        """
     456        # Make a failing file reading.
     457        class FailingFileReader(ftp._FileReader):
     458            def send(self, consumer):
     459                return defer.fail(ftp.IsADirectoryError("blah"))
    451460
     461        def failingRETR(a, b):
     462            return defer.succeed(FailingFileReader(None))
    452463
     464        # Monkey patch the shell so it returns a file reader that will
     465        # fail.
     466        self.patch(ftp.FTPAnonymousShell, 'openForReading', failingRETR)
     467
     468        def check_response(failure):
     469            self.flushLoggedErrors()
     470            failure.trap(ftp.CommandFailed)
     471            self.assertEqual(
     472                failure.value.args[0][0],
     473                "125 Data connection already open, starting transfer")
     474            self.assertEqual(
     475                failure.value.args[0][1],
     476                "550 blah: is a directory")
     477
     478        proto = _BufferingProtocol()
     479        d = self.client.retrieveFile('failing_file', proto)
     480        d.addErrback(check_response)
     481        return d
     482
     483
    453484class FTPServerPasvDataConnectionTestCase(FTPServerTestCase):
    454485    def _makeDataConnection(self, ignored=None):
    455486        # Establish a passive data connection (i.e. client connecting to
  • twisted/protocols/ftp.py

     
    10681068        def ebSent(err):
    10691069            log.msg("Unexpected error attempting to transmit file to client:")
    10701070            log.err(err)
     1071            if err.check(FTPCmdError):
     1072                return err
    10711073            return (CNX_CLOSED_TXFR_ABORTED,)
    10721074
    10731075        def cbOpened(file):