Skip to content

Commit 30f2aa3

Browse files
authored
Merge pull request #255 from open-runtimes/fix-storage-dsn-trace-redaction
fix: keep the storage connection out of refusals
2 parents febd2db + a2373d6 commit 30f2aa3

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎src/Executor/StorageFactory.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class StorageFactory
2929
*
3030
* @throws InvalidArgumentException When the connection string cannot be parsed or names a scheme with no device
3131
*/
32-
public static function getDevice(string $root, ?string $connection = '', (ClientInterface&StreamingClientInterface)|null $client = null): Device
32+
public static function getDevice(string $root, #[\SensitiveParameter] ?string $connection = '', (ClientInterface&StreamingClientInterface)|null $client = null): Device
3333
{
3434
$connection ??= '';
3535
$localSchemes = ['file', DeviceType::Local->value];
@@ -40,8 +40,8 @@ public static function getDevice(string $root, ?string $connection = '', (Client
4040

4141
try {
4242
$dsn = new DSN($connection);
43-
} catch (\Throwable $throwable) {
44-
throw new InvalidArgumentException('Unable to parse storage DSN: ' . $throwable->getMessage(), previous: $throwable);
43+
} catch (\Throwable) {
44+
throw new InvalidArgumentException('Unable to parse storage DSN');
4545
}
4646

4747
$scheme = $dsn->getScheme();

‎tests/unit/Executor/StorageFactoryTest.php‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,28 @@ public function testUnusableConnectionIsRefused(string $connection): void
200200
StorageFactory::getDevice('/storage/builds/app-test', $connection);
201201
}
202202

203+
public function testRefusalDoesNotPrintTheConnection(): void
204+
{
205+
$ignoreArgs = \ini_set('zend.exception_ignore_args', '0');
206+
$maxLength = \ini_set('zend.exception_string_param_max_len', '1000000');
207+
208+
try {
209+
foreach (self::unusableConnections() as $name => [$connection]) {
210+
try {
211+
StorageFactory::getDevice('/storage/builds/app-test', $connection);
212+
$this->fail(sprintf("Connection '%s' was accepted", $name));
213+
} catch (InvalidArgumentException $exception) {
214+
$printed = (string) $exception;
215+
$this->assertStringContainsString('/storage/builds/app-test', $printed, $name);
216+
$this->assertStringNotContainsString($connection, $printed, $name);
217+
}
218+
}
219+
} finally {
220+
\ini_set('zend.exception_ignore_args', $ignoreArgs);
221+
\ini_set('zend.exception_string_param_max_len', $maxLength);
222+
}
223+
}
224+
203225
/**
204226
* @return \Iterator<string, array{(string | null)}>
205227
*/

0 commit comments

Comments
 (0)