use super::*;
use crate::fingerprint::ja3::compute_ja3;
#[test]
fn all_profiles_have_required_fields() {
for profile in profiles() {
assert!(!profile.name.is_empty());
assert!(!profile.cipher_suites.is_empty());
assert!(!profile.extensions.is_empty());
assert!(!profile.elliptic_curves.is_empty());
assert!(!profile.ec_point_formats.is_empty());
assert!(!profile.alpn_protocols.is_empty());
assert!(!profile.expected_ja3.is_empty());
assert!(!profile.signature_algorithms.is_empty());
}
}
#[test]
fn profiles_count() {
assert!(profiles().len() >= 6);
}
#[test]
fn profile_for_finds_chrome() {
assert!(profile_for("chrome").unwrap().name.contains("Chrome"));
}
#[test]
fn profile_for_finds_firefox() {
assert!(profile_for("firefox").unwrap().name.contains("Firefox"));
}
#[test]
fn profile_for_resolves_shared_stealth_profile_aliases_first() {
assert_eq!(
profile_for("chrome-mac").unwrap().name,
"Chrome 120 / macOS 14"
);
assert_eq!(
profile_for("firefox-windows").unwrap().name,
"Firefox 115 ESR / Windows 10"
);
assert_eq!(
profile_for("safari-iphone").unwrap().name,
"Safari iOS 17 / iPhone"
);
assert!(profile_for("ie11").is_none());
}
#[test]
fn profile_for_rejects_empty_browser_name() {
assert!(profile_for("").is_none());
assert!(profile_for(" \t\n").is_none());
}
#[test]
fn profile_for_returns_none_for_unknown() {
assert!(profile_for("netscape").is_none());
}
#[test]
fn profile_for_stealth_profile_covers_rotation_profiles() {
for profile in crate::rotation::profiles() {
assert!(
profile_for_stealth_profile(*profile).is_some(),
"{profile:?} must map to a TLS ClientHello catalogue entry"
);
}
}
#[test]
fn legacy_ie_has_no_coherent_tls_catalogue_profile() {
assert!(profile_for_stealth_profile(StealthProfile::Ie11Windows).is_none());
}
#[cfg(feature = "http")]
#[test]
fn default_impersonate_profile_uses_shared_profile_catalogue() {
assert_eq!(
default_impersonate_profile_for_stealth_profile(StealthProfile::ChromeMacStable),
ImpersonateProfile::Chrome131
);
assert_eq!(
default_impersonate_profile_for_stealth_profile(StealthProfile::FirefoxWindows),
ImpersonateProfile::Firefox133
);
assert_eq!(
default_impersonate_profile_for_stealth_profile(StealthProfile::SafariIphone),
ImpersonateProfile::Safari17_5
);
}
#[cfg(feature = "http")]
#[test]
fn impersonate_compatibility_tracks_browser_family() {
assert!(impersonate_profile_matches_stealth_profile(
StealthProfile::ChromeWindowsStable,
ImpersonateProfile::Chrome131
));
assert!(impersonate_profile_matches_stealth_profile(
StealthProfile::BraveWindows,
ImpersonateProfile::Edge131
));
assert!(!impersonate_profile_matches_stealth_profile(
StealthProfile::FirefoxLinux,
ImpersonateProfile::Chrome131
));
assert!(!impersonate_profile_matches_stealth_profile(
StealthProfile::Ie11Windows,
ImpersonateProfile::Chrome120
));
}
#[test]
fn random_profile_returns_valid() {
for _ in 0..50 {
assert!(!random_profile().unwrap().name.is_empty());
}
}
#[test]
fn build_cipher_suites_includes_grease_for_chrome() {
let profile = profile_for("chrome").unwrap();
assert!(profile.include_grease);
let suites = build_cipher_suites(profile);
assert_eq!(suites.len(), profile.cipher_suites.len() + 1);
assert!(GREASE_VALUES.contains(&suites[0]));
}
#[test]
fn build_cipher_suites_no_grease_for_firefox() {
let profile = profile_for("firefox").unwrap();
assert!(!profile.include_grease);
let suites = build_cipher_suites(profile);
assert_eq!(suites.len(), profile.cipher_suites.len());
}
#[test]
fn build_extensions_includes_grease_at_both_edges() {
let profile = profile_for("chrome").unwrap();
let extensions = build_extensions(profile);
assert_eq!(extensions.len(), profile.extensions.len() + 2);
assert!(GREASE_VALUES.contains(extensions.first().unwrap()));
assert!(GREASE_VALUES.contains(extensions.last().unwrap()));
}
#[test]
fn ja3_string_format_uses_five_dash_joined_sections() {
let profile = profile_for("chrome").unwrap();
let ja3 = compute_ja3_string(profile);
let sections: Vec<&str> = ja3.split(',').collect();
assert_eq!(sections.len(), 5);
assert!(sections[0].parse::<u16>().is_ok());
assert!(sections[1].contains('-'));
assert!(sections[2].contains('-'));
assert!(sections[3].contains('-'));
}
#[test]
fn ja3_string_delegates_to_shared_ja3_renderer() {
let profile = profile_for("chrome").unwrap();
let fields = client_hello_fields(profile);
assert_eq!(compute_ja3_string(profile), compute_ja3(&fields));
}
#[test]
fn chrome_and_firefox_have_different_cipher_order() {
let chrome = profile_for("chrome").unwrap();
let firefox = profile_for("firefox").unwrap();
assert_ne!(chrome.cipher_suites[1], firefox.cipher_suites[1]);
}
#[test]
fn chrome_and_firefox_have_different_sig_algs() {
let chrome = profile_for("chrome").unwrap();
let firefox = profile_for("firefox").unwrap();
assert!(firefox.signature_algorithms.contains(&0x0603));
assert!(!chrome.signature_algorithms.contains(&0x0603));
}
#[test]
fn grease_values_are_valid() {
for grease in GREASE_VALUES {
assert_eq!(grease & 0x0f0f, 0x0a0a);
}
}
#[test]
fn expected_ja3_values_are_md5_hex() {
for profile in profiles() {
assert_eq!(profile.expected_ja3.len(), 32, "{}", profile.name);
assert!(
profile
.expected_ja3
.chars()
.all(|ch| ch.is_ascii_hexdigit() && !ch.is_ascii_uppercase()),
"{}",
profile.name
);
}
}
#[test]
fn profile_summary_readable() {
for profile in profiles() {
let summary = profile_summary(profile);
assert!(summary.contains(profile.name));
assert!(summary.contains("ciphers"));
assert!(summary.contains("ALPN"));
}
}
#[test]
fn all_profiles_support_h2_and_http11() {
for profile in profiles() {
assert!(profile.alpn_protocols.contains(&"h2"));
assert!(profile.alpn_protocols.contains(&"http/1.1"));
}
}
#[test]
fn all_profiles_include_sni_extension() {
for profile in profiles() {
assert!(
profile.extensions.contains(&0x0000),
"{} missing SNI extension",
profile.name
);
}
}
#[test]
fn all_profiles_include_alpn_extension() {
for profile in profiles() {
assert!(
profile.extensions.contains(&0x0010),
"{} missing ALPN extension",
profile.name
);
}
}
#[test]
fn build_supported_groups_includes_grease_for_chrome() {
let profile = profile_for("chrome").unwrap();
assert!(profile.include_grease);
let groups = build_supported_groups(profile);
assert_eq!(groups.len(), profile.elliptic_curves.len() + 1);
assert!(GREASE_VALUES.contains(&groups[0]));
}
#[test]
fn build_supported_groups_no_grease_for_firefox() {
let profile = profile_for("firefox").unwrap();
assert!(!profile.include_grease);
let groups = build_supported_groups(profile);
assert_eq!(groups.len(), profile.elliptic_curves.len());
for group in &groups {
assert!(!GREASE_VALUES.contains(group));
}
}
#[test]
fn build_supported_groups_preserves_order() {
let profile = profile_for("chrome").unwrap();
let groups = build_supported_groups(profile);
let start = if profile.include_grease { 1 } else { 0 };
assert_eq!(&groups[start..], profile.elliptic_curves);
}