use crate::tcp_relay_server::server_config::ServerConfig; use crate::test::pki::Pki; use crate::test::test_files_utils::create_temp_file_with_random_content; use crate::test::{get_port_number, PortsAllocation, BAD_PATH}; const TOKEN: &str = "mytok"; fn port(index: u16) -> u16 { get_port_number(PortsAllocation::TestsWithoutPortOpened, index) } #[tokio::test] async fn unspecified() { let _ = env_logger::builder().is_test(true).try_init(); let pki = Pki::load(); crate::tcp_relay_server::run_app(ServerConfig { tokens: vec![TOKEN.to_string()], tokens_file: None, ports: vec![port(1)], upstream_server: "127.0.0.1".to_string(), listen_address: format!("127.0.0.1:{}", port(0)), increment_ports: 1, tls_cert: None, tls_key: Some(pki.localhost_key.file_path()), tls_client_auth_root_cert: None, tls_revocation_list: None, }) .await .unwrap_err(); } #[tokio::test] async fn incorrect_pem_type() { let _ = env_logger::builder().is_test(true).try_init(); let pki = Pki::load(); crate::tcp_relay_server::run_app(ServerConfig { tokens: vec![TOKEN.to_string()], tokens_file: None, ports: vec![port(1)], upstream_server: "127.0.0.1".to_string(), listen_address: format!("127.0.0.1:{}", port(0)), increment_ports: 1, tls_cert: Some(pki.root_ca_crl.file_path()), tls_key: Some(pki.localhost_key.file_path()), tls_client_auth_root_cert: None, tls_revocation_list: None, }) .await .unwrap_err(); } #[tokio::test] async fn random_contents() { let _ = env_logger::builder().is_test(true).try_init(); let pki = Pki::load(); let random_file = create_temp_file_with_random_content(); crate::tcp_relay_server::run_app(ServerConfig { tokens: vec![TOKEN.to_string()], tokens_file: None, ports: vec![port(1)], upstream_server: "127.0.0.1".to_string(), listen_address: format!("127.0.0.1:{}", port(0)), increment_ports: 1, tls_cert: Some(random_file.to_string_lossy().to_string()), tls_key: Some(pki.localhost_key.file_path()), tls_client_auth_root_cert: None, tls_revocation_list: None, }) .await .unwrap_err(); } #[tokio::test] async fn invalid_path() { let _ = env_logger::builder().is_test(true).try_init(); let pki = Pki::load(); crate::tcp_relay_server::run_app(ServerConfig { tokens: vec![TOKEN.to_string()], tokens_file: None, ports: vec![port(1)], upstream_server: "127.0.0.1".to_string(), listen_address: format!("127.0.0.1:{}", port(0)), increment_ports: 1, tls_cert: Some(BAD_PATH.to_string()), tls_key: Some(pki.localhost_key.file_path()), tls_client_auth_root_cert: None, tls_revocation_list: None, }) .await .unwrap_err(); }