2014-12-10 00:27:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Andreas Fischer <bantu@phpbb.com>
|
|
|
|
* @copyright 2014 Andreas Fischer
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2014-12-12 19:20:33 +01:00
|
|
|
use phpseclib\Net\SSH2;
|
2014-12-15 23:33:25 +01:00
|
|
|
use phpseclib\System\SSH\Agent;
|
2014-12-15 18:25:46 +01:00
|
|
|
|
2014-12-10 00:27:53 +01:00
|
|
|
class Functional_Net_SSH2AgentTest extends PhpseclibFunctionalTestCase
|
|
|
|
{
|
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
|
|
|
if (!isset($_SERVER['SSH_AUTH_SOCK'])) {
|
|
|
|
self::markTestSkipped(
|
|
|
|
'This test requires an SSH Agent (SSH_AUTH_SOCK env variable).'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
parent::setUpBeforeClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAgentLogin()
|
|
|
|
{
|
2014-12-12 19:20:33 +01:00
|
|
|
$ssh = new SSH2($this->getEnv('SSH_HOSTNAME'));
|
2014-12-15 23:33:25 +01:00
|
|
|
$agent = new Agent;
|
2014-12-10 00:27:53 +01:00
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
$ssh->login($this->getEnv('SSH_USERNAME'), $agent),
|
|
|
|
'SSH2 login using Agent failed.'
|
|
|
|
);
|
2014-12-30 03:44:31 +01:00
|
|
|
|
|
|
|
return array('ssh' => $ssh, 'ssh-agent' => $agent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testAgentLogin
|
|
|
|
*/
|
|
|
|
public function testAgentForward($args)
|
|
|
|
{
|
|
|
|
$ssh = $args['ssh'];
|
|
|
|
$agent = $args['ssh-agent'];
|
|
|
|
|
|
|
|
$hostname = $this->getEnv('SSH_HOSTNAME');
|
|
|
|
$username = $this->getEnv('SSH_USERNAME');
|
|
|
|
|
|
|
|
$this->assertEquals($username, trim($ssh->exec('whoami')));
|
|
|
|
|
|
|
|
$agent->startSSHForwarding($ssh);
|
|
|
|
$this->assertEquals($username, trim($ssh->exec("ssh " . $username . "@" . $hostname . ' \'whoami\'')));
|
2015-01-12 10:13:33 +01:00
|
|
|
|
2014-12-30 03:44:31 +01:00
|
|
|
return $args;
|
2014-12-10 00:27:53 +01:00
|
|
|
}
|
|
|
|
}
|