Skip to content

Commit dc05cb2

Browse files
bug #60774 [FrameworkBundle] Fixes getting a type error when the secret you are trying to reveal could not be decrypted (jack-worman)
This PR was submitted for the 7.4 branch but it was merged into the 7.2 branch instead. Discussion ---------- [FrameworkBundle] Fixes getting a type error when the secret you are trying to reveal could not be decrypted | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Fixes getting a type error when the secret you are trying to reveal could not be decrypted. ```txt In SymfonyStyle.php line 322: Symfony\Component\Console\Style\SymfonyStyle::writeln(): Argument #1 ($messages) must be of type Traversable|array|string, null given, called in /Users/jworman/PhpstormProjects/gtx/vendor/symfony/framework-bundle/Command/Sec retsRevealCommand.php on line 67 ``` Not sure if this is considered a bug fix or a new feature Commits ------- 480e7d1 Fix-type-error-when-revealing-broken-secret
2 parents ec77126 + 480e7d1 commit dc05cb2

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/SecretsRevealCommand.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6161
if (!\array_key_exists($name, $secrets)) {
6262
$io->error(\sprintf('The secret "%s" does not exist.', $name));
6363

64+
return self::INVALID;
65+
} elseif (null === $secrets[$name]) {
66+
$io->error(\sprintf('The secret "%s" could not be decrypted.', $name));
67+
6468
return self::INVALID;
6569
}
6670

src/Symfony/Bundle/FrameworkBundle/Secrets/AbstractVault.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ abstract public function reveal(string $name): ?string;
3131

3232
abstract public function remove(string $name): bool;
3333

34+
/**
35+
* @return array<string, string|null>
36+
*/
3437
abstract public function list(bool $reveal = false): array;
3538

3639
protected function validateName(string $name): void

src/Symfony/Bundle/FrameworkBundle/Secrets/DotenvVault.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ public function list(bool $reveal = false): array
8989

9090
foreach ($_ENV as $k => $v) {
9191
if ('' !== ($v ?? '') && preg_match('/^\w+$/D', $k)) {
92-
$secrets[$k] = $reveal ? $v : null;
92+
$secrets[$k] = \is_string($v) && $reveal ? $v : null;
9393
}
9494
}
9595

9696
foreach ($_SERVER as $k => $v) {
9797
if ('' !== ($v ?? '') && preg_match('/^\w+$/D', $k)) {
98-
$secrets[$k] = $reveal ? $v : null;
98+
$secrets[$k] = \is_string($v) && $reveal ? $v : null;
9999
}
100100
}
101101

src/Symfony/Bundle/FrameworkBundle/Tests/Command/SecretsRevealCommandTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ public function testInvalidName()
4646
$this->assertStringContainsString('The secret "undefinedKey" does not exist.', trim($tester->getDisplay(true)));
4747
}
4848

49+
public function testFailedDecrypt()
50+
{
51+
$vault = $this->createMock(AbstractVault::class);
52+
$vault->method('list')->willReturn(['secretKey' => null]);
53+
54+
$command = new SecretsRevealCommand($vault);
55+
56+
$tester = new CommandTester($command);
57+
$this->assertSame(Command::INVALID, $tester->execute(['name' => 'secretKey']));
58+
59+
$this->assertStringContainsString('The secret "secretKey" could not be decrypted.', trim($tester->getDisplay(true)));
60+
}
61+
4962
/**
5063
* @backupGlobals enabled
5164
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy