2014-12-09 23:27:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Andreas Fischer <bantu@phpbb.com>
|
|
|
|
* @copyright 2014 Andreas Fischer
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
*/
|
|
|
|
|
2022-06-04 15:31:21 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-02-23 02:48:51 +00:00
|
|
|
namespace phpseclib3\Tests\Functional\Net;
|
|
|
|
|
2019-11-07 05:41:40 +00:00
|
|
|
use phpseclib3\Net\SSH2;
|
|
|
|
use phpseclib3\System\SSH\Agent;
|
2022-02-23 02:48:51 +00:00
|
|
|
use phpseclib3\Tests\PhpseclibFunctionalTestCase;
|
2014-12-15 17:25:46 +00:00
|
|
|
|
2022-02-23 02:48:51 +00:00
|
|
|
class SSH2AgentTest extends PhpseclibFunctionalTestCase
|
2014-12-09 23:27:53 +00:00
|
|
|
{
|
2022-06-04 15:31:21 +00:00
|
|
|
public static function setUpBeforeClass(): void
|
2014-12-09 23:27:53 +00:00
|
|
|
{
|
|
|
|
if (!isset($_SERVER['SSH_AUTH_SOCK'])) {
|
|
|
|
self::markTestSkipped(
|
|
|
|
'This test requires an SSH Agent (SSH_AUTH_SOCK env variable).'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
parent::setUpBeforeClass();
|
|
|
|
}
|
|
|
|
|
2022-06-04 15:31:21 +00:00
|
|
|
public function testAgentLogin(): array
|
2014-12-09 23:27:53 +00:00
|
|
|
{
|
2014-12-12 18:20:33 +00:00
|
|
|
$ssh = new SSH2($this->getEnv('SSH_HOSTNAME'));
|
2022-02-17 02:25:59 +00:00
|
|
|
$agent = new Agent();
|
2014-12-09 23:27:53 +00:00
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
$ssh->login($this->getEnv('SSH_USERNAME'), $agent),
|
|
|
|
'SSH2 login using Agent failed.'
|
|
|
|
);
|
2014-12-30 02:44:31 +00:00
|
|
|
|
2017-11-27 08:30:14 +00:00
|
|
|
return ['ssh' => $ssh, 'ssh-agent' => $agent];
|
2014-12-30 02:44:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 09:13:33 +00:00
|
|
|
|
2014-12-30 02:44:31 +00:00
|
|
|
return $args;
|
2014-12-09 23:27:53 +00:00
|
|
|
}
|
|
|
|
}
|