Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI-1290: [auth:login] php warning #1702

Merged
merged 2 commits into from
Mar 15, 2024
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
5 changes: 5 additions & 0 deletions src/Command/Auth/AuthLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Acquia\Cli\Command\Auth;

use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Exception\AcquiaCliException;
use AcquiaCloudApi\Endpoints\Account;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand All @@ -25,6 +26,10 @@ protected function configure(): void {
protected function execute(InputInterface $input, OutputInterface $output): int {
$keys = $this->datastoreCloud->get('keys');
$activeKey = $this->datastoreCloud->get('acli_key');
// @todo this validation should really be enforced as a schema on the datastore.
if (is_array($keys) && !array_key_exists($activeKey, $keys)) {
throw new AcquiaCliException('Invalid key in Cloud datastore; run acli auth:logout && acli auth:login to fix');
}
if ($activeKey) {
$activeKeyLabel = $keys[$activeKey]['label'];
$output->writeln("The following Cloud Platform API key is active: <options=bold>$activeKeyLabel</>");
Expand Down
13 changes: 13 additions & 0 deletions tests/phpunit/src/Commands/Auth/AuthLoginCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Acquia\Cli\Command\CommandBase;
use Acquia\Cli\Config\CloudDataConfig;
use Acquia\Cli\DataStore\CloudDataStore;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Tests\CommandTestBase;
use AcquiaCloudApi\Connector\Connector;
use Generator;
Expand Down Expand Up @@ -68,6 +69,18 @@ public function testAuthLoginInvalidInputCommand(array $inputs, array $args): vo
$this->executeCommand($args, $inputs);
}

public function testAuthLoginInvalidDatastore(): void {
$this->clientServiceProphecy->isMachineAuthenticated()->willReturn(FALSE);
$this->removeMockCloudConfigFile();
$this->createDataStores();
$this->datastoreCloud->set('keys', ['key1']);
$this->datastoreCloud->set('acli_key', 'key2');
$this->command = $this->createCommand();
$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage('Invalid key in Cloud datastore; run acli auth:logout && acli auth:login to fix');
$this->executeCommand();
}

protected function assertInteractivePrompts(string $output): void {
// Your machine has already been authenticated with the Cloud Platform API, would you like to re-authenticate?
$this->assertStringContainsString('You will need a Cloud Platform API token from https://cloud.acquia.com/a/profile/tokens', $output);
Expand Down