diff --git a/phpseclib/Net/SFTP/Stream.php b/phpseclib/Net/SFTP/Stream.php index 7af7280a..d19d08b8 100644 --- a/phpseclib/Net/SFTP/Stream.php +++ b/phpseclib/Net/SFTP/Stream.php @@ -154,7 +154,18 @@ class Stream */ function _parse_path($path) { + $orig = $path; extract(parse_url($path) + array('port' => 22)); + if (isset($query)) { + $path.= '?' . $query; + } elseif (preg_match('/(\?|\?#)$/', $orig)) { + $path.= '?'; + } + if (isset($fragment)) { + $path.= '#' . $fragment; + } elseif ($orig[strlen($orig) - 1] == '#') { + $path.= '#'; + } if (!isset($host)) { return false; diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 33594914..409d29c5 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2866,6 +2866,17 @@ class SSH2 return (bool) ($this->bitmap & self::MASK_CONNECTED); } + /** + * Have you successfully been logged in? + * + * @return bool + * @access public + */ + function isAuthenticated() + { + return (bool) ($this->bitmap & self::MASK_LOGIN); + } + /** * Gets Binary Packets * diff --git a/tests/Functional/Net/SFTPStreamTest.php b/tests/Functional/Net/SFTPStreamTest.php index aab16ec9..83602359 100644 --- a/tests/Functional/Net/SFTPStreamTest.php +++ b/tests/Functional/Net/SFTPStreamTest.php @@ -27,6 +27,21 @@ class Functional_Net_SFTPStreamTest extends Functional_Net_SFTPTestCase $this->assertSame(0, $this->sftp->size('fooo.txt')); } + /** + * @group github778 + */ + public function testFilenameWithHash() + { + $context = stream_context_create(array( + 'sftp' => array('session' => $this->sftp), + )); + $fp = fopen($this->buildUrl('te#st.txt'), 'wb', false, $context); + fputs($fp, 'zzzz'); + fclose($fp); + + $this->assertTrue(in_array('te#st.txt', $this->sftp->nlist())); + } + /** * Tests connection reuse functionality same as ssh2 extension: * {@link http://php.net/manual/en/wrappers.ssh2.php#refsect1-wrappers.ssh2-examples} diff --git a/tests/Functional/Net/SSH2Test.php b/tests/Functional/Net/SSH2Test.php index 51373705..4c18abed 100644 --- a/tests/Functional/Net/SSH2Test.php +++ b/tests/Functional/Net/SSH2Test.php @@ -34,6 +34,11 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase 'Failed asserting that SSH2 is not connected after construction.' ); + $this->assertFalse( + $ssh->isAuthenticated(), + 'Failed asserting that SSH2 is not authenticated after construction.' + ); + $this->assertNotEmpty( $ssh->getServerPublicHostKey(), 'Failed asserting that a non-empty public host key was fetched.' @@ -55,6 +60,31 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase /** * @depends testPreLogin */ + public function testBadPassword($ssh) + { + $username = $this->getEnv('SSH_USERNAME'); + $password = $this->getEnv('SSH_PASSWORD'); + $this->assertFalse( + $ssh->login($username, 'zzz' . $password), + 'SSH2 login using password succeeded.' + ); + + $this->assertTrue( + $ssh->isConnected(), + 'Failed asserting that SSH2 is connected after bad login attempt.' + ); + + $this->assertFalse( + $ssh->isAuthenticated(), + 'Failed asserting that SSH2 is not authenticated after bad login attempt.' + ); + + return $ssh; + } + + /** + * @depends testBadPassword + */ public function testPasswordLogin($ssh) { $username = $this->getEnv('SSH_USERNAME'); @@ -64,6 +94,11 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase 'SSH2 login using password failed.' ); + $this->assertTrue( + $ssh->isAuthenticated(), + 'Failed asserting that SSH2 is authenticated after good login attempt.' + ); + return $ssh; }