2014-03-03 00:43:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Andreas Fischer <bantu@phpbb.com>
|
2014-12-09 23:02:44 +00:00
|
|
|
* @copyright 2014 Andreas Fischer
|
2014-03-03 00:43:58 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2014-12-10 01:31:41 +00:00
|
|
|
use phpseclib\Net\SSH2;
|
|
|
|
|
2014-06-01 19:13:20 +00:00
|
|
|
class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase
|
2014-03-03 00:43:58 +00:00
|
|
|
{
|
2014-03-04 13:56:42 +00:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
if (getenv('TRAVIS') && version_compare(PHP_VERSION, '5.3.3', '<=')) {
|
|
|
|
$this->markTestIncomplete(
|
|
|
|
'This test hangs on Travis CI on PHP 5.3.3 and below.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
2014-03-03 00:43:58 +00:00
|
|
|
public function testConstructor()
|
|
|
|
{
|
2014-12-10 01:31:41 +00:00
|
|
|
$ssh = new SSH2($this->getEnv('SSH_HOSTNAME'));
|
2014-03-03 00:43:58 +00:00
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
is_object($ssh),
|
|
|
|
'Could not construct NET_SSH2 object.'
|
|
|
|
);
|
|
|
|
|
|
|
|
return $ssh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testConstructor
|
2014-07-20 20:58:24 +00:00
|
|
|
* @group github408
|
|
|
|
* @group github412
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testPreLogin
|
2014-03-03 00:43:58 +00: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 10:35:54 +00:00
|
|
|
|
|
|
|
return $ssh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testPasswordLogin
|
2014-04-18 14:49:37 +00:00
|
|
|
* @group github280
|
2014-03-06 10:35:54 +00:00
|
|
|
*/
|
|
|
|
public function testExecWithMethodCallback($ssh)
|
|
|
|
{
|
|
|
|
$callbackObject = $this->getMock('stdClass', array('callbackMethod'));
|
|
|
|
$callbackObject
|
|
|
|
->expects($this->atLeastOnce())
|
|
|
|
->method('callbackMethod')
|
|
|
|
->will($this->returnValue(true));
|
2014-04-07 15:58:49 +00:00
|
|
|
$ssh->exec('pwd', array($callbackObject, 'callbackMethod'));
|
2014-03-03 00:43:58 +00:00
|
|
|
}
|
2014-06-16 23:54:26 +00:00
|
|
|
|
|
|
|
public function testGetServerPublicHostKey()
|
|
|
|
{
|
2014-12-10 01:31:41 +00:00
|
|
|
$ssh = new SSH2($this->getEnv('SSH_HOSTNAME'));
|
2014-06-16 23:54:26 +00:00
|
|
|
|
|
|
|
$this->assertInternalType('string', $ssh->getServerPublicHostKey());
|
|
|
|
}
|
2014-03-03 00:43:58 +00:00
|
|
|
}
|