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
11 changes: 11 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,17 @@
*/
'mysql.collation' => null,

/**
* PostgreSQL SSL connection
*/
'pgsql_ssl' => [
'mode' => '',
'cert' => '',
'rootcert' => '',
'key' => '',
'crl' => '',
],

/**
* Database types that are supported for installation.
*
Expand Down
11 changes: 11 additions & 0 deletions lib/private/DB/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,17 @@ public function createConnectionParams(string $configPrefix = '', array $additio
'tablePrefix' => $connectionParams['tablePrefix']
];

if ($type === 'pgsql') {
$pgsqlSsl = $this->config->getValue('pgsql_ssl', false);
if (is_array($pgsqlSsl)) {
$connectionParams['sslmode'] = $pgsqlSsl['mode'] ?? '';
$connectionParams['sslrootcert'] = $pgsqlSsl['rootcert'] ?? '';
$connectionParams['sslcert'] = $pgsqlSsl['cert'] ?? '';
$connectionParams['sslkey'] = $pgsqlSsl['key'] ?? '';
$connectionParams['sslcrl'] = $pgsqlSsl['crl'] ?? '';
}
}

if ($type === 'mysql' && $this->config->getValue('mysql.utf8mb4', false)) {
$connectionParams['defaultTableOptions'] = [
'collate' => 'utf8mb4_bin',
Expand Down
29 changes: 29 additions & 0 deletions tests/lib/DB/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,33 @@ public function testSplitHostFromPortAndSocket($host, array $expected): void {

$this->assertEquals($expected, self::invokePrivate($factory, 'splitHostFromPortAndSocket', [$host]));
}

public function testPgsqlSslConnection(): void {
/** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject $config */
$config = $this->createMock(SystemConfig::class);
$config->method('getValue')
->willReturnCallback(function ($key, $default) {
return match ($key) {
'dbtype' => 'pgsql',
'pgsql_ssl' => [
'mode' => 'verify-full',
'cert' => 'client.crt',
'key' => 'client.key',
'crl' => 'client.crl',
'rootcert' => 'rootCA.crt',
],
default => $default,
};
});
$factory = new ConnectionFactory($config);

$params = $factory->createConnectionParams();

$this->assertEquals('pdo_pgsql', $params['driver']);
$this->assertEquals('verify-full', $params['sslmode']);
$this->assertEquals('rootCA.crt', $params['sslrootcert']);
$this->assertEquals('client.crt', $params['sslcert']);
$this->assertEquals('client.key', $params['sslkey']);
$this->assertEquals('client.crl', $params['sslcrl']);
}
}
Loading