Skip to content

Commit

Permalink
test: refactor pcap test to use version from rtshark (#4774)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrstewart authored Sep 18, 2024
1 parent aaaa2e9 commit 1c948da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
3 changes: 2 additions & 1 deletion tests/pcap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ bytes = "1.7.1"
hex = "0.4.3"
reqwest = { version = "0.12.7", features = ["blocking"] }
semver = "1.0.23"
rtshark = "2.9.0"

[dependencies]
anyhow = "1.0.86"
hex = "0.4.3"
rtshark = "2.7.1"
rtshark = "2.9.0"

[dev-dependencies]
# We want to test against the latest, local version of s2n
Expand Down
28 changes: 10 additions & 18 deletions tests/pcap/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
use anyhow::*;
use bytes::Buf;
use bytes::Bytes;
use rtshark::RTSharkBuilder;
use semver::Version;
use std::collections::HashMap;
use std::fs::File;
use std::io::copy;
use std::path::Path;
use std::process::Command;
use std::thread;
use std::time::Duration;

Expand Down Expand Up @@ -101,12 +101,8 @@ fn download(url: &str) -> Result<Bytes> {
}

fn assert_tshark_version() -> Result<()> {
let output = Command::new("tshark").args(["--version"]).output();
let version = output.ok().and_then(|output| {
let message = std::str::from_utf8(&output.stdout).ok();
message.and_then(|msg| msg.split_whitespace().find_map(|s| Version::parse(s).ok()))
});

let version_info = RTSharkBuilder::builder().version()?;
let version = version_info.version();
// Version requirements:
// 1. tshark >= 3.7.0 is required for JA3 support
// JA3 support was added to earlier versions, but did not correctly ignore grease values.
Expand All @@ -117,17 +113,13 @@ fn assert_tshark_version() -> Result<()> {
// 3. tshark >= 4.2.0 is required for JA4 support.
// See https://gitlab.com/wireshark/wireshark/-/commit/fd19f0d06f96b9934e3cd5b9889b2f83d3567fce
let min_version = Version::new(4, 2, 0);
if let Some(version) = version {
assert!(
version >= min_version,
"tshark {} required. tshark {} found",
min_version,
version
);
println!("tshark version: {}", version);
} else {
println!("cargo:warning=Unable to determine tshark version");
}
assert!(
version >= &min_version,
"tshark {} required. tshark {} found.",
min_version,
version
);
println!("tshark version: {}", version);
Ok(())
}

Expand Down

0 comments on commit 1c948da

Please sign in to comment.