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
|
|
@ -71,7 +71,8 @@ fn test_virtual_host_routing_multiple_hosts() {
|
|||
|
||||
// Create config with two hosts
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
let content = format!(r#"
|
||||
let content = format!(
|
||||
r#"
|
||||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
|
||||
|
|
@ -85,20 +86,29 @@ root = "{}"
|
|||
cert = "{}"
|
||||
key = "{}"
|
||||
"#,
|
||||
port,
|
||||
temp_dir.path().join("site1").display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display(),
|
||||
temp_dir.path().join("site2").display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display());
|
||||
port,
|
||||
temp_dir.path().join("site1").display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display(),
|
||||
temp_dir.path().join("site2").display(),
|
||||
temp_dir.path().join("cert.pem").display(),
|
||||
temp_dir.path().join("key.pem").display()
|
||||
);
|
||||
std::fs::write(&config_path, content).unwrap();
|
||||
|
||||
// Create host-specific content
|
||||
std::fs::create_dir_all(temp_dir.path().join("site1")).unwrap();
|
||||
std::fs::create_dir_all(temp_dir.path().join("site2")).unwrap();
|
||||
std::fs::write(temp_dir.path().join("site1").join("index.gmi"), "# Site 1 Content\n").unwrap();
|
||||
std::fs::write(temp_dir.path().join("site2").join("index.gmi"), "# Site 2 Content\n").unwrap();
|
||||
std::fs::write(
|
||||
temp_dir.path().join("site1").join("index.gmi"),
|
||||
"# Site 1 Content\n",
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(
|
||||
temp_dir.path().join("site2").join("index.gmi"),
|
||||
"# Site 2 Content\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Use the same certs for both hosts (server uses first cert anyway)
|
||||
|
||||
|
|
@ -114,11 +124,19 @@ key = "{}"
|
|||
|
||||
// Test request to site1.com with TLS
|
||||
let response1 = make_gemini_request("127.0.0.1", port, "gemini://site1.com/index.gmi");
|
||||
assert!(response1.starts_with("20"), "Expected success response for site1.com, got: {}", response1);
|
||||
assert!(
|
||||
response1.starts_with("20"),
|
||||
"Expected success response for site1.com, got: {}",
|
||||
response1
|
||||
);
|
||||
|
||||
// Test request to site2.org
|
||||
let response2 = make_gemini_request("127.0.0.1", port, "gemini://site2.org/index.gmi");
|
||||
assert!(response2.starts_with("20"), "Expected success response for site2.org, got: {}", response2);
|
||||
assert!(
|
||||
response2.starts_with("20"),
|
||||
"Expected success response for site2.org, got: {}",
|
||||
response2
|
||||
);
|
||||
|
||||
server_process.kill().unwrap();
|
||||
}
|
||||
|
|
@ -132,7 +150,8 @@ fn test_virtual_host_routing_known_hostname() {
|
|||
|
||||
// Config with only one host
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
let content = format!(r#"
|
||||
let content = format!(
|
||||
r#"
|
||||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
|
||||
|
|
@ -141,10 +160,11 @@ root = "{}"
|
|||
cert = "{}"
|
||||
key = "{}"
|
||||
"#,
|
||||
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, content).unwrap();
|
||||
|
||||
// Start server with TLS
|
||||
|
|
@ -159,7 +179,11 @@ key = "{}"
|
|||
|
||||
// Test request to unknown hostname
|
||||
let response = make_gemini_request("127.0.0.1", port, "gemini://unknown.com/index.gmi");
|
||||
assert!(response.starts_with("53"), "Should return status 53 for unknown hostname, got: {}", response);
|
||||
assert!(
|
||||
response.starts_with("53"),
|
||||
"Should return status 53 for unknown hostname, got: {}",
|
||||
response
|
||||
);
|
||||
|
||||
server_process.kill().unwrap();
|
||||
}
|
||||
|
|
@ -173,7 +197,8 @@ fn test_virtual_host_routing_malformed_url() {
|
|||
|
||||
// Config with one host
|
||||
let config_path = temp_dir.path().join("config.toml");
|
||||
let content = format!(r#"
|
||||
let content = format!(
|
||||
r#"
|
||||
bind_host = "127.0.0.1"
|
||||
port = {}
|
||||
|
||||
|
|
@ -182,10 +207,11 @@ root = "{}"
|
|||
cert = "{}"
|
||||
key = "{}"
|
||||
"#,
|
||||
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, content).unwrap();
|
||||
|
||||
// Start server with TLS
|
||||
|
|
@ -200,7 +226,11 @@ key = "{}"
|
|||
|
||||
// Test malformed URL (wrong protocol)
|
||||
let response = make_gemini_request("127.0.0.1", port, "http://example.com/index.gmi");
|
||||
assert!(response.starts_with("59"), "Should return status 59 for malformed URL, got: {}", response);
|
||||
assert!(
|
||||
response.starts_with("59"),
|
||||
"Should return status 59 for malformed URL, got: {}",
|
||||
response
|
||||
);
|
||||
|
||||
server_process.kill().unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue