//! Integration test: writes frames with `PcapWriter`, reads them back with //! `PcapReader`, and verifies `Engine::analyze_pcap` reconstructs the AP and handshake. //! mod common; use sabia_core::engine::Engine; use sabia_core::pcapreader::PcapReader; use sabia_core::pcapwriter::PcapWriter; #[test] fn writes_and_reads_back_identical_frames() { let dir = tempfile::tempdir().expect("tempdir"); let path = dir.path().join("captura.pcap"); let beacon = common::radiotap_wrap( &common::beacon_frame(common::ap(), "PcapRede", 1, &[2]), 2412, -30, ); let probe = common::radiotap_wrap(&common::probe_request(common::sta(), "PcapRede"), 2412, -45); { let mut writer = PcapWriter::create(&path).expect("create"); writer.write_frame(&beacon).expect("write beacon"); writer.write_frame(&probe).expect("write probe"); writer.flush().expect("flush"); } let mut reader = PcapReader::open(&path).expect("open"); assert!(reader.supports_80211()); let f1 = reader .next_frame() .expect("read 1") .expect("frame 1 presente"); assert_eq!(f1.data, beacon); let f2 = reader .next_frame() .expect("read 2") .expect("frame 2 presente"); assert_eq!(f2.data, probe); assert!(reader.next_frame().expect("read 3").is_none()); } #[test] fn analyze_pcap_finds_networks_and_handshake() { let dir = tempfile::tempdir().expect("tempdir"); let pcap_path = dir.path().join("sessao.pcap"); let audit_path = dir.path().join("audit.log"); let beacon = common::radiotap_wrap( &common::beacon_frame(common::ap(), "PcapHandshake", 3, &[2]), 2422, -38, ); let (f1, f2) = common::handshake_radiotap_frames("PcapHandshake", "senha-pcap", 2, false); { let mut writer = PcapWriter::create(&pcap_path).expect("create"); writer.write_frame(&beacon).expect("write beacon"); writer.write_frame(&f1).expect("write msg1"); writer.write_frame(&f2).expect("write msg2"); writer.flush().expect("flush"); } let engine = Engine::with_audit_path(&audit_path); let snapshot = engine.analyze_pcap(&pcap_path).expect("analyze_pcap"); assert_eq!(snapshot.access_points.len(), 1); assert_eq!( snapshot.access_points[0].ssid.as_deref(), Some("PcapHandshake") ); assert_eq!(snapshot.handshakes.len(), 1); let hs = &snapshot.handshakes[0]; assert_eq!(hs.ssid.as_deref(), Some("PcapHandshake")); assert!(hs.complete); assert!(hs.crackable); }