From 85610455824665b644fb91742aaa88df2be91219 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 11 May 2023 17:48:53 +0200 Subject: [PATCH] [FrameworkBundle] Ignore vars from dotenv files in secrets:list --- .../Command/SecretsListCommand.php | 2 +- .../Tests/Command/SecretsListCommandTest.php | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Command/SecretsListCommandTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/SecretsListCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/SecretsListCommand.php index 8422d2c91a023..abfe2064f8222 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/SecretsListCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/SecretsListCommand.php @@ -86,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } foreach ($localSecrets ?? [] as $name => $value) { - if (isset($rows[$name])) { + if (isset($rows[$name]) && !\in_array($value, ['', false, null], true)) { $rows[$name][] = $dump($value); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/SecretsListCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/SecretsListCommandTest.php new file mode 100644 index 0000000000000..933cafcf7c74c --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/SecretsListCommandTest.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Command; + +use PHPUnit\Framework\TestCase; +use Symfony\Bundle\FrameworkBundle\Command\SecretsListCommand; +use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault; +use Symfony\Component\Console\Tester\CommandTester; + +class SecretsListCommandTest extends TestCase +{ + public function testExecute() + { + $vault = $this->createMock(AbstractVault::class); + $vault->method('list')->willReturn(['A' => 'a', 'B' => 'b', 'C' => null, 'D' => null, 'E' => null]); + $localVault = $this->createMock(AbstractVault::class); + $localVault->method('list')->willReturn(['A' => '', 'B' => 'A', 'C' => '', 'D' => false, 'E' => null]); + $command = new SecretsListCommand($vault, $localVault); + $tester = new CommandTester($command); + $this->assertSame(0, $tester->execute([])); + + $expectedOutput = <<)%%" to reference a secret in a config file. + + // To reveal the secrets run %s secrets:list --reveal + + -------- -------- ------------- + Secret Value Local Value + -------- -------- ------------- + A "a" + B "b" "A" + C ****** + D ****** + E ****** + -------- -------- ------------- + + // Local values override secret values. + // Use secrets:set --local to define them. + EOTXT; + $this->assertStringMatchesFormat($expectedOutput, trim(preg_replace('/ ++$/m', '', $tester->getDisplay(true)), "\n")); + } +} 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