Skip to content

Commit

Permalink
Merge pull request #233 from acelaya-forks/feature/db-encryption-option
Browse files Browse the repository at this point in the history
Add config option for DB_USE_ENCRYPTION
  • Loading branch information
acelaya authored Dec 20, 2024
2 parents 957db97 + eb5450a commit 3675f6d
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
## [Unreleased]
### Added
* Add config option for `REDIRECT_EXTRA_PATH_MODE`
* Add config option for `DB_USE_ENCRYPTION`

### Changed
* *Nothing*
Expand Down
2 changes: 2 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
'Database > Password' => Config\Option\Database\DatabasePasswordConfigOption::class,
'Database > Unix socket (Mysql/MariaDB)'
=> Config\Option\Database\DatabaseUnixSocketConfigOption::class,
'Database > Use encryption' => Config\Option\Database\DatabaseUseEncryptionConfigOption::class,
],
'URL SHORTENER' => [
'URL shortener > Short domain' => Config\Option\UrlShortener\ShortDomainHostConfigOption::class,
Expand Down Expand Up @@ -143,6 +144,7 @@
Config\Option\Database\DatabaseUserConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabasePasswordConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseUnixSocketConfigOption::class => InvokableFactory::class,
Config\Option\Database\DatabaseUseEncryptionConfigOption::class => InvokableFactory::class,
Config\Option\Redirect\BaseUrlRedirectConfigOption::class => InvokableFactory::class,
Config\Option\Redirect\InvalidShortUrlRedirectConfigOption::class => InvokableFactory::class,
Config\Option\Redirect\Regular404RedirectConfigOption::class => InvokableFactory::class,
Expand Down
24 changes: 24 additions & 0 deletions src/Config/Option/Database/DatabaseUseEncryptionConfigOption.php
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,
);
}
}
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);
}
}

0 comments on commit 3675f6d

Please sign in to comment.