mirror of
https://codeberg.org/icewind/nextcloud-config-parser.git
synced 2026-06-03 08:34:13 +02:00
parent
59006e9e8e
commit
39e4ae9a2b
4 changed files with 46 additions and 3 deletions
|
|
@ -216,8 +216,12 @@ impl From<Database> for sqlx::any::AnyConnectOptions {
|
|||
} => {
|
||||
let mut options = PgConnectOptions::default()
|
||||
.database(&database)
|
||||
.username(&username)
|
||||
.password(&password);
|
||||
.username(&username);
|
||||
|
||||
if !password.is_empty() {
|
||||
options = options.password(&password);
|
||||
}
|
||||
|
||||
if matches!(ssl_options, SslOptions::Disabled) {
|
||||
options = options.ssl_mode(PgSslMode::Disable);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ fn parse_db_options(parsed: &Value) -> Result<Database> {
|
|||
}
|
||||
Some("pgsql") => {
|
||||
let username = parsed["dbuser"].as_str().ok_or(DbError::NoUsername)?;
|
||||
let password = parsed["dbpassword"].as_str().ok_or(DbError::NoPassword)?;
|
||||
let password = parsed["dbpassword"].as_str().unwrap_or_default();
|
||||
let (mut connect, disable_ssl) =
|
||||
match split_host(parsed["dbhost"].as_str().unwrap_or_default()) {
|
||||
(addr, None, None) => (
|
||||
|
|
|
|||
|
|
@ -177,6 +177,31 @@ fn test_parse_postgres_socket() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_postgres_socket_no_pass() {
|
||||
let config = config_from_file("tests/configs/postgres_socket_no_pass.php");
|
||||
assert_debug_equal(
|
||||
&Database::Postgres {
|
||||
database: "nextcloud".to_string(),
|
||||
username: "redacted".to_string(),
|
||||
password: "".to_string(),
|
||||
connect: DbConnect::Socket("/var/run/postgresql".into()),
|
||||
ssl_options: SslOptions::Default,
|
||||
},
|
||||
&config.database,
|
||||
);
|
||||
#[cfg(feature = "db-sqlx")]
|
||||
assert_debug_equal(
|
||||
AnyConnectOptions::from(
|
||||
PgConnectOptions::new()
|
||||
.socket("/var/run/postgresql")
|
||||
.username("redacted")
|
||||
.database("nextcloud"),
|
||||
),
|
||||
config.database.into(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_postgres_socket_folder() {
|
||||
let config = config_from_file("tests/configs/postgres_socket_folder.php");
|
||||
|
|
|
|||
14
tests/configs/postgres_socket_no_pass.php
Normal file
14
tests/configs/postgres_socket_no_pass.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
$CONFIG = [
|
||||
'overwrite.cli.url' => 'https://cloud.example.com',
|
||||
'dbtype' => 'pgsql',
|
||||
'dbname' => 'nextcloud',
|
||||
'dbhost' => 'localhost:/var/run/postgresql/.s.PGSQL.5432',
|
||||
'dbport' => '',
|
||||
'dbtableprefix' => 'oc_',
|
||||
'dbuser' => 'redacted',
|
||||
'redis' => [
|
||||
'host' => 'localhost'
|
||||
]
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue