Ticket #4930: 4930-rnto-3.diff
| File 4930-rnto-3.diff, 3.7 KB (added by adiroiban, 11 months ago) |
|---|
-
twisted/test/test_ftp.py
81 81 self.dirPath = filepath.FilePath(self.directory) 82 82 83 83 # 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 )) 85 88 p.registerChecker(checkers.AllowAnonymousAccess(), 86 89 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 87 97 self.factory = ftp.FTPFactory(portal=p, 88 98 userAnonymous=self.userAnonymous) 89 99 port = reactor.listenTCP(0, self.factory, interface="127.0.0.1") … … 159 169 ['230 Anonymous login ok, access restrictions apply.'], 160 170 chainDeferred=d) 161 171 172 def _userLogin(self): 173 """Authenticates the FTP client using the test account.""" 174 d = self.assertCommandResponse( 175 'USER %s' % (self.username), 176 ['331 Password required for %s.' % (self.username)]) 177 return self.assertCommandResponse( 178 'PASS %s' % (self.password), 179 ['230 User logged in, proceed'], 180 chainDeferred=d) 162 181 163 182 164 183 class FTPAnonymousTestCase(FTPServerTestCase): … … 342 361 self.serverProtocol.transport.loseConnection() 343 362 testPASV = defer.deferredGenerator(testPASV) 344 363 345 def testSYST(self): 364 def test_SYST(self): 365 """SYST command will always return UNIX Type: L8""" 346 366 d = self._anonymousLogin() 347 367 self.assertCommandResponse('SYST', ["215 UNIX Type: L8"], 348 368 chainDeferred=d) 349 369 return d 350 370 371 def test_RNFRandRNTO(self): 372 """ 373 Sending the RNFR command followed by RNTO should perform a 374 successful rename operation. 375 """ 376 # Create user home folder with a 'foo' file. 377 self.dirPath.child(self.username).createDirectory() 378 self.dirPath.child(self.username).child('foo').touch() 351 379 380 d = self._userLogin() 381 self.assertCommandResponse( 382 'RNFR foo', 383 ["350 Requested file action pending further information."], 384 chainDeferred=d) 385 self.assertCommandResponse( 386 'RNTO bar', 387 ["250 Requested File Action Completed OK"], 388 chainDeferred=d) 389 390 def check_rename(result): 391 self.assertTrue( 392 self.dirPath.child(self.username).child('bar').exists()) 393 return result 394 395 d.addCallback(check_rename) 396 return d 397 398 def test_RNFRwithoutRNTO(self): 399 """ 400 Sending the RNFR command followed by any command other than RNTO 401 should return an error informing users that RNFR should be followed 402 by RNTO. 403 """ 404 d = self._anonymousLogin() 405 self.assertCommandResponse( 406 'RNFR foo', 407 ["350 Requested file action pending further information."], 408 chainDeferred=d) 409 self.assertCommandFailed( 410 'OTHER don-tcare', 411 ["503 Incorrect sequence of commands: RNTO required after RNFR"], 412 chainDeferred=d) 413 return d 414 352 415 def test_portRangeForwardError(self): 353 416 """ 354 417 Exceptions other than L{error.CannotListenError} which are raised by
