forked from deployphp/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented tests and fixed default timeout value to not soo huge (fixes
- Loading branch information
Showing
6 changed files
with
133 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/.idea/ | ||
/nbproject/ | ||
*.phar | ||
/.vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/* (c) Dmitry Balabka <dmitry.balabka@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use \Deployer\Helper\RecipeTester; | ||
|
||
class RemoteServerTest extends RecipeTester | ||
{ | ||
/** | ||
* @var \Deployer\Type\Result | ||
*/ | ||
private $result; | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
// Prepare FS | ||
self::$deployPath = __DIR__ . '/../../localhost'; | ||
self::cleanUp(); | ||
mkdir(self::$deployPath); | ||
self::$deployPath = realpath(self::$deployPath); | ||
} | ||
|
||
protected function setUpServer() | ||
{ | ||
$username = getenv('DEPLOYER_USERNAME') ?: 'deployer'; | ||
$password = getenv('DEPLOYER_PASSWORD') ?: 'deployer_password'; | ||
server('remote_auth_by_password', 'localhost', 22) | ||
->env('deploy_path', self::$deployPath) | ||
->user($username) | ||
->password($password); | ||
server('remote_auth_by_identity_file', 'localhost', 22) | ||
->env('deploy_path', self::$deployPath) | ||
->user($username) | ||
->identityFile(); | ||
server('remote_auth_by_pem_file', 'localhost', 22) | ||
->env('deploy_path', self::$deployPath) | ||
->user($username) | ||
->pemFile('~/.ssh/id_rsa.pem'); | ||
server('remote_auth_by_agent', 'localhost', 22) | ||
->env('deploy_path', self::$deployPath) | ||
->user($username) | ||
->forwardAgent(); | ||
} | ||
|
||
protected function loadRecipe() | ||
{ | ||
require __DIR__ . '/../../recipe/common.php'; | ||
|
||
task('deploy:timeout_test', function () { | ||
$this->result = run('sleep 11 && echo $SSH_CLIENT'); | ||
}); | ||
task('deploy:ssh_test', function () { | ||
$this->result = run('echo $SSH_CLIENT'); | ||
}); | ||
task('deploy:agent_test', function () { | ||
$this->result = run('ssh -T deployer@localhost \'echo $SSH_CLIENT\''); | ||
}); | ||
} | ||
|
||
public function testAuthByPassword() | ||
{ | ||
$this->exec('deploy:ssh_test', ['stage' => 'remote_auth_by_password']); | ||
$this->assertRegExp('#^127\.0\.0\.1#', $this->result->getOutput()); | ||
} | ||
|
||
public function testAuthByIdentityFile() | ||
{ | ||
$this->exec('deploy:ssh_test', ['stage' => 'remote_auth_by_identity_file']); | ||
$this->assertRegExp('#^127\.0\.0\.1#', $this->result->getOutput()); | ||
} | ||
|
||
public function testAuthByPemFile() | ||
{ | ||
$this->markTestIncomplete('Will be implemented later'); | ||
$this->exec('deploy:ssh_test', ['stage' => 'remote_auth_by_pem_file']); | ||
$this->assertRegExp('#^127\.0\.0\.1#', $this->result->getOutput()); | ||
} | ||
|
||
public function testAuthByAgent() | ||
{ | ||
$this->exec('deploy:agent_test', ['stage' => 'remote_auth_by_agent']); | ||
$this->assertRegExp('#^127\.0\.0\.1#', $this->result->getOutput()); | ||
} | ||
|
||
public function testTimeout() | ||
{ | ||
$this->exec('deploy:timeout_test', ['stage' => 'remote_auth_by_agent']); | ||
$this->assertRegExp('#^127\.0\.0\.1#', $this->result->getOutput()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
set -x | ||
|
||
export DEPLOYER_USERNAME='deployer' | ||
export DEPLOYER_PASSWORD='deployer_password' | ||
|
||
# Create deployer user and home directory | ||
useradd --create-home --base-dir /home "$DEPLOYER_USERNAME" | ||
|
||
# Set deployer user password | ||
echo "$DEPLOYER_USERNAME:$DEPLOYER_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 "" | ||
ssh-keygen -f "$HOME/.ssh/id_rsa.pub" -e -m pem > "$HOME/.ssh/id_rsa.pem" | ||
|
||
# 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 deployer user | ||
mkdir -p "/home/$DEPLOYER_USERNAME/.ssh/" | ||
cat "$HOME/.ssh/id_rsa.pub" >> "/home/$DEPLOYER_USERNAME/.ssh/authorized_keys" | ||
ssh-keyscan -t rsa localhost > "/tmp/known_hosts" | ||
cp "/tmp/known_hosts" "/home/$DEPLOYER_USERNAME/.ssh/known_hosts" | ||
chown "$DEPLOYER_USERNAME:$DEPLOYER_USERNAME" "/home/$DEPLOYER_USERNAME/.ssh/" -R |