mirror of
https://codeberg.org/icewind/nextcloud-config-parser.git
synced 2026-06-03 16:44:09 +02:00
fix handling of pgsql sockets without hostname
This commit is contained in:
parent
ffc38e3ae1
commit
9ebb0f08ac
3 changed files with 49 additions and 0 deletions
|
|
@ -284,6 +284,9 @@ fn parse_db_options(parsed: &Value) -> Result<Database> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn split_host(host: &str) -> (&str, Option<u16>, Option<&str>) {
|
fn split_host(host: &str) -> (&str, Option<u16>, Option<&str>) {
|
||||||
|
if host.starts_with('/') {
|
||||||
|
return ("localhost", None, Some(host));
|
||||||
|
}
|
||||||
let mut parts = host.split(':');
|
let mut parts = host.split(':');
|
||||||
let host = parts.next().unwrap();
|
let host = parts.next().unwrap();
|
||||||
match parts
|
match parts
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,37 @@ fn test_parse_postgres_socket() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_postgres_socket_empty_hostname() {
|
||||||
|
let config = config_from_file("tests/configs/postgres_socket_no_host.php");
|
||||||
|
assert_debug_equal(
|
||||||
|
&Database::Postgres {
|
||||||
|
database: "nextcloud".to_string(),
|
||||||
|
username: "nextcloud".to_string(),
|
||||||
|
password: "redacted".to_string(),
|
||||||
|
connect: DbConnect::Socket("/run/postgresql".into()),
|
||||||
|
ssl_options: SslOptions::Default,
|
||||||
|
},
|
||||||
|
&config.database,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
config.database.url(),
|
||||||
|
"postgresql://nextcloud:redacted@localhost/nextcloud?host=/run/postgresql"
|
||||||
|
);
|
||||||
|
|
||||||
|
#[cfg(feature = "db-sqlx")]
|
||||||
|
assert_debug_equal(
|
||||||
|
PgConnectOptions::new()
|
||||||
|
.socket("/run/postgresql")
|
||||||
|
.host("localhost")
|
||||||
|
.username("nextcloud")
|
||||||
|
.password("redacted")
|
||||||
|
.database("nextcloud"),
|
||||||
|
PgConnectOptions::from_str(&config.database.url()).unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_postgres_socket_no_pass() {
|
fn test_parse_postgres_socket_no_pass() {
|
||||||
let config = config_from_file("tests/configs/postgres_socket_no_pass.php");
|
let config = config_from_file("tests/configs/postgres_socket_no_pass.php");
|
||||||
|
|
|
||||||
15
tests/configs/postgres_socket_no_host.php
Normal file
15
tests/configs/postgres_socket_no_host.php
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$CONFIG = [
|
||||||
|
'overwrite.cli.url' => 'https://cloud.example.com',
|
||||||
|
'dbtype' => 'pgsql',
|
||||||
|
'dbname' => 'nextcloud',
|
||||||
|
'dbhost' => '/run/postgresql',
|
||||||
|
'dbport' => '',
|
||||||
|
'dbtableprefix' => 'oc_',
|
||||||
|
'dbuser' => 'nextcloud',
|
||||||
|
'dbpassword' => 'redacted',
|
||||||
|
'redis' => [
|
||||||
|
'host' => 'localhost'
|
||||||
|
]
|
||||||
|
];
|
||||||
Loading…
Add table
Add a link
Reference in a new issue