Replace custom logging with tracing crate and RUST_LOG env var
- Remove custom logging module and init_logging function - Update main.rs to use tracing_subscriber with EnvFilter - Remove log_level from global config structure - Update documentation and tests to use RUST_LOG - Format long lines in config.rs and test files for better readability
This commit is contained in:
parent
50a4d9bc75
commit
55fe47b172
15 changed files with 787 additions and 459 deletions
|
|
@ -17,12 +17,19 @@ fn test_single_host_config() {
|
|||
|
||||
let cert_result = Command::new("openssl")
|
||||
.args(&[
|
||||
"req", "-x509", "-newkey", "rsa:2048",
|
||||
"-keyout", &key_path.to_string_lossy(),
|
||||
"-out", &cert_path.to_string_lossy(),
|
||||
"-days", "1",
|
||||
"req",
|
||||
"-x509",
|
||||
"-newkey",
|
||||
"rsa:2048",
|
||||
"-keyout",
|
||||
&key_path.to_string_lossy(),
|
||||
"-out",
|
||||
&cert_path.to_string_lossy(),
|
||||
"-days",
|
||||
"1",
|
||||
"-nodes",
|
||||
"-subj", "/CN=example.com"
|
||||
"-subj",
|
||||
"/CN=example.com",
|
||||
])
|
||||
.output();
|
||||
|
||||
|
|
@ -30,7 +37,8 @@ fn test_single_host_config() {
|
|||
panic!("Failed to generate test certificates for config test");
|
||||
}
|
||||
|
||||
let config_content = format!(r#"
|
||||
let config_content = format!(
|
||||
r#"
|
||||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
|
||||
|
|
@ -38,7 +46,12 @@ port = {}
|
|||
root = "{}"
|
||||
cert = "{}"
|
||||
key = "{}"
|
||||
"#, port, content_dir.display(), cert_path.display(), key_path.display());
|
||||
"#,
|
||||
port,
|
||||
content_dir.display(),
|
||||
cert_path.display(),
|
||||
key_path.display()
|
||||
);
|
||||
std::fs::write(&config_path, config_content).unwrap();
|
||||
|
||||
let mut server_process = std::process::Command::new(env!("CARGO_BIN_EXE_pollux"))
|
||||
|
|
@ -48,7 +61,10 @@ key = "{}"
|
|||
.unwrap();
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
assert!(server_process.try_wait().unwrap().is_none(), "Server should start with valid single host config");
|
||||
assert!(
|
||||
server_process.try_wait().unwrap().is_none(),
|
||||
"Server should start with valid single host config"
|
||||
);
|
||||
server_process.kill().unwrap();
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +72,8 @@ key = "{}"
|
|||
fn test_multiple_hosts_config() {
|
||||
let temp_dir = common::setup_test_environment();
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
let config_content = format!(r#"
|
||||
let config_content = format!(
|
||||
r#"
|
||||
[site1.com]
|
||||
root = "{}"
|
||||
cert = "{}"
|
||||
|
|
@ -69,12 +86,14 @@ key = "{}"
|
|||
|
||||
bind_host = "127.0.0.1"
|
||||
port = 1965
|
||||
"#, temp_dir.path().join("site1").display(),
|
||||
temp_dir.path().join("site1_cert.pem").display(),
|
||||
temp_dir.path().join("site1_key.pem").display(),
|
||||
temp_dir.path().join("site2").display(),
|
||||
temp_dir.path().join("site2_cert.pem").display(),
|
||||
temp_dir.path().join("site2_key.pem").display());
|
||||
"#,
|
||||
temp_dir.path().join("site1").display(),
|
||||
temp_dir.path().join("site1_cert.pem").display(),
|
||||
temp_dir.path().join("site1_key.pem").display(),
|
||||
temp_dir.path().join("site2").display(),
|
||||
temp_dir.path().join("site2_cert.pem").display(),
|
||||
temp_dir.path().join("site2_key.pem").display()
|
||||
);
|
||||
std::fs::write(&config_path, config_content).unwrap();
|
||||
|
||||
// Create additional directories and generate certificates
|
||||
|
|
@ -87,24 +106,38 @@ port = 1965
|
|||
// Site 1 certificate
|
||||
let cert_result1 = Command::new("openssl")
|
||||
.args(&[
|
||||
"req", "-x509", "-newkey", "rsa:2048",
|
||||
"-keyout", &temp_dir.path().join("site1_key.pem").to_string_lossy(),
|
||||
"-out", &temp_dir.path().join("site1_cert.pem").to_string_lossy(),
|
||||
"-days", "1",
|
||||
"req",
|
||||
"-x509",
|
||||
"-newkey",
|
||||
"rsa:2048",
|
||||
"-keyout",
|
||||
&temp_dir.path().join("site1_key.pem").to_string_lossy(),
|
||||
"-out",
|
||||
&temp_dir.path().join("site1_cert.pem").to_string_lossy(),
|
||||
"-days",
|
||||
"1",
|
||||
"-nodes",
|
||||
"-subj", "/CN=site1.com"
|
||||
"-subj",
|
||||
"/CN=site1.com",
|
||||
])
|
||||
.output();
|
||||
|
||||
// Site 2 certificate
|
||||
let cert_result2 = Command::new("openssl")
|
||||
.args(&[
|
||||
"req", "-x509", "-newkey", "rsa:2048",
|
||||
"-keyout", &temp_dir.path().join("site2_key.pem").to_string_lossy(),
|
||||
"-out", &temp_dir.path().join("site2_cert.pem").to_string_lossy(),
|
||||
"-days", "1",
|
||||
"req",
|
||||
"-x509",
|
||||
"-newkey",
|
||||
"rsa:2048",
|
||||
"-keyout",
|
||||
&temp_dir.path().join("site2_key.pem").to_string_lossy(),
|
||||
"-out",
|
||||
&temp_dir.path().join("site2_cert.pem").to_string_lossy(),
|
||||
"-days",
|
||||
"1",
|
||||
"-nodes",
|
||||
"-subj", "/CN=site2.org"
|
||||
"-subj",
|
||||
"/CN=site2.org",
|
||||
])
|
||||
.output();
|
||||
|
||||
|
|
@ -114,7 +147,8 @@ port = 1965
|
|||
|
||||
// Test server starts successfully with multiple host config
|
||||
let port = 1968 + (std::process::id() % 1000) as u16;
|
||||
let config_content = format!(r#"
|
||||
let config_content = format!(
|
||||
r#"
|
||||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
|
||||
|
|
@ -128,13 +162,14 @@ root = "{}"
|
|||
cert = "{}"
|
||||
key = "{}"
|
||||
"#,
|
||||
port,
|
||||
temp_dir.path().join("site1").display(),
|
||||
temp_dir.path().join("site1_cert.pem").display(),
|
||||
temp_dir.path().join("site1_key.pem").display(),
|
||||
temp_dir.path().join("site2").display(),
|
||||
temp_dir.path().join("site2_cert.pem").display(),
|
||||
temp_dir.path().join("site2_key.pem").display());
|
||||
port,
|
||||
temp_dir.path().join("site1").display(),
|
||||
temp_dir.path().join("site1_cert.pem").display(),
|
||||
temp_dir.path().join("site1_key.pem").display(),
|
||||
temp_dir.path().join("site2").display(),
|
||||
temp_dir.path().join("site2_cert.pem").display(),
|
||||
temp_dir.path().join("site2_key.pem").display()
|
||||
);
|
||||
std::fs::write(&config_path, config_content).unwrap();
|
||||
|
||||
let mut server_process = std::process::Command::new(env!("CARGO_BIN_EXE_pollux"))
|
||||
|
|
@ -144,7 +179,10 @@ key = "{}"
|
|||
.unwrap();
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
assert!(server_process.try_wait().unwrap().is_none(), "Server should start with valid multiple host config");
|
||||
assert!(
|
||||
server_process.try_wait().unwrap().is_none(),
|
||||
"Server should start with valid multiple host config"
|
||||
);
|
||||
server_process.kill().unwrap();
|
||||
}
|
||||
|
||||
|
|
@ -177,14 +215,17 @@ root = "/tmp/content"
|
|||
fn test_invalid_hostname_config() {
|
||||
let temp_dir = common::setup_test_environment();
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
let config_content = format!(r#"
|
||||
let config_content = format!(
|
||||
r#"
|
||||
["invalid"]
|
||||
root = "{}"
|
||||
cert = "{}"
|
||||
key = "{}"
|
||||
"#, temp_dir.path().join("content").display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display());
|
||||
"#,
|
||||
temp_dir.path().join("content").display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display()
|
||||
);
|
||||
std::fs::write(&config_path, config_content).unwrap();
|
||||
|
||||
let output = std::process::Command::new(env!("CARGO_BIN_EXE_pollux"))
|
||||
|
|
@ -224,7 +265,8 @@ port = 1965
|
|||
fn test_duplicate_hostname_config() {
|
||||
let temp_dir = common::setup_test_environment();
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
let config_content = format!(r#"
|
||||
let config_content = format!(
|
||||
r#"
|
||||
[example.com]
|
||||
root = "{}"
|
||||
cert = "{}"
|
||||
|
|
@ -234,12 +276,14 @@ key = "{}"
|
|||
root = "{}"
|
||||
cert = "{}"
|
||||
key = "{}"
|
||||
"#, temp_dir.path().join("path1").display(),
|
||||
temp_dir.path().join("cert1.pem").display(),
|
||||
temp_dir.path().join("key1.pem").display(),
|
||||
temp_dir.path().join("path2").display(),
|
||||
temp_dir.path().join("cert2.pem").display(),
|
||||
temp_dir.path().join("key2.pem").display());
|
||||
"#,
|
||||
temp_dir.path().join("path1").display(),
|
||||
temp_dir.path().join("cert1.pem").display(),
|
||||
temp_dir.path().join("key1.pem").display(),
|
||||
temp_dir.path().join("path2").display(),
|
||||
temp_dir.path().join("cert2.pem").display(),
|
||||
temp_dir.path().join("key2.pem").display()
|
||||
);
|
||||
std::fs::write(&config_path, config_content).unwrap();
|
||||
|
||||
// Create the directories and certs
|
||||
|
|
@ -266,7 +310,8 @@ fn test_host_with_port_override() {
|
|||
let config_path = temp_dir.path().join("config.toml");
|
||||
// Test server starts successfully
|
||||
let port = 1969 + (std::process::id() % 1000) as u16;
|
||||
let config_content = format!(r#"
|
||||
let config_content = format!(
|
||||
r#"
|
||||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
|
||||
|
|
@ -275,10 +320,12 @@ root = "{}"
|
|||
cert = "{}"
|
||||
key = "{}"
|
||||
port = 1970 # Override global port
|
||||
"#, port,
|
||||
temp_dir.path().join("content").display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display());
|
||||
"#,
|
||||
port,
|
||||
temp_dir.path().join("content").display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display()
|
||||
);
|
||||
std::fs::write(&config_path, config_content).unwrap();
|
||||
|
||||
let mut server_process = std::process::Command::new(env!("CARGO_BIN_EXE_pollux"))
|
||||
|
|
@ -288,7 +335,10 @@ port = 1970 # Override global port
|
|||
.unwrap();
|
||||
|
||||
std::thread::sleep(std::time::Duration::from_millis(500));
|
||||
assert!(server_process.try_wait().unwrap().is_none(), "Server should start with host port override");
|
||||
assert!(
|
||||
server_process.try_wait().unwrap().is_none(),
|
||||
"Server should start with host port override"
|
||||
);
|
||||
server_process.kill().unwrap();
|
||||
}
|
||||
|
||||
|
|
@ -303,4 +353,4 @@ fn test_config_file_not_found() {
|
|||
assert!(!output.status.success());
|
||||
let stderr = String::from_utf8(output.stderr).unwrap();
|
||||
assert!(stderr.contains("Config file 'nonexistent.toml' not found"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue