Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (!\array_key_exists($name, $secrets)) {
$io->error(\sprintf('The secret "%s" does not exist.', $name));

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

return self::INVALID;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Secrets/AbstractVault.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ abstract public function reveal(string $name): ?string;

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

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

protected function validateName(string $name): void
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Secrets/DotenvVault.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public function list(bool $reveal = false): array

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public function testInvalidName()
$this->assertStringContainsString('The secret "undefinedKey" does not exist.', trim($tester->getDisplay(true)));
}

public function testFailedDecrypt()
{
$vault = $this->createMock(AbstractVault::class);
$vault->method('list')->willReturn(['secretKey' => null]);

$command = new SecretsRevealCommand($vault);

$tester = new CommandTester($command);
$this->assertSame(Command::INVALID, $tester->execute(['name' => 'secretKey']));

$this->assertStringContainsString('The secret "secretKey" could not be decrypted.', trim($tester->getDisplay(true)));
}

/**
* @backupGlobals enabled
*/
Expand Down
Loading