add support for pgsql_ssl

fixes #2
This commit is contained in:
Robin Appelman 2026-09-14 23:11:19 +02:00
commit 2af3ee0742
3 changed files with 82 additions and 3 deletions

View file

@ -2,6 +2,7 @@ use nextcloud_config_parser::{
parse, parse_glob, Config, Database, DbConnect, RedisClusterConnectionInfo, RedisConfig,
RedisConnectionAddr, RedisConnectionInfo, RedisTlsParams, SslOptions,
};
use sqlx::postgres::PgSslMode;
use std::fmt::Debug;
use indexmap::{indexmap, IndexMap};
@ -394,6 +395,47 @@ fn test_parse_postgres_socket_folder() {
);
}
#[test]
fn test_parse_postgres_ssl() {
let config = config_from_file("tests/configs/postgres_ssl.php");
assert_debug_equal(
&Database::Postgres {
database: "nextcloud".to_string(),
username: "redacted".to_string(),
password: "".to_string(),
connect: DbConnect::Tcp {
host: "1.2.3.4".into(),
port: 5432,
},
options: indexmap! {
"sslmode".into() => "require".into(),
"sslcert".into() => "/cert.crt".into(),
"sslrootcert".into() => "/root.crt".into(),
"sslkey".into() => "/key.pem".into(),
"sslcrl".into() => "/root.crl".into(),
},
},
&config.database,
);
assert_eq!(
config.database.url(),
"postgresql://redacted:@1.2.3.4/nextcloud?sslmode=require&sslcert=/cert.crt&sslrootcert=/root.crt&sslkey=/key.pem&sslcrl=/root.crl"
);
assert_debug_equal(
PgConnectOptions::new()
.host("1.2.3.4")
.port(5432)
.username("redacted")
.database("nextcloud")
.ssl_mode(PgSslMode::Require)
.ssl_client_cert("/cert.crt")
.ssl_root_cert("/root.crt")
.ssl_client_key("/key.pem"),
PgConnectOptions::from_str(&config.database.url()).unwrap(),
);
}
#[test]
fn test_parse_redis_cluster() {
let config = config_from_file("tests/configs/redis.cluster.php");
@ -644,7 +686,7 @@ fn test_parse_postgres_ip() {
.password("redacted")
.database("nextcloud")
.port(5432)
.ssl_mode(sqlx::postgres::PgSslMode::Disable),
.ssl_mode(PgSslMode::Disable),
PgConnectOptions::from_str(&config.database.url()).unwrap(),
);
}
@ -747,7 +789,7 @@ fn test_parse_postgres_escaped_credentials() {
.password("reda@cted")
.port(5432)
.database("nextcloud")
.ssl_mode(sqlx::postgres::PgSslMode::Disable),
.ssl_mode(PgSslMode::Disable),
PgConnectOptions::from_str(&config.database.url()).unwrap(),
);
}

View file

@ -0,0 +1,21 @@
<?php
$CONFIG = [
'overwrite.cli.url' => 'https://cloud.example.com',
'dbtype' => 'pgsql',
'dbname' => 'nextcloud',
'dbhost' => '1.2.3.4',
'dbport' => '',
'dbtableprefix' => 'oc_',
'dbuser' => 'redacted',
'pgsql_ssl' => [
'mode' => 'require',
'cert' => '/cert.crt',
'rootcert' => '/root.crt',
'key' => '/key.pem',
'crl' => '/root.crl',
],
'redis' => [
'host' => 'localhost'
]
];