Skip to content

Commit 43c8bde

Browse files
bug #50712 [FrameworkBundle] Fix secrets:list not displaying local vars (nicolas-grekas)
This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle] Fix secrets:list not displaying local vars | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - My patch in #50301 was not correct. Commits ------- a46c659 [FrameworkBundle] Fix secrets:list not displaying local vars
2 parents df2ae1e + a46c659 commit 43c8bde

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8686
}
8787

8888
foreach ($localSecrets ?? [] as $name => $value) {
89-
if (isset($rows[$name]) && !\in_array($value, ['', false, null], true)) {
89+
if (isset($rows[$name])) {
9090
$rows[$name][] = $dump($value);
9191
}
9292
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ public function reveal(string $name): ?string
5252
{
5353
$this->lastMessage = null;
5454
$this->validateName($name);
55-
$v = \is_string($_SERVER[$name] ?? null) && !str_starts_with($name, 'HTTP_') ? $_SERVER[$name] : ($_ENV[$name] ?? null);
55+
$v = $_ENV[$name] ?? (str_starts_with($name, 'HTTP_') ? null : ($_SERVER[$name] ?? null));
5656

57-
if (null === $v) {
57+
if ('' === ($v ?? '')) {
5858
$this->lastMessage = sprintf('Secret "%s" not found in "%s".', $name, $this->getPrettyPath($this->dotenvFile));
5959

6060
return null;
@@ -89,13 +89,13 @@ public function list(bool $reveal = false): array
8989
$secrets = [];
9090

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

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

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\FrameworkBundle\Command\SecretsListCommand;
1616
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
17+
use Symfony\Bundle\FrameworkBundle\Secrets\DotenvVault;
1718
use Symfony\Component\Console\Tester\CommandTester;
1819

1920
class SecretsListCommandTest extends TestCase
2021
{
22+
/**
23+
* @backupGlobals enabled
24+
*/
2125
public function testExecute()
2226
{
2327
$vault = $this->createMock(AbstractVault::class);
2428
$vault->method('list')->willReturn(['A' => 'a', 'B' => 'b', 'C' => null, 'D' => null, 'E' => null]);
25-
$localVault = $this->createMock(AbstractVault::class);
26-
$localVault->method('list')->willReturn(['A' => '', 'B' => 'A', 'C' => '', 'D' => false, 'E' => null]);
29+
30+
$_ENV = ['A' => '', 'B' => 'A', 'C' => '', 'D' => false, 'E' => null];
31+
$localVault = new DotenvVault('/not/a/path');
32+
2733
$command = new SecretsListCommand($vault, $localVault);
2834
$tester = new CommandTester($command);
2935
$this->assertSame(0, $tester->execute([]));
@@ -37,9 +43,9 @@ public function testExecute()
3743
Secret Value Local Value
3844
-------- -------- -------------
3945
A "a"
40-
B "b" "A"
46+
B "b" ******
4147
C ******
42-
D ******
48+
D ****** ******
4349
E ******
4450
-------- -------- -------------
4551

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