From 00c19f4cc1410c41d6364c643530cf57eaf12f9e Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Mon, 3 Mar 2014 01:43:58 +0100 Subject: [PATCH] Add basic SSH2 functional test as an example. --- .travis.yml | 1 + tests/Net/SSH2FunctionalTest.php | 35 ++++++++++++++++++++++++++++++++ travis/run-phpunit.sh | 4 ++++ travis/setup-secure-shell.sh | 17 ++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 tests/Net/SSH2FunctionalTest.php create mode 100755 travis/setup-secure-shell.sh diff --git a/.travis.yml b/.travis.yml index aacbd919..16cf99fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ env: - secure: "jtQTZKQBnzUlp/jz7NlM6470ZDnLGVAs53sgvIm4tcYqf9TWSXSXjIYvFsrS\nKPR2eyZaAevYysUkIGRFTUXTlG6tC36YngMp9+6FPxASl8mnGXsTbKcm613B\n59vD3242pgIgqhhmgFQ0c8gbvnE8PuF2aS4/hluP3r+AxhWN56E=" before_script: + - 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.5' ]; then composer install --dev --no-interaction; fi" diff --git a/tests/Net/SSH2FunctionalTest.php b/tests/Net/SSH2FunctionalTest.php new file mode 100644 index 00000000..40bfeea3 --- /dev/null +++ b/tests/Net/SSH2FunctionalTest.php @@ -0,0 +1,35 @@ + + * @copyright MMXIV Andreas Fischer + * @license http://www.opensource.org/licenses/mit-license.html MIT License + */ + +class Net_SSH2FunctionalTest extends PhpseclibFunctionalTestCase +{ + public function testConstructor() + { + $ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME')); + + $this->assertTrue( + is_object($ssh), + 'Could not construct NET_SSH2 object.' + ); + + return $ssh; + } + + /** + * @depends testConstructor + */ + 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.' + ); + } +} diff --git a/travis/run-phpunit.sh b/travis/run-phpunit.sh index a448774a..35b16aee 100755 --- a/travis/run-phpunit.sh +++ b/travis/run-phpunit.sh @@ -2,6 +2,10 @@ set -e set -x +export PHPSECLIB_SSH_HOSTNAME='localhost' +export PHPSECLIB_SSH_USERNAME='phpseclib' +export PHPSECLIB_SSH_PASSWORD='EePoov8po1aethu2kied1ne0' + phpunit \ --verbose \ --coverage-text \ diff --git a/travis/setup-secure-shell.sh b/travis/setup-secure-shell.sh new file mode 100755 index 00000000..ad8d3504 --- /dev/null +++ b/travis/setup-secure-shell.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# +# This file is part of the phpseclib project. +# +# (c) Andreas Fischer +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. +# +set -e +set -x + +USERNAME='phpseclib' +PASSWORD='EePoov8po1aethu2kied1ne0' + +sudo useradd "$USERNAME" +echo "$USERNAME:$PASSWORD" | sudo chpasswd