parse redis ssl_context

This commit is contained in:
Robin Appelman 2025-04-29 18:13:10 +02:00
commit e4bb72fd00
6 changed files with 220 additions and 14 deletions

View file

@ -1,6 +1,6 @@
use nextcloud_config_parser::{
parse, parse_glob, Config, Database, DbConnect, RedisConfig, RedisConnectionAddr,
RedisConnectionInfo, SslOptions,
RedisConnectionInfo, RedisTlsParams, SslOptions,
};
use std::fmt::Debug;
@ -25,15 +25,9 @@ fn parse_redis(cfg: &str) -> RedisConnectionInfo {
let redis = ConnectionInfo::from_str(cfg).unwrap();
let addr = match redis.addr {
ConnectionAddr::Tcp(host, port) => RedisConnectionAddr::Tcp { host, port },
ConnectionAddr::TcpTls {
ConnectionAddr::TcpTls { host, port, .. } => RedisConnectionAddr::TcpTls {
host,
port,
insecure,
..
} => RedisConnectionAddr::TcpTls {
host,
port,
insecure,
tls_params: None,
},
ConnectionAddr::Unix(path) => RedisConnectionAddr::Unix { path },
@ -109,6 +103,30 @@ fn test_parse_redis_socket() {
);
}
#[test]
fn test_parse_redis_tls() {
let config = config_from_file("tests/configs/redis_tls.php");
assert_debug_equal(
RedisConfig::Single(RedisConnectionInfo {
addr: RedisConnectionAddr::TcpTls {
host: "127.0.0.1".into(),
port: 6379,
tls_params: Some(RedisTlsParams {
local_cert: Some("/certs/redis.crt".into()),
local_pk: Some("/certs/redis.key".into()),
ca_file: Some("/certs/ca.crt".into()),
insecure: false,
accept_invalid_hostname: false,
}),
},
db: 0,
username: None,
password: None,
}),
config.redis,
);
}
#[test]
fn test_parse_comment_whitespace() {
let config = config_from_file("tests/configs/comment_whitespace.php");

View file

@ -0,0 +1,19 @@
<?php
$CONFIG = [
'overwrite.cli.url' => 'https://cloud.example.com',
'dbtype' => 'mysql',
'dbname' => 'nextcloud',
'dbhost' => 'localhost',
'dbport' => '',
'dbuser' => 'nextcloud',
'dbpassword' => 'secret',
'redis' => [
'host' => 'localhost',
'ssl_context' => [
'local_cert' => '/certs/redis.crt',
'local_pk' => '/certs/redis.key',
'cafile' => '/certs/ca.crt'
]
]
];