add test for credentials escaping

This commit is contained in:
Robin Appelman 2024-01-23 15:08:58 +01:00
commit ffc38e3ae1
2 changed files with 49 additions and 0 deletions

View file

@ -562,3 +562,37 @@ fn test_parse_config_nested_array() {
&config.database, &config.database,
); );
} }
#[test]
fn test_parse_postgres_escaped_credentials() {
let config = config_from_file("tests/configs/postgres_escape.php");
assert_debug_equal(
&Database::Postgres {
database: "nextcloud".to_string(),
username: "reda:cted".to_string(),
password: "reda@cted".to_string(),
connect: DbConnect::Tcp {
host: "1.2.3.4".to_string(),
port: 5432,
},
ssl_options: SslOptions::Disabled,
},
&config.database,
);
assert_eq!(
config.database.url(),
"postgresql://reda%3Acted:reda%40cted@1.2.3.4/nextcloud?sslmode=disable"
);
#[cfg(feature = "db-sqlx")]
assert_debug_equal(
PgConnectOptions::new()
.host("1.2.3.4")
.username("reda:cted")
.password("reda@cted")
.port(5432)
.database("nextcloud")
.ssl_mode(sqlx::postgres::PgSslMode::Disable),
PgConnectOptions::from_str(&config.database.url()).unwrap(),
);
}

View file

@ -0,0 +1,15 @@
<?php
$CONFIG = [
'overwrite.cli.url' => 'https://cloud.example.com',
'dbtype' => 'pgsql',
'dbname' => 'nextcloud',
'dbhost' => '1.2.3.4',
'dbport' => '',
'dbtableprefix' => 'oc_',
'dbuser' => 'reda:cted',
'dbpassword' => 'reda@cted',
'redis' => [
'host' => 'localhost'
]
];