Skip to content

Commit 4d22b4c

Browse files
[FrameworkBundle] Ignore vars from dotenv files in secrets:list
1 parent 5c2072b commit 4d22b4c

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

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])) {
89+
if (isset($rows[$name]) && !\in_array($value, ['', false, null], true)) {
9090
$rows[$name][] = $dump($value);
9191
}
9292
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\FrameworkBundle\Command\SecretsListCommand;
16+
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
17+
use Symfony\Component\Console\Tester\CommandTester;
18+
19+
class SecretsListCommandTest extends TestCase
20+
{
21+
public function testExecute()
22+
{
23+
$vault = $this->createMock(AbstractVault::class);
24+
$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]);
27+
$command = new SecretsListCommand($vault, $localVault);
28+
$tester = new CommandTester($command);
29+
$this->assertSame(0, $tester->execute([]));
30+
31+
$expectedOutput = <<<EOTXT
32+
// Use "%%env(<name>)%%" to reference a secret in a config file.
33+
34+
// To reveal the secrets run %s secrets:list --reveal
35+
36+
-------- -------- -------------
37+
Secret Value Local Value
38+
-------- -------- -------------
39+
A "a"
40+
B "b" "A"
41+
C ******
42+
D ******
43+
E ******
44+
-------- -------- -------------
45+
46+
// Local values override secret values.
47+
// Use secrets:set --local to define them.
48+
EOTXT;
49+
$this->assertStringMatchesFormat($expectedOutput, trim(preg_replace('/ ++$/m', '', $tester->getDisplay(true)), "\n"));
50+
}
51+
}

0 commit comments

Comments
 (0)