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 bad_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(pki.localhost_crt.file_path()), tls_key: Some(pki.localhost_key.file_path()), tls_client_auth_root_cert: Some(pki.root_ca_crl.file_path()), tls_revocation_list: Some(BAD_PATH.to_string()), }) .await .unwrap_err(); } #[tokio::test] async fn random_content() { 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(pki.localhost_crt.file_path()), tls_key: Some(pki.localhost_key.file_path()), tls_client_auth_root_cert: Some(pki.root_ca_crl.file_path()), tls_revocation_list: Some(random_file.to_string_lossy().to_string()), }) .await .unwrap_err(); } #[tokio::test] async fn invalid_pem() { 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.localhost_crt.file_path()), tls_key: Some(pki.localhost_key.file_path()), tls_client_auth_root_cert: Some(pki.root_ca_crl.file_path()), tls_revocation_list: Some(pki.root_ca_crt.file_path()), }) .await .unwrap_err(); }