Skip to content

Commit eb6a111

Browse files
bug #50301 [FrameworkBundle] Ignore vars from dotenv files in secrets:list (nicolas-grekas)
This PR was merged into the 6.3 branch. Discussion ---------- [FrameworkBundle] Ignore vars from dotenv files in secrets:list | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Sidekick of #48705 Commits ------- 8561045 [FrameworkBundle] Ignore vars from dotenv files in secrets:list
2 parents e3a816d + 8561045 commit eb6a111

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
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])) {
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)
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