Skip to content

Commit

Permalink
CLI-1334: TypeError in auth:login (#1739)
Browse files Browse the repository at this point in the history
* CLI-1334: TypeError in auth:login

* fix tests
  • Loading branch information
danepowell authored May 17, 2024
1 parent e2b4f21 commit 1ef1800
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 30 deletions.
4 changes: 0 additions & 4 deletions src/Command/Auth/AuthLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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 @@ -26,9 +25,6 @@ protected function configure(): void {
protected function execute(InputInterface $input, OutputInterface $output): int {
$keys = $this->datastoreCloud->get('keys');
$activeKey = $this->datastoreCloud->get('acli_key');
if (is_array($keys) && !empty($keys) && !array_key_exists($activeKey, $keys)) {
throw new AcquiaCliException('Invalid key in datastore at {filepath}', ['filepath' => $this->datastoreCloud->filepath]);
}
if ($activeKey) {
$activeKeyLabel = $keys[$activeKey]['label'];
$output->writeln("The following Cloud Platform API key is active: <options=bold>$activeKeyLabel</>");
Expand Down
3 changes: 0 additions & 3 deletions src/Command/Auth/AuthLogoutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ protected function configure(): void {
protected function execute(InputInterface $input, OutputInterface $output): int {
$keys = $this->datastoreCloud->get('keys');
$activeKey = $this->datastoreCloud->get('acli_key');
if (is_array($keys) && !empty($keys) && !array_key_exists($activeKey, $keys)) {
throw new AcquiaCliException('Invalid key in datastore at {filepath}', ['filepath' => $this->datastoreCloud->filepath]);
}
if (!$activeKey) {
throw new AcquiaCliException('There is no active Cloud Platform API key');
}
Expand Down
9 changes: 7 additions & 2 deletions src/Config/CloudDataConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getConfigTreeBuilder(): TreeBuilder {
->children()
->scalarNode('label')->end()
->scalarNode('uuid')->end()
->scalarNode('secret')->end()
->scalarNode('secret')->isRequired()->end()
->end()
->end()
->end()
Expand Down Expand Up @@ -68,7 +68,12 @@ public function getConfigTreeBuilder(): TreeBuilder {

->scalarNode('acsf_active_factory')->end()

->end();
->end()
->validate()
->ifTrue(function ($config) {
return is_array($config['keys']) && !empty($config['keys']) && !array_key_exists($config['acli_key'], $config['keys']);
})
->thenInvalid('acli_key must exist in keys');
return $treeBuilder;
}

Expand Down
4 changes: 3 additions & 1 deletion src/DataStore/Datastore.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ protected function processConfig(array $config, ConfigurationInterface $definiti
);
}
catch (InvalidConfigurationException $e) {
throw new AcquiaCliException("Configuration file at the following path contains invalid keys: $path. {$e->getMessage()}");
throw new AcquiaCliException(
'Configuration file at the following path contains invalid keys: {path} {error}',
['path' => $path, 'error' => $e->getMessage()]);
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ public function onConsoleError(ConsoleErrorEvent $event): void {
case 'Could not extract aliases to {destination}':
$this->helpMessages[] = 'Check that you have write access to the directory';
break;
case 'Invalid key in datastore at {filepath}':
$this->helpMessages[] = 'Delete the datastore and run this command again.';
break;
}
}

Expand Down
6 changes: 2 additions & 4 deletions tests/phpunit/src/Commands/Auth/AuthLoginCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@ public function testAuthLoginInvalidDatastore(): void {
],
];
$this->fs->dumpFile($this->cloudConfigFilepath, json_encode($data));
$this->createDataStores();
$this->command = $this->createCommand();
$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage("Invalid key in datastore at $this->cloudConfigFilepath");
$this->executeCommand();
$this->expectExceptionMessage("Configuration file at the following path contains invalid keys: $this->cloudConfigFilepath Invalid configuration for path \"cloud_api\": acli_key must exist in keys");
$this->createDataStores();
}

protected function assertInteractivePrompts(string $output): void {
Expand Down
11 changes: 2 additions & 9 deletions tests/phpunit/src/Commands/Auth/AuthLogoutCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Acquia\Cli\Command\Auth\AuthLogoutCommand;
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;

Expand All @@ -24,9 +22,6 @@ public function testAuthLogoutCommand(): void {
$this->executeCommand();
$output = $this->getDisplay();
$this->assertFileExists($this->cloudConfigFilepath);
$config = new CloudDataStore($this->localMachineHelper, new CloudDataConfig(), $this->cloudConfigFilepath);
$this->assertFalse($config->exists('acli_key'));
$this->assertNotEmpty($config->get('keys'));
$this->assertStringContainsString('The key Test Key will be deactivated on this machine.', $output);
$this->assertStringContainsString('Do you want to delete the active Cloud Platform API credentials (option --delete)? (yes/no) [no]:', $output);
$this->assertStringContainsString('The active Cloud Platform API credentials were deactivated', $output);
Expand All @@ -46,11 +41,9 @@ public function testAuthLogoutInvalidDatastore(): void {
],
];
$this->fs->dumpFile($this->cloudConfigFilepath, json_encode($data));
$this->createDataStores();
$this->command = $this->createCommand();
$this->expectException(AcquiaCliException::class);
$this->expectExceptionMessage("Invalid key in datastore at $this->cloudConfigFilepath");
$this->executeCommand();
$this->expectExceptionMessage("Configuration file at the following path contains invalid keys: $this->cloudConfigFilepath Invalid configuration for path \"cloud_api\": acli_key must exist in keys");
$this->createDataStores();
}

}
4 changes: 0 additions & 4 deletions tests/phpunit/src/Misc/ExceptionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ public function providerTestHelp(): array {
new AcquiaCliException('Could not extract aliases to {destination}'),
'Check that you have write access to the directory',
],
[
new AcquiaCliException('Invalid key in datastore at {filepath}'),
'Delete the datastore and run this command again.',
],
[
new ApiErrorException((object) ['error' => '', 'message' => "There are no available Cloud IDEs for this application.\n"]),
'Delete an existing IDE via <bg=blue;fg=white;options=bold>acli ide:delete</> or contact your Account Manager or Acquia Sales to purchase additional IDEs.',
Expand Down

0 comments on commit 1ef1800

Please sign in to comment.