85 lines
2.6 KiB
Rust
85 lines
2.6 KiB
Rust
use circle_ws_lib::{spawn_circle_server, ServerConfig};
|
|
use std::time::Duration;
|
|
use tokio::time::sleep;
|
|
|
|
#[tokio::test]
|
|
async fn test_basic_ws_server_startup() {
|
|
env_logger::init();
|
|
|
|
let config = ServerConfig::new(
|
|
"127.0.0.1".to_string(),
|
|
8091, // Use a different port to avoid conflicts
|
|
"redis://127.0.0.1:6379".to_string(),
|
|
);
|
|
|
|
let (server_task, server_handle) = spawn_circle_server(config)
|
|
.expect("Failed to spawn circle server");
|
|
|
|
// Let the server run for a short time
|
|
sleep(Duration::from_millis(100)).await;
|
|
|
|
// Stop the server
|
|
server_handle.stop(true).await;
|
|
|
|
// Wait for the server task to complete
|
|
let _ = server_task.await;
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_tls_server_configuration() {
|
|
env_logger::init();
|
|
|
|
// Test TLS configuration validation
|
|
let config = ServerConfig::new(
|
|
"127.0.0.1".to_string(),
|
|
8092,
|
|
"redis://127.0.0.1:6379".to_string(),
|
|
)
|
|
.with_tls("nonexistent_cert.pem".to_string(), "nonexistent_key.pem".to_string())
|
|
.with_tls_port(8444);
|
|
|
|
// This should fail gracefully if cert files don't exist
|
|
match spawn_circle_server(config) {
|
|
Ok((server_task, server_handle)) => {
|
|
// If it succeeds (cert files exist), clean up
|
|
sleep(Duration::from_millis(100)).await;
|
|
server_handle.stop(true).await;
|
|
let _ = server_task.await;
|
|
println!("TLS server started successfully (cert files found)");
|
|
}
|
|
Err(e) => {
|
|
// Expected if cert files don't exist - this is fine for testing
|
|
println!("TLS server failed to start as expected: {}", e);
|
|
assert!(e.to_string().contains("Certificate") || e.to_string().contains("TLS"));
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_server_config_validation() {
|
|
// Test that ServerConfig properly validates TLS settings
|
|
let config = ServerConfig::new(
|
|
"127.0.0.1".to_string(),
|
|
8093,
|
|
"redis://127.0.0.1:6379".to_string(),
|
|
);
|
|
|
|
// Test basic configuration
|
|
|
|
assert_eq!(config.host, "127.0.0.1");
|
|
assert_eq!(config.port, 8093);
|
|
assert!(!config.enable_tls);
|
|
assert!(!config.enable_auth);
|
|
|
|
// Test TLS configuration
|
|
let tls_config = config
|
|
.with_tls("cert.pem".to_string(), "key.pem".to_string())
|
|
.with_tls_port(8445)
|
|
.with_auth();
|
|
|
|
assert!(tls_config.enable_tls);
|
|
assert!(tls_config.enable_auth);
|
|
assert_eq!(tls_config.get_tls_port(), 8445);
|
|
assert_eq!(tls_config.cert_path, Some("cert.pem".to_string()));
|
|
assert_eq!(tls_config.key_path, Some("key.pem".to_string()));
|
|
} |