diff --git a/src/Command/Auth/AuthAcsfLoginCommand.php b/src/Command/Auth/AuthAcsfLoginCommand.php index 04772ad7b..9f32ab102 100644 --- a/src/Command/Auth/AuthAcsfLoginCommand.php +++ b/src/Command/Auth/AuthAcsfLoginCommand.php @@ -29,6 +29,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getOption('factory-url')) { $factoryUrl = $input->getOption('factory-url'); + self::validateUrl($factoryUrl); } elseif ($input->isInteractive() && $this->datastoreCloud->get('acsf_factories')) { $factories = $this->datastoreCloud->get('acsf_factories'); $factoryChoices = $factories; diff --git a/tests/phpunit/src/Commands/Acsf/AcsfAuthLoginCommandTest.php b/tests/phpunit/src/Commands/Acsf/AcsfAuthLoginCommandTest.php index 050f6ae81..f34948c90 100644 --- a/tests/phpunit/src/Commands/Acsf/AcsfAuthLoginCommandTest.php +++ b/tests/phpunit/src/Commands/Acsf/AcsfAuthLoginCommandTest.php @@ -9,6 +9,7 @@ use Acquia\Cli\Command\CommandBase; use Acquia\Cli\Config\CloudDataConfig; use Acquia\Cli\DataStore\CloudDataStore; +use Symfony\Component\Validator\Exception\ValidatorException; /** * @property \Acquia\Cli\Command\Auth\AuthLoginCommand $command @@ -117,6 +118,39 @@ public function testAcsfAuthLoginCommand(bool $machineIsAuthenticated, array $in $this->assertEquals(self::$acsfCurrentFactoryUrl, $this->cloudCredentials->getBaseUri()); } + /** + * @return string[][] + */ + public static function providerTestAcsfAuthLoginInvalid(): array + { + return [ + [ + ['--factory-url' => 'example.com', '--key' => 'asdfasdfasdf','--username' => 'asdf'], + 'This value is not a valid URL.', + ], + [ + ['--factory-url' => 'https://example.com', '--key' => 'asdf','--username' => 'asdf'], + 'This value is too short. It should have 10 characters or more.', + ], + ]; + } + + /** + * @dataProvider providerTestAcsfAuthLoginInvalid + * @throws \Exception + */ + public function testAcsfAuthLoginInvalid(array $args, string $message): void + { + $this->clientServiceProphecy->isMachineAuthenticated() + ->willReturn(false); + $this->removeMockCloudConfigFile(); + $this->createDataStores(); + $this->command = $this->createCommand(); + $this->expectException(ValidatorException::class); + $this->expectExceptionMessage($message); + $this->executeCommand($args); + } + protected function assertKeySavedCorrectly(): void { $credsFile = $this->cloudConfigFilepath;