Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/composer/dependencies-3c309bb971
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell authored Mar 25, 2024
2 parents ba6b163 + 6934108 commit a0f41f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/Command/Auth/AuthLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ 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)) {
if (is_array($keys) && !empty($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) {
Expand Down
29 changes: 27 additions & 2 deletions tests/phpunit/src/Commands/Auth/AuthLoginCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ public function testAuthLoginCommand(): void {
$this->assertKeySavedCorrectly();
}

public function testAuthLoginNoKeysCommand(): void {
$this->mockRequest('getAccount');
$this->clientServiceProphecy->setConnector(Argument::type(Connector::class))->shouldBeCalled();
$this->clientServiceProphecy->isMachineAuthenticated()->willReturn(FALSE);
$this->removeMockCloudConfigFile();
$this->fs->dumpFile($this->cloudConfigFilepath, json_encode(['send_telemetry' => FALSE]));
$this->createDataStores();
$this->command = $this->createCommand();

$this->executeCommand(['--key' => $this->key, '--secret' => $this->secret]);
$output = $this->getDisplay();

$this->assertStringContainsString('Saved credentials', $output);
$this->assertKeySavedCorrectly();
}

public function providerTestAuthLoginInvalidInputCommand(): Generator {
yield
[
Expand Down Expand Up @@ -72,9 +88,18 @@ public function testAuthLoginInvalidInputCommand(array $inputs, array $args): vo
public function testAuthLoginInvalidDatastore(): void {
$this->clientServiceProphecy->isMachineAuthenticated()->willReturn(FALSE);
$this->removeMockCloudConfigFile();
$data = [
'acli_key' => 'key2',
'keys' => [
'key1' => [
'label' => 'foo',
'secret' => 'foo',
'uuid' => 'foo',
],
],
];
$this->fs->dumpFile($this->cloudConfigFilepath, json_encode($data));
$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');
Expand Down

0 comments on commit a0f41f2

Please sign in to comment.