mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-24 11:05:30 +00:00
Merge pull request #552 from bantu/ssh2-agent-login-test
SSH2 Agent Login Test * bantu/ssh2-agent-login-test: Setup SSH key and agent for travis user. Add a functional test case for SSH2 login using Agent.
This commit is contained in:
commit
6d42873b87
@ -20,6 +20,7 @@ env:
|
||||
before_install: true
|
||||
|
||||
install:
|
||||
- eval `ssh-agent -s`
|
||||
- travis/setup-secure-shell.sh
|
||||
- sh -c "if [ '$TRAVIS_PHP_VERSION' != 'hhvm' ]; then travis/install-php-extensions.sh; fi"
|
||||
- sh -c "if [ '$TRAVIS_PHP_VERSION' != '5.2' ]; then travis/setup-composer.sh; fi"
|
||||
|
31
tests/Functional/Net/SSH2AgentTest.php
Normal file
31
tests/Functional/Net/SSH2AgentTest.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Andreas Fischer <bantu@phpbb.com>
|
||||
* @copyright 2014 Andreas Fischer
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
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()
|
||||
{
|
||||
$ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME'));
|
||||
$agent = new System_SSH_Agent;
|
||||
|
||||
$this->assertTrue(
|
||||
$ssh->login($this->getEnv('SSH_USERNAME'), $agent),
|
||||
'SSH2 login using Agent failed.'
|
||||
);
|
||||
}
|
||||
}
|
@ -13,5 +13,19 @@ set -x
|
||||
USERNAME='phpseclib'
|
||||
PASSWORD='EePoov8po1aethu2kied1ne0'
|
||||
|
||||
# Create phpseclib user and home directory
|
||||
sudo useradd --create-home --base-dir /home "$USERNAME"
|
||||
|
||||
# Set phpseclib user password
|
||||
echo "$USERNAME:$PASSWORD" | sudo chpasswd
|
||||
|
||||
# Create a 1024 bit RSA SSH key pair without passphrase for the travis user
|
||||
ssh-keygen -t rsa -b 1024 -f "$HOME/.ssh/id_rsa" -q -N ""
|
||||
|
||||
# Add the generated private key to SSH agent of travis user
|
||||
ssh-add "$HOME/.ssh/id_rsa"
|
||||
|
||||
# Allow the private key of the travis user to log in as phpseclib user
|
||||
sudo mkdir -p "/home/$USERNAME/.ssh/"
|
||||
sudo cp "$HOME/.ssh/id_rsa.pub" "/home/$USERNAME/.ssh/authorized_keys"
|
||||
sudo chown "$USERNAME:$USERNAME" "/home/$USERNAME/.ssh/" -R
|
||||
|
Loading…
Reference in New Issue
Block a user