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.
[deployphp#2197] Added testcases for running commands with sudo
Added two testcases for e2e tests, that verify: * that sudo command can be ran with password provided interactively * that sudo command can be ran with password passed via argument To allow for these tests to happen, the Dockerfile for server service had to be modified - the deployer user will require a password, when running command with sudo.
- Loading branch information
Bartlomiej Sacharski
committed
Oct 18, 2020
1 parent
1c610d1
commit ffb9772
Showing
7 changed files
with
68 additions
and
9 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
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,49 @@ | ||
<?php declare(strict_types=1); | ||
namespace e2e; | ||
|
||
class MiscE2ETest extends AbstractE2ETest | ||
{ | ||
private const RECIPE = __DIR__ . '/recipe/misc.php'; | ||
|
||
/** | ||
* @group e2e | ||
*/ | ||
public function testSudoWithPasswordEnteredInteractively(): void | ||
{ | ||
$this->init(self::RECIPE); | ||
|
||
// We're adding this to inputs, to have it passed with via the STDIN | ||
$this->tester->setInputs(['deployer']); | ||
|
||
$this->tester->run([ | ||
'test:misc:sudo-write-user', | ||
'-f' => self::RECIPE, | ||
'selector' => 'all', | ||
], [ 'decorated' => false ]); | ||
|
||
$display = trim($this->tester->getDisplay()); | ||
|
||
self::assertEquals(0, $this->tester->getStatusCode(), $display); | ||
self::assertStringContainsString('Current user is: root', $display); | ||
} | ||
|
||
/** | ||
* @group e2e | ||
*/ | ||
public function testSudoWithPasswordProvidedViaArgument(): void | ||
{ | ||
$this->init(self::RECIPE); | ||
|
||
$this->tester->run([ | ||
'test:misc:sudo-write-user', | ||
'-f' => self::RECIPE, | ||
'-o' => [ 'sudo_pass=deployer' ], | ||
'selector' => 'all', | ||
], [ 'decorated' => false ]); | ||
|
||
$display = trim($this->tester->getDisplay()); | ||
|
||
self::assertEquals(0, $this->tester->getStatusCode(), $display); | ||
self::assertStringContainsString('Current user is: root', $display); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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,12 @@ | ||
<?php declare(strict_types=1); | ||
namespace Deployer; | ||
|
||
// we need to user require instead of require_once, as the hosts HAVE to be loaded multiple times | ||
require __DIR__ . '/deploy.php'; | ||
|
||
task('test:misc:sudo-write-user', function (): void { | ||
$cmd = 'sudo bash -c \'echo Current user is: $USER\''; | ||
$output = run($cmd); | ||
writeln($output); | ||
})->shallow(); | ||
|