mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-26 19:40:28 +00:00
Merge branch '1.0' of https://github.com/phpseclib/phpseclib into 1.0
This commit is contained in:
commit
62fc4bbc88
@ -171,7 +171,18 @@ class Net_SFTP_Stream
|
|||||||
*/
|
*/
|
||||||
function _parse_path($path)
|
function _parse_path($path)
|
||||||
{
|
{
|
||||||
|
$orig = $path;
|
||||||
extract(parse_url($path) + array('port' => 22));
|
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)) {
|
if (!isset($host)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -2964,6 +2964,17 @@ class Net_SSH2
|
|||||||
return (bool) ($this->bitmap & NET_SSH2_MASK_CONNECTED);
|
return (bool) ($this->bitmap & NET_SSH2_MASK_CONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Have you successfully been logged in?
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function isAuthenticated()
|
||||||
|
{
|
||||||
|
return (bool) ($this->bitmap & NET_SSH2_MASK_LOGIN);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets Binary Packets
|
* Gets Binary Packets
|
||||||
*
|
*
|
||||||
|
@ -22,6 +22,21 @@ class Functional_Net_SFTPStreamTest extends Functional_Net_SFTPTestCase
|
|||||||
$this->assertSame(0, $this->sftp->size('fooo.txt'));
|
$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()));
|
||||||
|
}
|
||||||
|
|
||||||
protected function buildUrl($suffix)
|
protected function buildUrl($suffix)
|
||||||
{
|
{
|
||||||
return sprintf(
|
return sprintf(
|
||||||
|
@ -32,6 +32,11 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase
|
|||||||
'Failed asserting that SSH2 is not connected after construction.'
|
'Failed asserting that SSH2 is not connected after construction.'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->assertFalse(
|
||||||
|
$ssh->isAuthenticated(),
|
||||||
|
'Failed asserting that SSH2 is not authenticated after construction.'
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertNotEmpty(
|
$this->assertNotEmpty(
|
||||||
$ssh->getServerPublicHostKey(),
|
$ssh->getServerPublicHostKey(),
|
||||||
'Failed asserting that a non-empty public host key was fetched.'
|
'Failed asserting that a non-empty public host key was fetched.'
|
||||||
@ -53,6 +58,31 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase
|
|||||||
/**
|
/**
|
||||||
* @depends testPreLogin
|
* @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)
|
public function testPasswordLogin($ssh)
|
||||||
{
|
{
|
||||||
$username = $this->getEnv('SSH_USERNAME');
|
$username = $this->getEnv('SSH_USERNAME');
|
||||||
@ -62,6 +92,11 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase
|
|||||||
'SSH2 login using password failed.'
|
'SSH2 login using password failed.'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$ssh->isAuthenticated(),
|
||||||
|
'Failed asserting that SSH2 is authenticated after good login attempt.'
|
||||||
|
);
|
||||||
|
|
||||||
return $ssh;
|
return $ssh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user