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
|
|
@ -1,7 +1,5 @@
|
|||
mod common;
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_per_host_content_isolation() {
|
||||
let temp_dir = common::setup_test_environment();
|
||||
|
|
@ -19,7 +17,8 @@ fn test_per_host_content_isolation() {
|
|||
// Create config with two hosts
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
let port = 1965 + (std::process::id() % 1000) as u16; // Use dynamic port
|
||||
let config_content = format!(r#"
|
||||
let config_content = format!(
|
||||
r#"
|
||||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
|
||||
|
|
@ -33,13 +32,14 @@ root = "{}"
|
|||
cert = "{}"
|
||||
key = "{}"
|
||||
"#,
|
||||
port,
|
||||
site1_root.display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display(),
|
||||
site2_root.display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display());
|
||||
port,
|
||||
site1_root.display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display(),
|
||||
site2_root.display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display()
|
||||
);
|
||||
std::fs::write(&config_path, config_content).unwrap();
|
||||
|
||||
// Start server with TLS
|
||||
|
|
@ -54,13 +54,29 @@ key = "{}"
|
|||
|
||||
// Test site1.com serves its content
|
||||
let response1 = make_gemini_request("127.0.0.1", port, "gemini://site1.com/");
|
||||
assert!(response1.starts_with("20"), "Expected success for site1.com, got: {}", response1);
|
||||
assert!(response1.contains("Welcome to Site 1"), "Should serve site1 content, got: {}", response1);
|
||||
assert!(
|
||||
response1.starts_with("20"),
|
||||
"Expected success for site1.com, got: {}",
|
||||
response1
|
||||
);
|
||||
assert!(
|
||||
response1.contains("Welcome to Site 1"),
|
||||
"Should serve site1 content, got: {}",
|
||||
response1
|
||||
);
|
||||
|
||||
// Test site2.org serves its content
|
||||
let response2 = make_gemini_request("127.0.0.1", port, "gemini://site2.org/");
|
||||
assert!(response2.starts_with("20"), "Expected success for site2.org, got: {}", response2);
|
||||
assert!(response2.contains("Welcome to Site 2"), "Should serve site2 content, got: {}", response2);
|
||||
assert!(
|
||||
response2.starts_with("20"),
|
||||
"Expected success for site2.org, got: {}",
|
||||
response2
|
||||
);
|
||||
assert!(
|
||||
response2.contains("Welcome to Site 2"),
|
||||
"Should serve site2 content, got: {}",
|
||||
response2
|
||||
);
|
||||
|
||||
server_process.kill().unwrap();
|
||||
}
|
||||
|
|
@ -73,7 +89,11 @@ fn test_per_host_path_security() {
|
|||
let site1_root = temp_dir.path().join("site1");
|
||||
std::fs::create_dir(&site1_root).unwrap();
|
||||
std::fs::create_dir(site1_root.join("subdir")).unwrap();
|
||||
std::fs::write(site1_root.join("subdir").join("secret.gmi"), "Secret content").unwrap();
|
||||
std::fs::write(
|
||||
site1_root.join("subdir").join("secret.gmi"),
|
||||
"Secret content",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Create config
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
|
|
@ -81,7 +101,8 @@ fn test_per_host_path_security() {
|
|||
let cert_path = temp_dir.path().join("cert.pem");
|
||||
let key_path = temp_dir.path().join("key.pem");
|
||||
|
||||
let config_content = format!(r#"
|
||||
let config_content = format!(
|
||||
r#"
|
||||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
|
||||
|
|
@ -90,10 +111,11 @@ root = "{}"
|
|||
cert = "{}"
|
||||
key = "{}"
|
||||
"#,
|
||||
port,
|
||||
site1_root.display(),
|
||||
cert_path.display(),
|
||||
key_path.display());
|
||||
port,
|
||||
site1_root.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"))
|
||||
|
|
@ -106,12 +128,24 @@ key = "{}"
|
|||
|
||||
// Test path traversal attempt should be blocked
|
||||
let response = make_gemini_request("127.0.0.1", port, "gemini://site1.com/../../../etc/passwd");
|
||||
assert!(response.starts_with("51"), "Path traversal should be blocked, got: {}", response);
|
||||
assert!(
|
||||
response.starts_with("51"),
|
||||
"Path traversal should be blocked, got: {}",
|
||||
response
|
||||
);
|
||||
|
||||
// Test valid subdirectory access should work
|
||||
let response = make_gemini_request("127.0.0.1", port, "gemini://site1.com/subdir/secret.gmi");
|
||||
assert!(response.starts_with("20"), "Valid subdirectory access should work, got: {}", response);
|
||||
assert!(response.contains("Secret content"), "Should serve content from subdirectory, got: {}", response);
|
||||
assert!(
|
||||
response.starts_with("20"),
|
||||
"Valid subdirectory access should work, got: {}",
|
||||
response
|
||||
);
|
||||
assert!(
|
||||
response.contains("Secret content"),
|
||||
"Should serve content from subdirectory, got: {}",
|
||||
response
|
||||
);
|
||||
|
||||
server_process.kill().unwrap();
|
||||
}
|
||||
|
|
@ -128,4 +162,4 @@ fn make_gemini_request(host: &str, port: u16, url: &str) -> String {
|
|||
.output()
|
||||
.unwrap();
|
||||
String::from_utf8(output.stdout).unwrap()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue