#![cfg(all(
feature = "arp",
feature = "dhcp",
feature = "stun",
feature = "snmp",
feature = "dnp3",
))]
use flowscope::{ErrorCode, Module};
#[test]
fn arp_parse_error_converts_to_unified_error() {
let e = flowscope::arp::parse(&[]).expect_err("empty payload must fail");
let err: flowscope::Error = e.into();
assert_eq!(err.module(), Module::Arp);
assert_eq!(err.code(), ErrorCode::Truncated);
assert!(err.is_recoverable());
}
#[test]
fn dhcp_parse_error_converts_to_unified_error() {
let e = flowscope::dhcp::parse(&[0u8; 8]).expect_err("short BOOTP must fail");
let err: flowscope::Error = e.into();
assert_eq!(err.module(), Module::Dhcp);
assert_eq!(err.code(), ErrorCode::Truncated);
}
#[test]
fn stun_not_my_protocol_is_parse_not_truncated() {
let mut buf = [0u8; 20];
buf[0] = 0x00; let e = flowscope::stun::parse(&buf).expect_err("bad cookie must fail");
let err: flowscope::Error = e.into();
assert_eq!(err.module(), Module::Stun);
assert_eq!(err.code(), ErrorCode::Parse);
}
#[test]
fn snmp_decode_error_converts_to_unified_error() {
let e = flowscope::snmp::parse(&[0xff, 0xff, 0xff]).expect_err("garbage must fail");
let err: flowscope::Error = e.into();
assert_eq!(err.module(), Module::Snmp);
assert_eq!(err.code(), ErrorCode::Parse);
}
#[test]
fn dnp3_parse_error_converts_to_unified_error() {
let e = flowscope::dnp3::parse(&[]).expect_err("empty payload must fail");
let err: flowscope::Error = e.into();
assert_eq!(err.module(), Module::Dnp3);
assert_eq!(err.code(), ErrorCode::Truncated);
}
#[test]
fn question_mark_bubbles_module_error_into_crate_result() {
fn accept(payload: &[u8]) -> flowscope::Result<()> {
let _msg = flowscope::arp::parse(payload)?; Ok(())
}
let err = accept(&[]).expect_err("empty must fail");
assert_eq!(err.module(), Module::Arp);
}