diff --git a/src/Executor/StorageFactory.php b/src/Executor/StorageFactory.php index aa9392e..edfa567 100644 --- a/src/Executor/StorageFactory.php +++ b/src/Executor/StorageFactory.php @@ -29,7 +29,7 @@ class StorageFactory * * @throws InvalidArgumentException When the connection string cannot be parsed or names a scheme with no device */ - public static function getDevice(string $root, ?string $connection = '', (ClientInterface&StreamingClientInterface)|null $client = null): Device + public static function getDevice(string $root, #[\SensitiveParameter] ?string $connection = '', (ClientInterface&StreamingClientInterface)|null $client = null): Device { $connection ??= ''; $localSchemes = ['file', DeviceType::Local->value]; @@ -40,8 +40,8 @@ public static function getDevice(string $root, ?string $connection = '', (Client try { $dsn = new DSN($connection); - } catch (\Throwable $throwable) { - throw new InvalidArgumentException('Unable to parse storage DSN: ' . $throwable->getMessage(), previous: $throwable); + } catch (\Throwable) { + throw new InvalidArgumentException('Unable to parse storage DSN'); } $scheme = $dsn->getScheme(); diff --git a/tests/unit/Executor/StorageFactoryTest.php b/tests/unit/Executor/StorageFactoryTest.php index f644e55..21659cd 100644 --- a/tests/unit/Executor/StorageFactoryTest.php +++ b/tests/unit/Executor/StorageFactoryTest.php @@ -200,6 +200,28 @@ public function testUnusableConnectionIsRefused(string $connection): void StorageFactory::getDevice('/storage/builds/app-test', $connection); } + public function testRefusalDoesNotPrintTheConnection(): void + { + $ignoreArgs = \ini_set('zend.exception_ignore_args', '0'); + $maxLength = \ini_set('zend.exception_string_param_max_len', '1000000'); + + try { + foreach (self::unusableConnections() as $name => [$connection]) { + try { + StorageFactory::getDevice('/storage/builds/app-test', $connection); + $this->fail(sprintf("Connection '%s' was accepted", $name)); + } catch (InvalidArgumentException $exception) { + $printed = (string) $exception; + $this->assertStringContainsString('/storage/builds/app-test', $printed, $name); + $this->assertStringNotContainsString($connection, $printed, $name); + } + } + } finally { + \ini_set('zend.exception_ignore_args', $ignoreArgs); + \ini_set('zend.exception_string_param_max_len', $maxLength); + } + } + /** * @return \Iterator */