Skip to content

Commit

Permalink
CLI-1290: [auth:login] php warning (#1702)
Browse files Browse the repository at this point in the history
* CLI-1290: [auth:login] php warning

* add note
  • Loading branch information
danepowell authored Mar 15, 2024
1 parent bda9ffa commit b3e3455
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit b3e3455

Please sign in to comment.