use super::*;
#[test]
fn wire_self_probe_coherent_when_every_layer_matches() {
let capture = WireCapture {
observed_ttl: Some(55),
akamai_fingerprint: Some(FIREFOX_H2.akamai_fingerprint()),
observed_ja4t: None,
};
assert_eq!(
persona_wire_self_probe(StealthProfile::FirefoxLinux, &capture),
WireSelfProbe::Coherent
);
}
#[test]
fn wire_self_probe_flags_ttl_os_mismatch() {
let capture = WireCapture {
observed_ttl: Some(55),
akamai_fingerprint: None,
observed_ja4t: None,
};
match persona_wire_self_probe(StealthProfile::FirefoxWindows, &capture) {
WireSelfProbe::Incoherent(mismatches) => {
assert_eq!(mismatches.len(), 1);
assert_eq!(
mismatches[0],
WireLayerMismatch::Ttl {
expected_os: UserAgentPlatform::Windows,
expected_initial_ttl: 128,
observed_initial_ttl: 64,
}
);
}
other => panic!("expected Incoherent Ttl, got {other:?}"),
}
}
#[test]
fn wire_self_probe_flags_akamai_engine_mismatch() {
let capture = WireCapture {
observed_ttl: Some(55),
akamai_fingerprint: Some(CHROME_H2.akamai_fingerprint()),
observed_ja4t: None,
};
match persona_wire_self_probe(StealthProfile::FirefoxLinux, &capture) {
WireSelfProbe::Incoherent(mismatches) => {
assert_eq!(mismatches.len(), 1, "TTL matches; only Akamai should fail");
assert_eq!(
mismatches[0],
WireLayerMismatch::Akamai {
expected: FIREFOX_H2.akamai_fingerprint(),
observed: CHROME_H2.akamai_fingerprint(),
}
);
}
other => panic!("expected Incoherent Akamai, got {other:?}"),
}
}
#[test]
fn akamai_mismatch_localizes_to_the_exact_h2_fields() {
use crate::fingerprint::akamai_h2::AkamaiH2Divergence;
let capture = WireCapture {
observed_ttl: None,
akamai_fingerprint: Some(CHROME_H2.akamai_fingerprint()),
observed_ja4t: None,
};
let mismatch = match persona_wire_self_probe(StealthProfile::FirefoxLinux, &capture) {
WireSelfProbe::Incoherent(mut m) => m.remove(0),
other => panic!("expected Incoherent, got {other:?}"),
};
let divergences = mismatch
.akamai_field_divergences()
.expect("an Akamai mismatch with two parseable sides must localize");
assert!(divergences
.iter()
.any(|d| matches!(d, AkamaiH2Divergence::PseudoHeaderOrder { .. })));
assert!(divergences.iter().any(|d| matches!(
d,
AkamaiH2Divergence::Setting {
id: 4,
observed: Some(6_291_456),
target: Some(131_072)
}
)));
let ttl_only = WireLayerMismatch::Ttl {
expected_os: crate::fingerprint::UserAgentPlatform::Windows,
expected_initial_ttl: 128,
observed_initial_ttl: 64,
};
assert!(ttl_only.akamai_field_divergences().is_none());
}
#[test]
fn wire_self_probe_reports_both_layers_failing() {
let capture = WireCapture {
observed_ttl: Some(55),
akamai_fingerprint: Some(SAFARI_H2.akamai_fingerprint()),
observed_ja4t: None,
};
match persona_wire_self_probe(StealthProfile::FirefoxWindows, &capture) {
WireSelfProbe::Incoherent(mismatches) => {
assert_eq!(mismatches.len(), 2, "both TTL and Akamai must be reported");
assert!(mismatches
.iter()
.any(|m| matches!(m, WireLayerMismatch::Ttl { .. })));
assert!(mismatches
.iter()
.any(|m| matches!(m, WireLayerMismatch::Akamai { .. })));
}
other => panic!("expected two mismatches, got {other:?}"),
}
}
#[test]
fn wire_self_probe_unmeasured_on_empty_capture() {
let capture = WireCapture::default();
assert!(capture.is_empty());
assert_eq!(
persona_wire_self_probe(StealthProfile::FirefoxLinux, &capture),
WireSelfProbe::Unmeasured
);
}
#[test]
fn wire_self_probe_skips_unmeasurable_ttl_zero() {
let capture = WireCapture {
observed_ttl: Some(0),
akamai_fingerprint: None,
observed_ja4t: None,
};
assert_eq!(
persona_wire_self_probe(StealthProfile::FirefoxLinux, &capture),
WireSelfProbe::Unmeasured
);
}
#[test]
fn wire_self_probe_skips_akamai_when_persona_has_no_h2_model() {
let capture = WireCapture {
observed_ttl: None,
akamai_fingerprint: Some(CHROME_H2.akamai_fingerprint()),
observed_ja4t: None,
};
assert_eq!(
persona_wire_self_probe(StealthProfile::Ie11Windows, &capture),
WireSelfProbe::Unmeasured
);
}
#[test]
fn wire_self_probe_coherent_when_observed_ja4t_matches() {
let capture = WireCapture {
observed_ttl: None,
akamai_fingerprint: None,
observed_ja4t: Some("64240_2-1-3-1-1-4_1460_8".to_string()),
};
assert_eq!(
persona_wire_self_probe(StealthProfile::FirefoxWindows, &capture),
WireSelfProbe::Coherent
);
}
#[test]
fn wire_self_probe_flags_ja4t_os_mismatch() {
let capture = WireCapture {
observed_ttl: None,
akamai_fingerprint: None,
observed_ja4t: Some("29200_2-4-8-1-3_1460_7".to_string()),
};
match persona_wire_self_probe(StealthProfile::FirefoxWindows, &capture) {
WireSelfProbe::Incoherent(mismatches) => {
assert_eq!(mismatches.len(), 1);
match &mismatches[0] {
WireLayerMismatch::Ja4t { expected, observed } => {
assert_eq!(expected, "64240_2-1-3-1-1-4_1460_8");
assert_eq!(observed, "29200_2-4-8-1-3_1460_7");
}
other => panic!("expected a Ja4t mismatch, got {other:?}"),
}
}
other => panic!("expected Incoherent, got {other:?}"),
}
}
#[test]
fn wire_self_probe_ja4t_wildcards_autotuned_window() {
let capture = WireCapture {
observed_ttl: None,
akamai_fingerprint: None,
observed_ja4t: Some("29200_2-4-8-1-3_1460_7".to_string()),
};
assert_eq!(
persona_wire_self_probe(StealthProfile::FirefoxLinux, &capture),
WireSelfProbe::Coherent
);
}
#[test]
fn wire_self_probe_coherent_on_the_real_captured_tuned_linux_syn() {
let capture = WireCapture {
observed_ttl: None,
akamai_fingerprint: None,
observed_ja4t: Some("64240_2-4-8-1-3_1460_10".to_string()),
};
assert_eq!(
persona_wire_self_probe(StealthProfile::ChromeLinux, &capture),
WireSelfProbe::Coherent,
"the real captured tuned-Linux SYN must be coherent with a Linux persona"
);
match persona_wire_self_probe(StealthProfile::ChromeWindowsStable, &capture) {
WireSelfProbe::Incoherent(mismatches) => assert!(
mismatches
.iter()
.any(|m| matches!(m, WireLayerMismatch::Ja4t { .. })),
"a Windows persona on the real Linux egress must still leak a Ja4t tell"
),
other => {
panic!("expected Incoherent for a Windows persona on real Linux egress, got {other:?}")
}
}
}
#[test]
fn wire_self_probe_stacks_ttl_and_ja4t_mismatches_together() {
let capture = WireCapture {
observed_ttl: Some(54),
akamai_fingerprint: None,
observed_ja4t: Some("29200_2-4-8-1-3_1460_7".to_string()),
};
match persona_wire_self_probe(StealthProfile::FirefoxWindows, &capture) {
WireSelfProbe::Incoherent(mismatches) => {
assert_eq!(mismatches.len(), 2, "both TTL and JA4T should be flagged");
assert!(mismatches
.iter()
.any(|m| matches!(m, WireLayerMismatch::Ttl { .. })));
assert!(mismatches
.iter()
.any(|m| matches!(m, WireLayerMismatch::Ja4t { .. })));
}
other => panic!("expected Incoherent with two layers, got {other:?}"),
}
}