Ticket #4930: 4930-rnto-1.diff

File 4930-rnto-1.diff, 2.8 KB (added by adiroiban, 4 years ago)
  • twisted/test/test_ftp.py

     
    8181        self.dirPath = filepath.FilePath(self.directory)
    8282
    8383        # Start the server
    84         p = portal.Portal(ftp.FTPRealm(self.directory))
     84        p = portal.Portal(ftp.FTPRealm(
     85            anonymousRoot=self.directory,
     86            userHome=self.directory,
     87            ))
    8588        p.registerChecker(checkers.AllowAnonymousAccess(),
    8689                          credentials.IAnonymous)
     90
     91        users_checker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
     92        self.username = "test-user"
     93        self.password = "test-password"
     94        users_checker.addUser(self.username, self.password)
     95        p.registerChecker(users_checker, credentials.IUsernamePassword)
     96
    8797        self.factory = ftp.FTPFactory(portal=p,
    8898                                      userAnonymous=self.userAnonymous)
    8999        port = reactor.listenTCP(0, self.factory, interface="127.0.0.1")
     
    159169            ['230 Anonymous login ok, access restrictions apply.'],
    160170            chainDeferred=d)
    161171
     172    def _userLogin(self):
     173        d = self.assertCommandResponse(
     174            'USER %s' % (self.username),
     175            ['331 Password required for %s.' % (self.username)])
     176        return self.assertCommandResponse(
     177            'PASS %s' % (self.password),
     178            ['230 User logged in, proceed'],
     179            chainDeferred=d)
    162180
    163181
    164182class FTPAnonymousTestCase(FTPServerTestCase):
     
    348366                                   chainDeferred=d)
    349367        return d
    350368
     369    def testRNFRandRNTO(self):
     370        # Create user home folder with a 'foo' file.
     371        self.dirPath.child(self.username).createDirectory()
     372        self.dirPath.child(self.username).child('foo').touch()
    351373
     374        d = self._userLogin()
     375        self.assertCommandResponse(
     376            'RNFR foo',
     377            ["350 Requested file action pending further information."],
     378            chainDeferred=d)
     379        self.assertCommandResponse(
     380            'RNTO bar',
     381            ["250 Requested File Action Completed OK"],
     382            chainDeferred=d)
     383        return d
     384
     385    def testRNFRwithoutRNTO(self):
     386        d = self._anonymousLogin()
     387        self.assertCommandResponse(
     388            'RNFR foo',
     389            ["350 Requested file action pending further information."],
     390            chainDeferred=d)
     391        self.assertCommandFailed(
     392            'OTHER don-tcare',
     393            ["503 Incorrect sequence of commands: RNTO required after RNFR"],
     394            chainDeferred=d)
     395        return d
     396
    352397    def test_portRangeForwardError(self):
    353398        """
    354399        Exceptions other than L{error.CannotListenError} which are raised by