-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from acelaya-forks/feature/db-encryption-option
Add config option for DB_USE_ENCRYPTION
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Config/Option/Database/DatabaseUseEncryptionConfigOption.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shlinkio\Shlink\Installer\Config\Option\Database; | ||
|
||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class DatabaseUseEncryptionConfigOption extends AbstractNonSqliteDependentConfigOption | ||
{ | ||
public function getEnvVar(): string | ||
{ | ||
return 'DB_USE_ENCRYPTION'; | ||
} | ||
|
||
public function ask(StyleInterface $io, array $currentOptions): bool | ||
{ | ||
return $io->confirm( | ||
'Do you want the database connection to be encrypted? Enabling this will make database connections fail if ' | ||
. 'your database server does not support or enforce encryption.', | ||
default: false, | ||
); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
test/Config/Option/Database/DatabaseUseEncryptionConfigOptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ShlinkioTest\Shlink\Installer\Config\Option\Database; | ||
|
||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\Attributes\TestWith; | ||
use PHPUnit\Framework\TestCase; | ||
use Shlinkio\Shlink\Installer\Config\Option\Database\DatabaseUseEncryptionConfigOption; | ||
use Symfony\Component\Console\Style\StyleInterface; | ||
|
||
class DatabaseUseEncryptionConfigOptionTest extends TestCase | ||
{ | ||
private DatabaseUseEncryptionConfigOption $configOption; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->configOption = new DatabaseUseEncryptionConfigOption(); | ||
} | ||
|
||
#[Test] | ||
public function returnsExpectedEnvVar(): void | ||
{ | ||
self::assertEquals('DB_USE_ENCRYPTION', $this->configOption->getEnvVar()); | ||
} | ||
|
||
#[Test] | ||
#[TestWith([true])] | ||
#[TestWith([false])] | ||
public function expectedQuestionIsAsked(bool $expectedAnswer): void | ||
{ | ||
$io = $this->createMock(StyleInterface::class); | ||
$io->expects($this->once())->method('confirm')->with( | ||
'Do you want the database connection to be encrypted? Enabling this will make database connections fail if ' | ||
. 'your database server does not support or enforce encryption.', | ||
false, | ||
)->willReturn($expectedAnswer); | ||
|
||
$answer = $this->configOption->ask($io, []); | ||
|
||
self::assertEquals($expectedAnswer, $answer); | ||
} | ||
} |