1
0
mirror of https://github.com/danog/tgseclib.git synced 2024-11-27 04:34:45 +01:00

Merge branch 'authenticated-1.0' into authenticated-2.0

This commit is contained in:
terrafrost 2015-12-16 09:20:27 -06:00
commit d17aeffc04
2 changed files with 46 additions and 0 deletions

View File

@ -2862,6 +2862,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 & NET_SSH2_MASK_LOGIN);
}
/**
* Gets Binary Packets
*

View File

@ -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;
}