From a6a1a0cd372dd445dfbaf21d3f5940d09f499a51 Mon Sep 17 00:00:00 2001 From: rustdesk Date: Sun, 15 Nov 2026 08:50:08 +0800 Subject: [PATCH] test: initialize isolated app names without production overrides --- src/config.rs | 63 ++++++++++++++++++++++---------- src/config/permanent_password.rs | 15 ++++++++ src/lib.rs | 15 ++++++++ src/password_security.rs | 13 +++++++ src/webrtc.rs | 31 ++++++++++++++++ src/websocket.rs | 1 + 6 files changed, 118 insertions(+), 20 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8cf1a5e4f..d534ebcc2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -916,12 +916,6 @@ impl Config { } } - #[cfg(test)] - pub fn path>(p: P) -> PathBuf { - tests::CONFIG_DIR.join(p) - } - - #[cfg(not(test))] pub fn path>(p: P) -> PathBuf { #[cfg(any(target_os = "android", target_os = "ios"))] { @@ -3044,16 +3038,7 @@ impl Status { #[cfg(test)] mod tests { use super::{permanent_password::PERMANENT_PASSWORD_ENC_VERSION, *}; - - lazy_static::lazy_static! { - pub(super) static ref CONFIG_DIR: PathBuf = { - let path = std::env::temp_dir().join(format!("hbb-common-test-{}", uuid::Uuid::new_v4())); - fs::create_dir(&path).expect("create isolated test config directory"); - path - }; - } - - static CONFIG_STATE_TEST_LOCK: Mutex<()> = Mutex::new(()); + use crate::test::CONFIG_STATE_TEST_LOCK; struct ConfigStateTestGuard { original_config: Config, @@ -3119,12 +3104,21 @@ mod tests { } #[test] - fn test_config_files_use_isolated_temporary_paths() { + fn test_config_files_use_isolated_application_paths() { + crate::test::init_config(); + let app_name = APP_NAME.read().unwrap().clone(); + assert!(app_name.starts_with("RustDesk-test-")); + let identifier = app_name.strip_prefix("RustDesk-test-").unwrap(); + assert!(uuid::Uuid::parse_str(identifier).is_ok()); let root = Config::path(""); - assert!(root.starts_with(std::env::temp_dir())); - assert_ne!(root, std::env::temp_dir()); + assert!(root.to_string_lossy().contains(identifier)); assert_eq!( - std::thread::spawn(|| Config::path("")).join().unwrap(), + std::thread::spawn(|| { + crate::test::init_config(); + Config::path("") + }) + .join() + .unwrap(), root ); for path in [ @@ -3148,6 +3142,7 @@ mod tests { #[test] fn test_serialize() { + crate::test::init_config(); let cfg: Config = Default::default(); let res = toml::to_string_pretty(&cfg); assert!(res.is_ok()); @@ -3158,6 +3153,7 @@ mod tests { #[test] fn test_hbbs_00_hashed_preset_password_storage_matches_plain_with_salt() { + crate::test::init_config(); let salt = "salt123"; let h1 = compute_permanent_password_h1("p@ssw0rd", salt); let storage = "00".to_owned() + &base64::encode(h1, base64::Variant::Original); @@ -3176,6 +3172,7 @@ mod tests { #[test] fn test_legacy_plain_preset_password_with_00_hash_shape_without_salt_keeps_old_behavior() { + crate::test::init_config(); let h1 = compute_permanent_password_h1("p@ssw0rd", "salt123"); let storage = "00".to_owned() + &base64::encode(h1, base64::Variant::Original); let hard_settings = HashMap::from([("password".to_owned(), storage.clone())]); @@ -3193,6 +3190,7 @@ mod tests { #[test] fn test_local_hashed_permanent_password_without_salt_is_not_reported_as_set() { + crate::test::init_config(); let h1 = compute_permanent_password_h1("p@ssw0rd", "salt123"); let mut config = Config::default(); config.password = encode_permanent_password_encrypted_storage_from_h1(&h1).unwrap(); @@ -3206,6 +3204,7 @@ mod tests { #[test] fn test_invalid_local_hashed_password_does_not_generate_effective_salt() { + crate::test::init_config(); let h1 = compute_permanent_password_h1("p@ssw0rd", "salt123"); let mut config = Config::default(); config.password = encode_permanent_password_encrypted_storage_from_h1(&h1).unwrap(); @@ -3221,6 +3220,7 @@ mod tests { #[test] fn test_legacy_plain_preset_password_uses_local_salt_for_challenge() { + crate::test::init_config(); let mut config = Config::default(); config.salt = "local1".to_owned(); let hard_settings = HashMap::from([("password".to_owned(), "legacy-password".to_owned())]); @@ -3234,6 +3234,7 @@ mod tests { #[test] fn test_malformed_preset_password_with_salt_is_not_usable() { + crate::test::init_config(); for storage in ["01secret", "00not-a-valid-hash"] { let hard_settings = HashMap::from([ ("password".to_owned(), storage.to_owned()), @@ -3254,6 +3255,7 @@ mod tests { #[test] fn test_validate_or_decrypt_keeps_plaintext_permanent_password_unchanged() { + crate::test::init_config(); let mut cfg = Config::default(); cfg.password = "p@ssw0rd".to_owned(); cfg.salt = "".to_owned(); @@ -3264,6 +3266,7 @@ mod tests { #[test] fn test_validate_or_decrypt_decrypts_00_permanent_password_without_forcing_store() { + crate::test::init_config(); let mut cfg = Config::default(); let legacy_storage = encrypt_str_or_original("legacy-secret", PASSWORD_ENC_VERSION, ENCRYPT_MAX_LEN); @@ -3276,6 +3279,7 @@ mod tests { #[test] fn test_validate_or_decrypt_rejects_corrupted_00_permanent_password_storage() { + crate::test::init_config(); let legacy_storage = encrypt_str_or_original("legacy-secret", PASSWORD_ENC_VERSION, ENCRYPT_MAX_LEN); let mut invalid_payload = base64::decode( @@ -3295,6 +3299,7 @@ mod tests { #[test] fn test_validate_or_decrypt_rejects_encrypted_hashed_permanent_password_without_salt() { + crate::test::init_config(); let mut cfg = Config::default(); let h1 = compute_permanent_password_h1("p@ssw0rd", "salt123"); cfg.password = encode_permanent_password_encrypted_storage_from_h1(&h1).unwrap(); @@ -3307,6 +3312,7 @@ mod tests { #[test] fn test_set_does_not_validate_or_decrypt_permanent_password_storage_in_memory() { + crate::test::init_config(); let mut cfg = Config::default(); let invalid_payload = crate::password_security::symmetric_crypt(b"not-a-hash", true).unwrap(); @@ -3327,6 +3333,7 @@ mod tests { #[test] fn test_store_keeps_existing_enc_id_when_id_is_unchanged() { + crate::test::init_config(); let mut cfg = Config::default(); cfg.id = "123456789".to_owned(); cfg.enc_id = encrypt_str_or_original(&cfg.id, PASSWORD_ENC_VERSION, ENCRYPT_MAX_LEN); @@ -3342,6 +3349,7 @@ mod tests { #[test] fn test_store_rewrites_enc_id_when_id_changes() { + crate::test::init_config(); let original_id = "123456789"; let updated_id = "987654321"; let mut cfg = Config::default(); @@ -3364,6 +3372,7 @@ mod tests { #[test] fn test_config2_store_keeps_existing_unlock_pin_when_pin_is_unchanged() { + crate::test::init_config(); let _guard = CONFIG_STATE_TEST_LOCK.lock().unwrap(); let _file_guard = ConfigFileRestoreGuard::new(Config::file_("2")); let pin = "123456"; @@ -3388,6 +3397,7 @@ mod tests { #[test] fn test_set_does_not_convert_plaintext_permanent_password_to_storage_format_in_memory() { + crate::test::init_config(); let mut cfg = Config::default(); cfg.password = "legacy-secret".to_owned(); cfg.salt = "".to_owned(); @@ -3404,6 +3414,7 @@ mod tests { #[test] fn test_set_keeps_plaintext_permanent_password_with_current_prefix_in_memory() { + crate::test::init_config(); let mut cfg = Config::default(); cfg.password = "01legacy-secret".to_owned(); cfg.salt = "".to_owned(); @@ -3420,6 +3431,7 @@ mod tests { #[test] fn test_validate_or_decrypt_keeps_plaintext_permanent_password_with_current_prefix_and_long_base64( ) { + crate::test::init_config(); let mut cfg = Config::default(); let plain = "01".to_owned() + &base64::encode([42u8; 24], base64::Variant::Original); cfg.password = plain.clone(); @@ -3432,6 +3444,7 @@ mod tests { #[test] fn test_permanent_password_sync_treats_same_encrypted_hash_as_unchanged() { + crate::test::init_config(); let mut cfg = Config::default(); cfg.salt = "salt123".to_owned(); let h1 = compute_permanent_password_h1("p@ssw0rd", &cfg.salt); @@ -3450,6 +3463,7 @@ mod tests { #[test] fn test_permanent_password_sync_stores_incoming_encrypted_hash_when_local_empty() { + crate::test::init_config(); let salt = "salt123"; let h1 = compute_permanent_password_h1("p@ssw0rd", salt); let incoming = encode_permanent_password_encrypted_storage_from_h1(&h1).unwrap(); @@ -3464,6 +3478,7 @@ mod tests { #[test] fn test_permanent_password_sync_rejects_non_current_storage_payloads() { + crate::test::init_config(); let invalid_payload = vec![42u8; sodiumoxide::crypto::secretbox::MACBYTES + 1]; let invalid_storage = PERMANENT_PASSWORD_ENC_VERSION.to_owned() + &base64::encode(invalid_payload, base64::Variant::Original); @@ -3504,6 +3519,7 @@ mod tests { #[test] fn test_permanent_password_sync_rejects_non_empty_storage_without_salt() { + crate::test::init_config(); let mut cfg = Config::default(); let h1 = compute_permanent_password_h1("p@ssw0rd", "salt123"); let incoming = encode_permanent_password_encrypted_storage_from_h1(&h1).unwrap(); @@ -3517,6 +3533,7 @@ mod tests { #[test] fn test_permanent_password_sync_empty_storage_clears_existing_password() { + crate::test::init_config(); let salt = "salt123"; let h1 = compute_permanent_password_h1("p@ssw0rd", salt); let mut cfg = Config::default(); @@ -3530,6 +3547,7 @@ mod tests { #[test] fn test_permanent_password_sync_empty_storage_uses_incoming_salt() { + crate::test::init_config(); let old_salt = "old-salt"; let h1 = compute_permanent_password_h1("p@ssw0rd", old_salt); let mut cfg = Config::default(); @@ -3545,6 +3563,7 @@ mod tests { #[test] fn test_overwrite_settings() { + crate::test::init_config(); DEFAULT_SETTINGS .write() .unwrap() @@ -3699,6 +3718,7 @@ mod tests { #[test] fn test_config_deserialize() { + crate::test::init_config(); let wrong_type_str = r#" id = true enc_id = [] @@ -3733,6 +3753,7 @@ mod tests { #[test] fn test_peer_config_deserialize() { + crate::test::init_config(); let default_peer_config = toml::from_str::("").unwrap(); // test custom_resolution { @@ -3777,6 +3798,7 @@ mod tests { #[test] fn test_store_load() { + crate::test::init_config(); let peerconfig_id = "123456789"; let cfg: PeerConfig = Default::default(); cfg.store(&peerconfig_id); @@ -3800,6 +3822,7 @@ mod tests { #[test] #[cfg(any(target_os = "linux", target_os = "macos"))] fn test_uinput_ipc_path_is_shared_across_uids() { + crate::test::init_config(); const ROOT_UID: u32 = 0; const USER_UID: u32 = 1000; diff --git a/src/config/permanent_password.rs b/src/config/permanent_password.rs index 5fbca2542..29856fd1b 100644 --- a/src/config/permanent_password.rs +++ b/src/config/permanent_password.rs @@ -215,6 +215,7 @@ mod tests { #[test] fn test_permanent_password_h1_storage_roundtrip() { + crate::test::init_config(); let salt = "salt123"; let password = "p@ssw0rd"; let h1 = compute_permanent_password_h1(password, salt); @@ -227,6 +228,7 @@ mod tests { #[test] fn test_permanent_password_encrypted_storage_uses_01_outer_and_00_inner() { + crate::test::init_config(); let h1 = compute_permanent_password_h1("p@ssw0rd", "salt123"); let storage = encode_permanent_password_encrypted_storage_from_h1(&h1).unwrap(); @@ -245,6 +247,7 @@ mod tests { #[test] fn test_encrypted_hashed_password_storage_matches_plain_with_salt() { + crate::test::init_config(); let salt = "salt123"; let h1 = compute_permanent_password_h1("p@ssw0rd", salt); let storage = encode_permanent_password_encrypted_storage_from_h1(&h1).unwrap(); @@ -262,6 +265,7 @@ mod tests { #[test] fn test_hbbs_00_hashed_preset_password_storage_is_decoded_for_preset_auth() { + crate::test::init_config(); let h1 = compute_permanent_password_h1("p@ssw0rd", "salt123"); let storage = encode_hbbs_preset_password_storage_from_h1(&h1); @@ -270,6 +274,7 @@ mod tests { #[test] fn test_hbbs_00_hashed_preset_password_storage_matches_plain_with_salt() { + crate::test::init_config(); let salt = "salt123"; let h1 = compute_permanent_password_h1("p@ssw0rd", salt); let storage = encode_hbbs_preset_password_storage_from_h1(&h1); @@ -287,6 +292,7 @@ mod tests { #[test] fn test_encrypted_hash_storage_is_not_accepted_as_preset_storage() { + crate::test::init_config(); let salt = "salt123"; let h1 = compute_permanent_password_h1("p@ssw0rd", salt); let storage = encode_permanent_password_encrypted_storage_from_h1(&h1).unwrap(); @@ -301,6 +307,7 @@ mod tests { #[test] fn test_hbbs_00_shaped_preset_password_without_salt_stays_plaintext() { + crate::test::init_config(); let h1 = compute_permanent_password_h1("p@ssw0rd", "salt123"); let storage = encode_hbbs_preset_password_storage_from_h1(&h1); @@ -317,6 +324,7 @@ mod tests { #[test] fn test_hashed_preset_password_storage_without_salt_is_not_usable() { + crate::test::init_config(); let h1 = compute_permanent_password_h1("p@ssw0rd", "salt123"); let storage = encode_permanent_password_storage_from_h1(&h1); @@ -330,6 +338,7 @@ mod tests { #[test] fn test_legacy_plain_preset_password_without_salt_keeps_old_behavior() { + crate::test::init_config(); let storage = "01not-a-valid-hash"; assert!(preset_permanent_password_storage_is_usable_for_auth( @@ -344,6 +353,7 @@ mod tests { #[test] fn test_malformed_preset_password_with_salt_is_not_usable_for_auth() { + crate::test::init_config(); for storage in ["01not-a-valid-hash", "00not-a-valid-hash"] { assert!(!preset_permanent_password_storage_is_usable_for_auth( storage, @@ -359,6 +369,7 @@ mod tests { #[test] fn test_invalid_current_version_storage_is_not_usable_for_auth() { + crate::test::init_config(); let encrypted = symmetric_crypt(b"not-a-hash", true).unwrap(); let encrypted_non_hash = PERMANENT_PASSWORD_ENC_VERSION.to_owned() + &base64::encode(encrypted, base64::Variant::Original); @@ -376,6 +387,7 @@ mod tests { #[test] fn test_legacy_plain_preset_password_that_decodes_as_hash_requires_salt() { + crate::test::init_config(); let h1 = compute_permanent_password_h1("plain-looking-hash", "salt123"); let storage = encode_permanent_password_storage_from_h1(&h1); @@ -389,6 +401,7 @@ mod tests { #[test] fn test_password_is_empty_or_not_hashed_accepts_plaintext_and_decryptable_legacy_plaintext() { + crate::test::init_config(); let storage = encrypt_str_or_original("legacy-secret", PASSWORD_ENC_VERSION, ENCRYPT_MAX_LEN); @@ -398,6 +411,7 @@ mod tests { #[test] fn test_password_is_empty_or_not_hashed_treats_locked_00_storage_as_hashed() { + crate::test::init_config(); let invalid_payload = vec![42u8; sodiumoxide::crypto::secretbox::MACBYTES + 1]; let locked_storage = PASSWORD_ENC_VERSION.to_owned() + &base64::encode(invalid_payload, base64::Variant::Original); @@ -407,6 +421,7 @@ mod tests { #[test] fn test_password_is_empty_or_not_hashed_treats_invalid_01_storage_as_hashed() { + crate::test::init_config(); assert!(!password_is_empty_or_not_hashed("01not-a-valid-hash")); } } diff --git a/src/lib.rs b/src/lib.rs index 503954535..fee3477b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -547,6 +547,21 @@ pub fn time_based_rand() -> u32 { mod test { use super::*; + pub(crate) static CONFIG_STATE_TEST_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(()); + + pub(crate) fn init_config() { + static INIT: std::sync::Once = std::sync::Once::new(); + INIT.call_once(|| { + let app_name = format!("RustDesk-test-{}", uuid::Uuid::new_v4()); + // Mobile config paths use APP_DIR rather than APP_NAME. + *config::APP_DIR.write().unwrap() = std::env::temp_dir() + .join(&app_name) + .to_string_lossy() + .into_owned(); + *config::APP_NAME.write().unwrap() = app_name; + }); + } + #[test] fn test_mangle() { let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 16, 32), 21116)); diff --git a/src/password_security.rs b/src/password_security.rs index 3f5f32430..f321a4900 100644 --- a/src/password_security.rs +++ b/src/password_security.rs @@ -265,6 +265,7 @@ mod test { #[test] fn test() { + crate::test::init_config(); use super::*; use rand::{thread_rng, Rng}; use std::time::Instant; @@ -396,6 +397,7 @@ mod test { #[test] fn test_is_encrypted() { + crate::test::init_config(); use super::*; use sodiumoxide::base64::{encode, Variant}; use sodiumoxide::crypto::secretbox; @@ -439,6 +441,7 @@ mod test { #[test] fn test_encrypted_payload_min_len_macbytes() { + crate::test::init_config(); use super::*; use sodiumoxide::base64::{decode, Variant}; use sodiumoxide::crypto::secretbox; @@ -463,6 +466,7 @@ mod test { #[test] fn test_encryption_uses_random_nonce() { + crate::test::init_config(); use super::*; let data = b"test password 123"; @@ -482,6 +486,7 @@ mod test { #[test] fn test_decrypt_legacy_zero_nonce_payload() { + crate::test::init_config(); use super::*; use std::convert::TryInto; @@ -498,6 +503,7 @@ mod test { #[test] fn test_decrypt_legacy_payload_starting_with_v1_marker() { + crate::test::init_config(); use super::*; use std::convert::TryInto; @@ -520,6 +526,7 @@ mod test { #[test] fn test_invalid_short_v1_payload_returns_error() { + crate::test::init_config(); use super::*; let encrypted = vec![FORMAT_V1]; @@ -529,6 +536,7 @@ mod test { #[test] fn test_decrypt_legacy_string_does_not_request_store() { + crate::test::init_config(); use super::*; use sodiumoxide::base64::{encode, Variant}; use std::convert::TryInto; @@ -551,6 +559,7 @@ mod test { #[test] fn test_decrypt_legacy_vec_does_not_request_store() { + crate::test::init_config(); use super::*; use sodiumoxide::base64::{encode, Variant}; use std::convert::TryInto; @@ -575,6 +584,8 @@ mod test { #[test] #[cfg(not(any(target_os = "android", target_os = "ios")))] fn test_decrypt_with_pk_fallback() { + crate::test::init_config(); + let _guard = crate::test::CONFIG_STATE_TEST_LOCK.lock().unwrap(); use sodiumoxide::crypto::secretbox; use std::convert::TryInto; @@ -608,6 +619,8 @@ mod test { #[test] #[cfg(not(any(target_os = "android", target_os = "ios")))] fn test_decrypt_v1_with_pk_fallback() { + crate::test::init_config(); + let _guard = crate::test::CONFIG_STATE_TEST_LOCK.lock().unwrap(); use super::*; use sodiumoxide::base64::{encode, Variant}; use sodiumoxide::crypto::secretbox; diff --git a/src/webrtc.rs b/src/webrtc.rs index f33f9141c..5f4ec58c5 100644 --- a/src/webrtc.rs +++ b/src/webrtc.rs @@ -1554,6 +1554,7 @@ mod tests { #[test] fn test_webrtc_ice_url() { + crate::test::init_config(); let turn = WebRTCStream::get_ice_server_from_url("turn://123:321@example.com:3478") .expect("credentialed turn is usable"); assert_eq!(turn.urls[0], "turn:example.com:3478"); @@ -1649,6 +1650,7 @@ mod tests { // one process, so mutating it raced every peer connection the loopback tests were building. #[test] fn test_webrtc_ice_server_list() { + crate::test::init_config(); assert_eq!( WebRTCStream::parse_ice_servers("")[0].urls[0], DEFAULT_ICE_SERVERS[0].to_string() @@ -1670,6 +1672,7 @@ mod tests { #[test] fn test_endpoint_ice_policy_declaration() { + crate::test::init_config(); // An envelope with the marker declares full ICE; everything else — no marker, // wrong value, foreign scheme, garbage — reads as the old Relay-only semantics. let marked = @@ -1727,6 +1730,7 @@ mod tests { /// and a fragmented one is dropped without a trace on paths that discard fragments. #[tokio::test] async fn test_stored_endpoint_does_not_grow_with_the_live_description() { + crate::test::init_config(); let offerer = WebRTCStream::new("", false, 20000).await.unwrap(); let live = first_gathered_description(&offerer).await; let endpoint = offerer.local_endpoint().to_owned(); @@ -1753,6 +1757,7 @@ mod tests { /// endpoint the peer cannot consume would trade a silent drop for a silent failure. #[tokio::test] async fn test_trickle_endpoint_splits_candidates_off() { + crate::test::init_config(); let offerer = WebRTCStream::new("", false, 20000).await.unwrap(); let gathered = first_gathered_description(&offerer).await; offerer.close().await; @@ -1803,6 +1808,7 @@ mod tests { #[test] fn test_webrtc_session_key() { + crate::test::init_config(); let mut sdp_str = "".to_owned(); assert_eq!( WebRTCStream::get_key_for_sdp( @@ -1944,6 +1950,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc #[tokio::test] async fn test_webrtc_new_stream() { + crate::test::init_config(); let mut endpoint = "webrtc://sdfsdf".to_owned(); assert!( WebRTCStream::new(&endpoint, false, 10000).await.is_err(), @@ -1981,6 +1988,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc #[tokio::test] async fn test_session_cleanup_only_removes_matching_peer() { + crate::test::init_config(); let key = "test-session-cleanup".to_owned(); let old_key = "test-session-cleanup-old".to_owned(); let old = new_test_stream().await; @@ -2017,6 +2025,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc #[tokio::test] async fn test_webrtc_wait_connected_timeout() { + crate::test::init_config(); let mut stream = WebRTCStream::new("", false, 100).await.unwrap(); let err = stream.wait_connected(10).await.unwrap_err(); assert!(err.to_string().contains("timeout")); @@ -2057,6 +2066,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // entry. `close_detached` is non-async, so what needs proving is that the handoff completes. #[tokio::test] async fn test_close_detached_completes_without_the_caller() { + crate::test::init_config(); let (offerer, answerer) = connect_loopback().await; let key = format!("offer:{}", offerer.session_key()); assert!( @@ -2083,6 +2093,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // exercises the refill itself — a boundary the fixed-size buffer never had. #[tokio::test] async fn test_webrtc_mixed_message_sizes_survive_scratch_refill() { + crate::test::init_config(); let (mut offerer, mut answerer) = connect_loopback().await; // Sized either side of MAX_FRAGMENT_PAYLOAD, and enough rounds to consume several @@ -2116,6 +2127,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // obligation, and the controlled side never honoured it. #[tokio::test] async fn dropping_the_stream_closes_the_peer_connection() { + crate::test::init_config(); let offerer = WebRTCStream::new("", false, 20000).await.unwrap(); let key = format!("offer:{}", offerer.session_key()); assert!( @@ -2142,6 +2154,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // code: the lookup rejected the entry, and the insert handed back the very same one. #[tokio::test] async fn test_cached_peer_is_not_reused_across_ice_policies() { + crate::test::init_config(); let offerer = WebRTCStream::new("", false, 20000).await.unwrap(); let offer = offerer.local_endpoint().to_owned(); @@ -2167,6 +2180,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // has only the teardown, which is what this pins. #[tokio::test] async fn test_local_ice_channel_closes_with_the_peer_connection() { + crate::test::init_config(); let offerer = WebRTCStream::new("", false, 20000).await.unwrap(); let mut ice_rx = offerer.take_local_ice_rx().unwrap(); @@ -2193,6 +2207,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // left in CLOSE_WAIT. #[tokio::test] async fn test_local_ice_channel_closes_when_gathering_completes() { + crate::test::init_config(); let offerer = WebRTCStream::new("", false, 20000).await.unwrap(); let mut ice_rx = offerer.take_local_ice_rx().unwrap(); let drained = timeout(Duration::from_secs(20), async { @@ -2210,6 +2225,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // bind-once guard is exercised; the ordered+reliable check cannot decide anything here. #[tokio::test] async fn test_webrtc_answerer_binds_only_the_first_data_channel() { + crate::test::init_config(); use webrtc::data_channel::data_channel_init::RTCDataChannelInit; let mut offerer = WebRTCStream::new("", false, 20000).await.unwrap(); @@ -2274,6 +2290,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // One-shot callers exchange only the endpoints and never consume `take_local_ice_rx`. #[tokio::test] async fn test_webrtc_loopback_gathered_endpoints() { + crate::test::init_config(); let connect = async { let mut offerer = WebRTCStream::new("", false, 20000).await.unwrap(); let offer = offerer.get_local_endpoint().await.unwrap(); @@ -2296,6 +2313,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // directly; the loopback test below covers the wiring from the flag out to callers. #[test] fn test_note_health_maps_only_the_transient_states() { + crate::test::init_config(); use crate::webrtc::RTCPeerConnectionState; use std::sync::atomic::{AtomicBool, Ordering}; let flag = AtomicBool::new(false); @@ -2326,6 +2344,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // look suspect. #[tokio::test] async fn test_webrtc_disconnected_is_false_on_a_live_pair() { + crate::test::init_config(); let body = async { let (offerer, answerer) = connect_loopback().await; assert!(!offerer.is_disconnected()); @@ -2343,6 +2362,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // messages cannot tell a peer mid-transfer from one that died. #[tokio::test] async fn test_webrtc_rx_progress_moves_before_a_large_message_completes() { + crate::test::init_config(); let body = async { let (mut offerer, mut answerer) = connect_loopback().await; @@ -2399,6 +2419,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // so the sender still puts it on the wire, exactly as an unauthenticated peer would. #[tokio::test] async fn test_webrtc_max_packet_length_bounds_reassembly() { + crate::test::init_config(); let body = async { let (mut offerer, mut answerer) = connect_loopback().await; answerer.set_max_packet_length(16 * 1024); @@ -2431,6 +2452,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // it is lifted, which is what authorization does on the server. #[tokio::test] async fn test_webrtc_max_packet_length_restores() { + crate::test::init_config(); let body = async { let (mut offerer, mut answerer) = connect_loopback().await; answerer.set_max_packet_length(16 * 1024); @@ -2461,6 +2483,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // configured/default STUN just fails in the background without blocking the host pair). #[tokio::test] async fn test_webrtc_loopback_roundtrip() { + crate::test::init_config(); let connect = async { let (mut offerer, mut answerer) = connect_loopback().await; @@ -2514,6 +2537,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // peer must still see EOF — the closer thread, not any caller runtime, delivers it. #[tokio::test(flavor = "multi_thread")] async fn test_session_end_close_reaches_the_peer() { + crate::test::init_config(); let (offerer, mut answerer) = connect_loopback().await; let stream = crate::Stream::WebRTC(offerer); tokio::task::spawn_blocking(move || { @@ -2536,6 +2560,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // the last must close it — an unanswered offerer never reaches a terminal ICE state itself. #[tokio::test(flavor = "multi_thread")] async fn test_last_abandoned_claim_closes_an_unadopted_pc() { + crate::test::init_config(); let builder = WEBRTC_RT .as_ref() .expect("WebRTC I/O runtime") @@ -2574,6 +2599,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // abandonment has to be a property of the pc, not of one handoff. #[tokio::test(flavor = "multi_thread")] async fn test_abandoned_builder_handoff_spares_an_adopted_pc() { + crate::test::init_config(); // Exactly what `new()` does, minus the adoption: the setup task runs on WEBRTC_RT and // hands back a fresh, still-unadopted handoff. let builder = WEBRTC_RT @@ -2621,6 +2647,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // the whole wait while the other keeps starting sessions. #[tokio::test(flavor = "multi_thread")] async fn test_cancelled_new_does_not_leak_the_pc() { + crate::test::init_config(); use std::collections::HashSet; let before: HashSet = SESSIONS.lock().await.keys().cloned().collect(); // Zero timeout: polls the future exactly once (spawning new_inner), then cancels it — @@ -2678,6 +2705,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // (non-trickle) endpoints keep the cross-runtime signaling to two string handoffs. #[tokio::test(flavor = "multi_thread")] async fn test_close_survives_creator_runtime_destruction() { + crate::test::init_config(); // tokio oneshots for every handoff: their sends are synchronous, and the session side // awaits them INSIDE block_on — a current_thread runtime only drives its tasks while // being block_on-driven, and the offerer's SCTP/ICE pumps must stay live until the @@ -2732,6 +2760,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // must end up closed and evicted, never stranded by one closer cancelling the other. #[tokio::test(flavor = "multi_thread")] async fn test_eof_close_then_drop_still_evicts() { + crate::test::init_config(); let (mut offerer, answerer) = connect_loopback().await; let key = format!("offer:{}", offerer.session_key()); answerer.close().await; @@ -2757,6 +2786,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc // The bad frame is injected mid-message so the branch's `acc` reset is exercised too. #[tokio::test] async fn test_webrtc_rejects_bad_fragment_framing() { + crate::test::init_config(); // (raw frame, expected substring) let cases: [(&[u8], &str); 2] = [ (&[0x2A, b'x'], "fragment header 42"), @@ -2797,6 +2827,7 @@ IHR5cCBzcmZseCByYWRkciAwLjAuMC4wIHJwb3J0IDY0MDA4XHJcbmE9ZW5kLW9mLWNhbmRpZGF0ZXNc #[tokio::test] async fn test_webrtc_concurrent_large_sends_preserve_boundaries() { + crate::test::init_config(); let connect = async { let (offerer, mut answerer) = connect_loopback().await; let mut sender_a = offerer.clone(); diff --git a/src/websocket.rs b/src/websocket.rs index 02f0b122c..dfa2b0519 100644 --- a/src/websocket.rs +++ b/src/websocket.rs @@ -625,6 +625,7 @@ mod tests { #[test] fn test_check_ws() { + crate::test::init_config(); let options = Config::get_options(); // enable websocket Config::set_option(keys::OPTION_ALLOW_WEBSOCKET.to_string(), "Y".to_string());