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-1296: auth:login on 2.23.1 > Invalid key in Cloud datastore fixed #1710

Merged
merged 3 commits into from
Mar 25, 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
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