Benjamin Gaussorgues
10 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
51 additions and
0 deletions
-
config/config.sample.php
-
lib/private/DB/ConnectionFactory.php
-
tests/lib/DB/ConnectionFactoryTest.php
|
|
|
@ -2118,6 +2118,17 @@ $CONFIG = [ |
|
|
|
*/ |
|
|
|
'mysql.collation' => null, |
|
|
|
|
|
|
|
/** |
|
|
|
* PostgreSQL SSL connection |
|
|
|
*/ |
|
|
|
'pgsql_ssl' => [ |
|
|
|
'mode' => '', |
|
|
|
'cert' => '', |
|
|
|
'rootcert' => '', |
|
|
|
'key' => '', |
|
|
|
'crl' => '', |
|
|
|
], |
|
|
|
|
|
|
|
/** |
|
|
|
* Database types supported for installation. |
|
|
|
* |
|
|
|
|
|
|
|
@ -198,6 +198,17 @@ class ConnectionFactory { |
|
|
|
'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', |
|
|
|
|
|
|
|
@ -40,4 +40,33 @@ class ConnectionFactoryTest extends TestCase { |
|
|
|
|
|
|
|
$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']); |
|
|
|
} |
|
|
|
} |