Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions src/Command/Remote/SshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ final class SshCommand extends SshBaseCommand
protected function configure(): void
{
$this
->addArgument('alias', InputArgument::REQUIRED, 'Alias for application & environment in the format `app-name.env`')
->acceptEnvironmentId()
->addArgument('ssh_command', InputArgument::IS_ARRAY, 'Command to run via SSH (if not provided, opens a shell in the site directory)')
->addUsage("myapp.dev # open a shell in the myapp.dev environment")
->addUsage("myapp.dev -- ls -al # list files in the myapp.dev environment and return");
->addUsage("myapp.dev -- ls -al # list files in the myapp.dev environment and return")
->addUsage("12345-abcd1234-1111-2222-3333-0e02b2c3d470 -- ls -al");
}

protected function execute(InputInterface $input, OutputInterface $output): ?int
{
$alias = $input->getArgument('alias');
$alias = $this->normalizeAlias($alias);
$alias = self::validateEnvironmentAlias($alias);
$environment = $this->getEnvironmentFromAliasArg($alias);
$environment = $this->determineEnvironment($input, $output, true);
$alias = self::getEnvironmentAlias($environment);
Comment on lines +33 to +34
if (!isset($environment->sshUrl)) {
throw new AcquiaCliException('Cannot determine environment SSH URL. Check that you have SSH permissions on this environment.');
}
Expand Down
76 changes: 64 additions & 12 deletions tests/phpunit/src/Commands/Remote/SshCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Command\Remote\SshCommand;
use Acquia\Cli\Command\Self\ClearCacheCommand;
use Acquia\Cli\Helpers\SshHelper;
use PHPUnit\Framework\Attributes\Group;
use Prophecy\Argument;

/**
Expand All @@ -21,11 +19,9 @@ protected function createCommand(): CommandBase
return $this->injectCommand(SshCommand::class);
}

#[Group('serial')]
public function testRemoteAliasesDownloadCommand(): void
public function testRemoteSshCommand(): void
{
ClearCacheCommand::clearCaches();
$this->mockForGetEnvironmentFromAliasArg();
$this->mockGetEnvironment();
[$process, $localMachineHelper] = $this->mockForExecuteCommand();
$localMachineHelper->checkRequiredBinariesExist(['ssh'])
->shouldBeCalled();
Expand All @@ -36,21 +32,77 @@ public function testRemoteAliasesDownloadCommand(): void
'-o StrictHostKeyChecking=accept-new',
'-o AddressFamily inet',
'-o LogLevel=ERROR',
'cd /var/www/html/devcloud2.dev; exec $SHELL -l',
'cd /var/www/html/site.dev; exec $SHELL -l',
];
$localMachineHelper
->execute($sshCommand, Argument::type('callable'), null, true, null, null)
->willReturn($process->reveal())
->shouldBeCalled();

$this->command->sshHelper = new SshHelper($this->output, $localMachineHelper->reveal(), $this->logger);
$this->executeCommand(['ssh_command' => []], self::inputChooseEnvironment());

$args = [
'alias' => 'devcloud2.dev',
$this->getDisplay();
}

public function testRemoteSshCommandAllowsProductionEnvironment(): void
{
$this->mockGetEnvironment();
[$process, $localMachineHelper] = $this->mockForExecuteCommand();
$localMachineHelper->checkRequiredBinariesExist(['ssh'])
->shouldBeCalled();
$sshCommand = [
'ssh',
'site.prod@siteprod.ssh.hosted.acquia-sites.com',
'-t',
'-o StrictHostKeyChecking=accept-new',
'-o AddressFamily inet',
'-o LogLevel=ERROR',
'cd /var/www/html/site.prod; exec $SHELL -l',
];
$this->executeCommand($args);
$localMachineHelper
->execute($sshCommand, Argument::type('callable'), null, true, null, null)
->willReturn($process->reveal())
->shouldBeCalled();

$this->command->sshHelper = new SshHelper($this->output, $localMachineHelper->reveal(), $this->logger);
$this->executeCommand(['ssh_command' => []], [
// Would you like Acquia CLI to search for a Cloud application that matches your local git config?
'n',
// Select a Cloud Platform application:
self::$INPUT_DEFAULT_CHOICE,
// Would you like to link the project at ... ?
'n',
// Choose a Cloud Platform environment (index 1 = prod):
1,
]);

$this->getDisplay();
}

public function testRemoteSshCommandWithEnvUuid(): void
{
$this->mockRequest('getEnvironment', '24-a47ac10b-58cc-4372-a567-0e02b2c3d470');
[$process, $localMachineHelper] = $this->mockForExecuteCommand();
$localMachineHelper->checkRequiredBinariesExist(['ssh'])
->shouldBeCalled();
$sshCommand = [
'ssh',
'site.dev@sitedev.ssh.hosted.acquia-sites.com',
'-t',
'-o StrictHostKeyChecking=accept-new',
'-o AddressFamily inet',
'-o LogLevel=ERROR',
'cd /var/www/html/site.dev; exec $SHELL -l',
];
$localMachineHelper
->execute($sshCommand, Argument::type('callable'), null, true, null, null)
->willReturn($process->reveal())
->shouldBeCalled();

$this->command->sshHelper = new SshHelper($this->output, $localMachineHelper->reveal(), $this->logger);
$this->executeCommand(['environmentId' => '24-a47ac10b-58cc-4372-a567-0e02b2c3d470']);

Comment on lines +83 to 105
// Assert.
$output = $this->getDisplay();
$this->getDisplay();
}
}
9 changes: 0 additions & 9 deletions tests/phpunit/src/Commands/Remote/SshCommandTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@

abstract class SshCommandTestBase extends CommandTestBase
{
protected function mockForGetEnvironmentFromAliasArg(): void
{
$applicationsResponse = $this->mockApplicationsRequest(1);
$this->mockEnvironmentsRequest($applicationsResponse);
$this->clientProphecy->addQuery('filter', 'hosting=@*:devcloud2')
->shouldBeCalled();
$this->mockRequest('getAccount');
}

/**
* @return array<mixed>
*/
Expand Down