From 6e8e44b120af12c01e79465e0ca63b09939a790d Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 21 May 2014 10:29:08 -0500 Subject: [PATCH 1/4] SFTP: add more unit tests --- tests/Net/SFTPFunctionalTest.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/Net/SFTPFunctionalTest.php b/tests/Net/SFTPFunctionalTest.php index 4f524be8..9d8d0731 100644 --- a/tests/Net/SFTPFunctionalTest.php +++ b/tests/Net/SFTPFunctionalTest.php @@ -19,6 +19,7 @@ class Net_SFTPFunctionalTest extends PhpseclibFunctionalTestCase 'This test hangs on Travis CI on PHP 5.3.3 and below.' ); } + parent::setUpBeforeClass(); self::$scratchDir = uniqid('phpseclib-sftp-scratch-'); @@ -123,6 +124,22 @@ class Net_SFTPFunctionalTest extends PhpseclibFunctionalTestCase return $sftp; } + /** + * @depends testChDirScratch + */ + public function testStatOnDir($sftp) + { + $stat = $sftp->stat('.'); + + $this->assertThat( + $stat, + $this->logicalNot($this->equalTo(array())), + 'Failed asserting that the cwd has a non-empty stat' + ); + + return $sftp; + } + /** * @depends testChDirScratch */ @@ -148,6 +165,19 @@ class Net_SFTPFunctionalTest extends PhpseclibFunctionalTestCase return $sftp; } + /** + * @depends testPutSizeGetFile + */ + public function testChDirOnFile($sftp) + { + $this->assertFalse( + $sftp->chdir('file1.txt'), + 'Failed to assert that the cwd cannot be changed to a file' + ); + + return $sftp; + } + /** * @depends testPutSizeGetFile */ From 8a43f02ae98ffd302a6658fcddcd102fb62d25ce Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 22 May 2014 00:37:15 +0200 Subject: [PATCH 2/4] SFTP Functional tests: Keep story linear. --- tests/Net/SFTPFunctionalTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Net/SFTPFunctionalTest.php b/tests/Net/SFTPFunctionalTest.php index 9d8d0731..0fc2399d 100644 --- a/tests/Net/SFTPFunctionalTest.php +++ b/tests/Net/SFTPFunctionalTest.php @@ -141,7 +141,7 @@ class Net_SFTPFunctionalTest extends PhpseclibFunctionalTestCase } /** - * @depends testChDirScratch + * @depends testStatOnDir */ public function testPutSizeGetFile($sftp) { @@ -179,7 +179,7 @@ class Net_SFTPFunctionalTest extends PhpseclibFunctionalTestCase } /** - * @depends testPutSizeGetFile + * @depends testChDirOnFile */ public function testFileExistsIsFileIsDirFile($sftp) { From 5afc865775b523357ba15baafd85fde8b0b7115f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 22 May 2014 00:38:04 +0200 Subject: [PATCH 3/4] SFTP Functional tests: Make use of assertNotSame --- tests/Net/SFTPFunctionalTest.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/Net/SFTPFunctionalTest.php b/tests/Net/SFTPFunctionalTest.php index 0fc2399d..9c43b55b 100644 --- a/tests/Net/SFTPFunctionalTest.php +++ b/tests/Net/SFTPFunctionalTest.php @@ -129,12 +129,10 @@ class Net_SFTPFunctionalTest extends PhpseclibFunctionalTestCase */ public function testStatOnDir($sftp) { - $stat = $sftp->stat('.'); - - $this->assertThat( - $stat, - $this->logicalNot($this->equalTo(array())), - 'Failed asserting that the cwd has a non-empty stat' + $this->assertNotSame( + array(), + $sftp->stat('.'), + 'Failed asserting that the cwd has a non-empty stat.' ); return $sftp; From 1ddcd6d87392e1c8763c65e286574c7393f8ef4e Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 21 May 2014 19:55:12 -0500 Subject: [PATCH 4/4] SFTP: last commit had a few ommissions --- phpseclib/Net/SFTP.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 103a7cd5..3c746565 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -1033,10 +1033,13 @@ class Net_SFTP extends Net_SSH2 $stat = $this->_stat($filename, NET_SFTP_STAT); if ($stat === false) { - $this->_update_stat_cache($filename, 0); + $this->_remove_from_stat_cache($filename); return false; } if (isset($stat['type'])) { + if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) { + $filename.= '/.'; + } $this->_update_stat_cache($filename, (object) $stat); return $stat; } @@ -1047,6 +1050,9 @@ class Net_SFTP extends Net_SSH2 NET_SFTP_TYPE_REGULAR; $this->pwd = $pwd; + if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) { + $filename.= '/.'; + } $this->_update_stat_cache($filename, (object) $stat); return $stat; @@ -1084,9 +1090,13 @@ class Net_SFTP extends Net_SSH2 $lstat = $this->_stat($filename, NET_SFTP_LSTAT); if ($lstat === false) { + $this->_remove_from_stat_cache($filename); return false; } if (isset($lstat['type'])) { + if ($lstat['type'] == NET_SFTP_TYPE_DIRECTORY) { + $filename.= '/.'; + } $this->_update_stat_cache($filename, (object) $lstat); return $lstat; } @@ -1105,6 +1115,9 @@ class Net_SFTP extends Net_SSH2 NET_SFTP_TYPE_REGULAR; $this->pwd = $pwd; + if ($lstat['type'] == NET_SFTP_TYPE_DIRECTORY) { + $filename.= '/.'; + } $this->_update_stat_cache($filename, (object) $lstat); return $lstat;