2014-03-03 01:43:58 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Andreas Fischer <bantu@phpbb.com>
|
2014-12-10 00:02:44 +01:00
|
|
|
* @copyright 2014 Andreas Fischer
|
2014-03-03 01:43:58 +01:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2014-06-01 21:13:20 +02:00
|
|
|
class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase
|
2014-03-03 01:43:58 +01:00
|
|
|
{
|
|
|
|
public function testConstructor()
|
|
|
|
{
|
|
|
|
$ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME'));
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
is_object($ssh),
|
|
|
|
'Could not construct NET_SSH2 object.'
|
|
|
|
);
|
|
|
|
|
|
|
|
return $ssh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 18:07:17 +02:00
|
|
|
* @depends testConstructor
|
|
|
|
* @group github408
|
|
|
|
* @group github412
|
|
|
|
*/
|
2014-07-20 22:58:24 +02:00
|
|
|
public function testPreLogin($ssh)
|
|
|
|
{
|
|
|
|
$this->assertFalse(
|
|
|
|
$ssh->isConnected(),
|
|
|
|
'Failed asserting that SSH2 is not connected after construction.'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertNotEmpty(
|
|
|
|
$ssh->getServerPublicHostKey(),
|
|
|
|
'Failed asserting that a non-empty public host key was fetched.'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
$ssh->isConnected(),
|
|
|
|
'Failed asserting that SSH2 is connected after public key fetch.'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertNotEmpty(
|
|
|
|
$ssh->getServerIdentification(),
|
|
|
|
'Failed asserting that the server identifier was set after connect.'
|
|
|
|
);
|
|
|
|
|
|
|
|
return $ssh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 18:07:17 +02:00
|
|
|
* @depends testPreLogin
|
|
|
|
*/
|
2014-03-03 01:43:58 +01:00
|
|
|
public function testPasswordLogin($ssh)
|
|
|
|
{
|
|
|
|
$username = $this->getEnv('SSH_USERNAME');
|
|
|
|
$password = $this->getEnv('SSH_PASSWORD');
|
|
|
|
$this->assertTrue(
|
|
|
|
$ssh->login($username, $password),
|
|
|
|
'SSH2 login using password failed.'
|
|
|
|
);
|
2014-03-06 11:35:54 +01:00
|
|
|
|
|
|
|
return $ssh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 18:07:17 +02:00
|
|
|
* @depends testPasswordLogin
|
|
|
|
* @group github280
|
|
|
|
*/
|
2014-03-06 11:35:54 +01:00
|
|
|
public function testExecWithMethodCallback($ssh)
|
|
|
|
{
|
|
|
|
$callbackObject = $this->getMock('stdClass', array('callbackMethod'));
|
|
|
|
$callbackObject
|
|
|
|
->expects($this->atLeastOnce())
|
|
|
|
->method('callbackMethod')
|
|
|
|
->will($this->returnValue(true));
|
2014-04-07 17:58:49 +02:00
|
|
|
$ssh->exec('pwd', array($callbackObject, 'callbackMethod'));
|
2014-03-03 01:43:58 +01:00
|
|
|
}
|
2014-06-17 01:54:26 +02:00
|
|
|
|
|
|
|
public function testGetServerPublicHostKey()
|
|
|
|
{
|
|
|
|
$ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME'));
|
|
|
|
|
|
|
|
$this->assertInternalType('string', $ssh->getServerPublicHostKey());
|
|
|
|
}
|
2014-03-03 01:43:58 +01:00
|
|
|
}
|