use std::time::Duration; use clap::Parser; use sandhole::{ApplicationConfig, entrypoint}; use tokio::{ net::TcpStream, time::{sleep, timeout}, }; use crate::common::SandholeHandle; /// This test ensures that HTTPS services can be fully disabled by the /// `--disable-https` option. #[test_log::test(tokio::test(flavor = "multi_thread"))] async fn config_disable_https() { // 1. Initialize Sandhole let config = ApplicationConfig::parse_from([ "sandhole", "--domain=foobar.tld", "--user-keys-directory", &(format!( "{}/tests/data/user_keys", std::env::var("CARGO_MANIFEST_DIR").unwrap() )), "--admin-keys-directory", &(format!( "{}/tests/data/admin_keys", std::env::var("CARGO_MANIFEST_DIR").unwrap() )), "--certificates-directory", &(format!( "{}/tests/data/certificates", std::env::var("CARGO_MANIFEST_DIR").unwrap() )), "--private-key-file", &(format!( "{}/tests/data/server_keys/ssh", std::env::var("CARGO_MANIFEST_DIR").unwrap() )), "--acme-cache-directory", &(format!( "{}/tests/data/acme_cache", std::env::var("CARGO_MANIFEST_DIR").unwrap() )), "--disable-directory-creation", "--listen-address=127.0.0.1", "--ssh-port=18022", "--http-port=18080", "--https-port=18443", "--acme-use-staging", "--bind-hostnames=none", "--disable-https", "--idle-connection-timeout=1s", "--authentication-request-timeout=5s", "--http-request-timeout=5s", ]); let _sandhole_handle = SandholeHandle(tokio::spawn(async move { entrypoint(config).await })); if timeout(Duration::from_secs(5), async { while TcpStream::connect("127.0.0.1:18022").await.is_err() { sleep(Duration::from_millis(100)).await; } }) .await .is_err() { panic!("Timeout waiting for Sandhole to start.") }; assert!( TcpStream::connect("127.0.0.1:18080").await.is_ok(), "shouldn't listen on HTTP port" ); assert!( TcpStream::connect("127.0.0.1:18443").await.is_err(), "shouldn't listen on HTTPS port" ); }