feat: Implement virtual hosting for multi-domain Gemini server
- Add hostname-based request routing for multiple capsules per server - Parse virtual host configs from TOML sections ([hostname]) - Implement per-host certificate and content isolation - Add comprehensive virtual host testing and validation - Update docs and examples for multi-host deployments This enables Pollux to serve multiple Gemini domains from one instance, providing the foundation for multi-tenant Gemini hosting.
This commit is contained in:
parent
c193d831ed
commit
0459cb6220
22 changed files with 2296 additions and 406 deletions
|
|
@ -1,4 +1,15 @@
|
|||
use std::path::Path;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn generate_test_certificates_for_host(temp_dir: &Path, hostname: &str) {
|
||||
let cert_path = temp_dir.join(format!("{}.pem", hostname));
|
||||
let key_path = temp_dir.join(format!("{}_key.pem", hostname));
|
||||
|
||||
// Generate self-signed certificate for testing
|
||||
// This is a simplified version - in production, use proper certificates
|
||||
std::fs::write(&cert_path, format!("-----BEGIN CERTIFICATE-----\nTest cert for {}\n-----END CERTIFICATE-----\n", hostname)).unwrap();
|
||||
std::fs::write(&key_path, format!("-----BEGIN PRIVATE KEY-----\nTest key for {}\n-----END PRIVATE KEY-----\n", hostname)).unwrap();
|
||||
}
|
||||
use tempfile::TempDir;
|
||||
|
||||
pub fn setup_test_environment() -> TempDir {
|
||||
|
|
@ -12,16 +23,24 @@ pub fn setup_test_environment() -> TempDir {
|
|||
// Generate test certificates
|
||||
generate_test_certificates(temp_dir.path());
|
||||
|
||||
// Verify certificates were created successfully
|
||||
let cert_path = temp_dir.path().join("cert.pem");
|
||||
let key_path = temp_dir.path().join("key.pem");
|
||||
assert!(cert_path.exists(), "Certificate file was not created");
|
||||
assert!(key_path.exists(), "Private key file was not created");
|
||||
|
||||
temp_dir
|
||||
}
|
||||
|
||||
fn generate_test_certificates(temp_dir: &Path) {
|
||||
use std::process::Command;
|
||||
|
||||
// Generate self-signed certificate for testing
|
||||
let cert_path = temp_dir.join("cert.pem");
|
||||
let key_path = temp_dir.join("key.pem");
|
||||
|
||||
let status = Command::new("openssl")
|
||||
// Use openssl to generate a test certificate
|
||||
let output = Command::new("openssl")
|
||||
.args(&[
|
||||
"req", "-x509", "-newkey", "rsa:2048",
|
||||
"-keyout", &key_path.to_string_lossy(),
|
||||
|
|
@ -30,8 +49,19 @@ fn generate_test_certificates(temp_dir: &Path) {
|
|||
"-nodes",
|
||||
"-subj", "/CN=localhost"
|
||||
])
|
||||
.status()
|
||||
.unwrap();
|
||||
.output();
|
||||
|
||||
match output {
|
||||
Ok(result) if result.status.success() => {
|
||||
// Certificate generation successful
|
||||
}
|
||||
_ => {
|
||||
panic!("Failed to generate test certificates with OpenSSL. Make sure OpenSSL is installed and available in PATH.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
assert!(status.success(), "Failed to generate test certificates");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue