Skip to content

Commit

Permalink
fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Will committed Feb 23, 2024
1 parent 5c53a48 commit ddb0d10
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/tests/decoders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::*;
#[test]
fn decode_dhcp() {
let mut customs = Customs::new(&CUSTOMS);
let mut classify = Classify::new();
let mut classify = classifier();
let mut decoders = Decoders::new(&customs, &mut classify, true);

let mut flows = iter::flows("pcaps/dhcp/dhcpv4.pcap");
Expand Down Expand Up @@ -56,7 +56,7 @@ fn decode_dhcp() {
#[test]
fn decode_radius_acct() {
let mut customs = Customs::new(&CUSTOMS);
let mut classify = Classify::new();
let mut classify = classifier();
let mut decoders = Decoders::new(&customs, &mut classify, true);
let mut flows = iter::flows("pcaps/radius/radius-acct-start.pcap");

Expand Down Expand Up @@ -100,7 +100,7 @@ fn decode_radius_acct() {
#[test]
fn decode_radius_access() {
let mut customs = Customs::new(&CUSTOMS);
let mut classify = Classify::new();
let mut classify = classifier();
let mut decoders = Decoders::new(&customs, &mut classify, true);
let mut flows = iter::flows("pcaps/radius/radius-auth-req.pcap");

Expand Down Expand Up @@ -236,7 +236,7 @@ fn decode_http_1_0_fin_data() {
#[test]
fn decode_dns() {
let mut customs = Customs::new(&CUSTOMS);
let mut classify = Classify::new();
let mut classify = classifier();
let mut decoders = Decoders::new(&customs, &mut classify, true);

let mut query_name: Option<Value> = None;
Expand Down
6 changes: 3 additions & 3 deletions src/tests/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use super::*;
#[test]
fn new_flow_export_timeout_correct() {
let customs = Customs::new(&[]);
let mut queue = FlowQueue::new(None, customs, Classify::new(), true);
let mut queue = FlowQueue::new(None, customs, classifier(), true);

let flow = flow(23, 31, true);
let key = flow.key();
Expand All @@ -24,7 +24,7 @@ fn new_flow_export_timeout_correct() {
#[test]
fn exported_counter_updated_on_add() {
let customs = Customs::new(&[]);
let mut queue = FlowQueue::new(None, customs, Classify::new(), true);
let mut queue = FlowQueue::new(None, customs, classifier(), true);

let mut flow_a = flow(23, 31, true);
let mut flow_b = flow_a.clone();
Expand Down Expand Up @@ -117,7 +117,7 @@ fn unexported_flow_not_sent_on_export() {
#[test]
fn customs_appended_on_decode() {
let customs = Customs::new(&CUSTOMS);
let mut queue = FlowQueue::new(None, customs, Classify::new(), true);
let mut queue = FlowQueue::new(None, customs, classifier(), true);
for mut flow in iter::flows("pcaps/dns/google.com-any.pcap") {
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {
flow.fragments = 2;
Expand Down
11 changes: 11 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::libkflow::*;
use crate::flow::*;
use crate::packet;
use crate::custom::*;
use crate::protocol::{Classify, Decoder};
use crate::reasm::Reassembler;
use crate::time::Timestamp;
use crate::timer::{Timer, Timeout};
Expand Down Expand Up @@ -468,6 +469,16 @@ pub fn value(name: &str, cs: &Customs) -> Option<Value> {
cs.get(name).ok().and_then(|id| cs.iter().find(|c| c.id == id).map(Value::from))
}

pub fn classifier() -> Classify {
let mut classify = Classify::new();
classify.add(Protocol::TCP, 22, Decoder::TLS);
classify.add(Protocol::TCP, 80, Decoder::HTTP);
classify.add(Protocol::UDP, 53, Decoder::DNS);
classify.add(Protocol::UDP, 1812, Decoder::Radius);
classify.add(Protocol::UDP, 1813, Decoder::Radius);
classify
}

fn flow<'a>(src: u32, dst: u32, export: bool) -> Flow<'a> {
Flow{
timestamp: Timestamp::zero(),
Expand Down
4 changes: 3 additions & 1 deletion src/tests/modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ fn dns_mode_parse() {
let flows = iter::flows("pcaps/dns/google.com-any.pcap");
let res = flows.skip(1).next().unwrap();

let result = dns.parse(res.src, res.dst, &res.payload);
let packet = res.payload.to_vec();
let result = dns.parse(res.src, res.dst, &packet);

let expect = Some(dns::Response {
question: dns::Question {
name: "google.com".to_owned(),
Expand Down

0 comments on commit ddb0d10

Please sign in to comment.