Consolidate pcap integration tests

This commit is contained in:
FredApps
2026-11-19 12:56:29 +01:00
parent b2456f91c6
commit 702822a5fc
19 changed files with 38 additions and 64 deletions
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{dns_query, eth, ipv4_pkt, udp};
use craft_pcap::{Dns, decode};
use support::{dns_query, eth, ipv4_pkt, udp};
fn answer(kind: u16, rd: &[u8]) -> Dns {
let mut msg = dns_query();
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{dns_query, eth, ipv4_pkt, pcap, udp};
use craft_pcap::{decode, summarize};
use support::{dns_query, eth, ipv4_pkt, pcap, udp};
fn packet(message: &[u8]) -> Vec<u8> {
eth(0x0800, &ipv4_pkt(17, [192, 0, 2, 1], [192, 0, 2, 2], &udp(51000, 53, message)))
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{dns_query, eth, ipv4_pkt, pcap, udp};
use craft_pcap::{decode, summarize};
use support::{dns_query, eth, ipv4_pkt, pcap, udp};
fn response(record_type: u16, rdata: &[u8], declared_length: usize) -> Vec<u8> {
let mut message = dns_query();
+22
View File
@@ -0,0 +1,22 @@
//! Integration tests for craft-pcap.
mod dns_discovery_answers;
mod dns_question_class;
mod dns_rdata_names;
mod pcap_dns_name_limit;
mod pcap_dns_txt_lengths;
mod pcap_flow_time_range;
mod pcap_http_host_boundary;
mod pcap_http_methods;
mod pcap_ipv4_lengths;
mod pcap_ipv6_fragments;
mod pcap_ipv6_no_next_header;
mod pcap_ipv6_version;
mod pcap_tcp_ecn;
mod pcapng_simple_payload;
mod regression_pcapng_framing;
mod regression_tcp_dns_framing;
mod regression_tcp_header_length;
mod regression_tls_bounds;
#[path = "../support/mod.rs"]
mod support;
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{ipv4_pkt, udp};
use craft_pcap::{Dns, decode};
use support::{ipv4_pkt, udp};
fn query(last: usize, compressed: bool) -> Dns {
let mut msg = vec![0, 1, 1, 0, 0, if compressed { 2 } else { 1 }, 0, 0, 0, 0, 0, 0];
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{ipv4_pkt, udp};
use craft_pcap::{Dns, decode};
use support::{ipv4_pkt, udp};
fn response(data: &[u8]) -> Dns {
let mut msg = vec![0, 1, 0x81, 0x80, 0, 0, 0, 1, 0, 0, 0, 0];
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{block, eth, ipv4_pkt, pcap, pcapng, udp};
use craft_pcap::summarize;
use support::{block, eth, ipv4_pkt, pcap, pcapng, udp};
fn frame() -> Vec<u8> {
eth(0x0800, &ipv4_pkt(17, [1; 4], [2; 4], &udp(100, 200, b"body")))
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{ipv4_pkt, tcp};
use craft_pcap::{Http, decode};
use support::{ipv4_pkt, tcp};
fn request(data: &[u8]) -> Http {
decode(101, &ipv4_pkt(6, [1; 4], [2; 4], &tcp(100, 80, 0x18, data))).http.unwrap()
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{ipv4_pkt, tcp};
use craft_pcap::decode;
use support::{ipv4_pkt, tcp};
/// WebDAV and extension methods retain the same HTTP evidence as core methods.
#[test]
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{ipv4_pkt, udp};
use craft_pcap::decode;
use support::{ipv4_pkt, udp};
#[test]
fn incomplete_ipv4_base_headers_explain_why_decoding_stopped() {
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{eth, udp};
use craft_pcap::decode;
use support::{eth, udp};
fn packet(offset: u16, next: u8, payload: &[u8]) -> Vec<u8> {
let mut ip = vec![0u8; 40];
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{eth, ipv4_pkt};
use craft_pcap::decode;
use support::{eth, ipv4_pkt};
fn raw_packets() -> (Vec<u8>, Vec<u8>) {
let ipv4 = ipv4_pkt(17, [1; 4], [2; 4], &[0; 20]);
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{block, pcapng};
use craft_pcap::Capture;
use support::{block, pcapng};
fn capture(original: u32, snaplen: u32, payload: &[u8]) -> Vec<u8> {
let mut out = pcapng(&[]);
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{block, pcapng, sample_frames};
use craft_pcap::summarize;
use support::{block, pcapng, sample_frames};
#[test]
fn mismatched_block_footers_stop_the_capture_with_a_warning() {
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{dns_query, dns_response, ipv4_pkt, tcp};
use craft_pcap::{Decoded, decode};
use support::{dns_query, dns_response, ipv4_pkt, tcp};
fn decoded(payload: &[u8]) -> Decoded {
decode(101, &ipv4_pkt(6, [192, 0, 2, 1], [192, 0, 2, 2], &tcp(53, 51000, 0x18, payload)))
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{ipv4_pkt, tcp};
use craft_pcap::{Decoded, decode};
use support::{ipv4_pkt, tcp};
fn decoded(segment: &[u8]) -> Decoded {
decode(101, &ipv4_pkt(6, [192, 0, 2, 1], [192, 0, 2, 2], segment))
@@ -1,8 +1,5 @@
#[path = "support/mod.rs"]
mod support;
use super::support::{client_hello, ipv4_pkt, tcp};
use craft_pcap::{Decoded, decode};
use support::{client_hello, ipv4_pkt, tcp};
fn decoded(record: &[u8]) -> Decoded {
decode(101, &ipv4_pkt(6, [192, 0, 2, 1], [192, 0, 2, 2], &tcp(51000, 443, 0x18, record)))