Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fuzzing test to flowgger #79

Merged
merged 8 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2018"
name = "flowgger"
version = "0.3.1"
version = "0.3.2"
authors = ["Frank Denis <github@pureftpd.org>", "Matteo Bigoi <bigo@crisidev.org>", "Vivien Chene <viv.chene@gmail.com>", "Francesco Berni <kurojishi@kurojishi.me>"]
build = "build.rs"
repository = "https://github.com/awslabs/flowgger"
Expand Down Expand Up @@ -56,6 +56,7 @@ time-tz = "0.3"

[dev-dependencies]
tempdir = "0.3"
quickcheck = "1"

[profile.release]
opt-level = 3
Expand Down
3 changes: 3 additions & 0 deletions src/flowgger/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use toml::Value;
/// [`Configuration`]: https://github.com/jedisct1/flowgger/wiki/Configuration
#[derive(Clone)]
pub struct Config {
#[cfg(not(test))]
config: Value,
#[cfg(test)]
pub config: Value,
}

impl Config {
Expand Down
8 changes: 4 additions & 4 deletions src/flowgger/encoder/ltsv_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ use time::Month;
#[test]
fn test_ltsv_full_encode_no_sd() {
let full_msg = "<23>Aug 6 11:15:24 testhostname appname[69]: 42 - some test message";
let expected_msg = "host:testhostname\ttime:1659784524\tmessage:some test message\tfull_message:<23>Aug 6 11:15:24 testhostname appname[69]: 42 - some test message\tlevel:7\tfacility:2\tappname:appname\tprocid:69\tmsgid:42";
let cfg = Config::from_string("[input]\n[input.ltsv_schema]\nformat = \"ltsv\"\n").unwrap();
let ts = ts_from_partial_date_time(Month::August, 6, 11, 15, 24);
let expected_msg = format!("host:testhostname\ttime:{}\tmessage:some test message\tfull_message:<23>Aug 6 11:15:24 testhostname appname[69]: 42 - some test message\tlevel:7\tfacility:2\tappname:appname\tprocid:69\tmsgid:42", ts);
let cfg = Config::from_string("[input]\n[input.ltsv_schema]\nformat = \"ltsv\"\n").unwrap();

let record = Record {
ts,
Expand All @@ -159,9 +159,9 @@ fn test_ltsv_full_encode_no_sd() {
#[test]
fn test_ltsv_full_encode_multiple_sd() {
let full_msg = "<23>Aug 6 11:15:24 testhostname appname[69]: 42 [someid a=\"b\" c=\"123456\"][someid2 a2=\"b2\" c2=\"123456\"] some test message";
let expected_msg = "a:b\tc:123456\ta2:b2\tc2:123456\thost:testhostname\ttime:1659784524\tmessage:some test message\tfull_message:<23>Aug 6 11:15:24 testhostname appname[69]: 42 [someid a=\"b\" c=\"123456\"][someid2 a2=\"b2\" c2=\"123456\"] some test message\tlevel:7\tfacility:2\tappname:appname\tprocid:69\tmsgid:42";
let cfg = Config::from_string("[input]\n[input.ltsv_schema]\nformat = \"ltsv\"\n").unwrap();
let ts = ts_from_partial_date_time(Month::August, 6, 11, 15, 24);
let expected_msg = format!("a:b\tc:123456\ta2:b2\tc2:123456\thost:testhostname\ttime:{}\tmessage:some test message\tfull_message:<23>Aug 6 11:15:24 testhostname appname[69]: 42 [someid a=\"b\" c=\"123456\"][someid2 a2=\"b2\" c2=\"123456\"] some test message\tlevel:7\tfacility:2\tappname:appname\tprocid:69\tmsgid:42", ts);
let cfg = Config::from_string("[input]\n[input.ltsv_schema]\nformat = \"ltsv\"\n").unwrap();

let record = Record {
ts,
Expand Down
4 changes: 3 additions & 1 deletion src/flowgger/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ mod stdin_input;
mod tcp;
#[cfg(feature = "tls")]
mod tls;
#[cfg(feature = "syslog")]
#[cfg(all(feature = "syslog", not(test)))]
mod udp_input;
#[cfg(test)]
pub mod udp_input;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make those public only in test mode ? and keep them private otherwise ? Applicable to all scope changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack!


#[cfg(feature = "file")]
pub use self::file::FileInput;
Expand Down
2 changes: 1 addition & 1 deletion src/flowgger/input/udp_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Input for UdpInput {
/// but could not be handled
/// `Invalid UTF-8 input`: Bubble up from handle_record, the record is not in a valid utf-8 format, it could be a non
/// supported compression format
fn handle_record_maybe_compressed(
pub fn handle_record_maybe_compressed(
line: &[u8],
tx: &SyncSender<Vec<u8>>,
decoder: &Box<dyn Decoder>,
Expand Down
51 changes: 46 additions & 5 deletions src/flowgger/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
#[cfg(not(test))]
mod config;
#[cfg(not(test))]
mod decoder;
#[cfg(not(test))]
mod encoder;
#[cfg(not(test))]
mod input;
#[cfg(not(test))]
mod merger;
#[cfg(not(test))]
mod output;

#[cfg(test)]
pub mod config;
#[cfg(test)]
pub mod decoder;
#[cfg(test)]
pub mod encoder;
#[cfg(test)]
pub mod input;
#[cfg(test)]
pub mod merger;
#[cfg(test)]
pub mod output;

mod record;
mod splitter;
mod utils;

#[cfg(test)]
mod test_fuzzer;

use std::io::{stderr, Write};

#[cfg(feature = "capnp-recompile")]
Expand Down Expand Up @@ -179,16 +202,26 @@ fn get_output_kafka(_config: &Config) -> ! {
panic!("Support for Kafka hasn't been compiled in")
}

#[cfg(feature = "file")]
#[cfg(all(feature = "file", not(test)))]
fn get_output_file(config: &Config) -> Box<dyn Output> {
Box::new(FileOutput::new(config)) as Box<dyn Output>
}

#[cfg(not(feature = "file"))]
#[cfg(all(not(feature = "file"), not(test)))]
fn get_output_file(_config: &Config) -> ! {
panic!("Support for file hasn't been compiled in")
}

#[cfg(all(feature = "file", test))]
pub fn get_output_file(config: &Config) -> Box<dyn Output> {
Box::new(FileOutput::new(config)) as Box<dyn Output>
}

#[cfg(all(not(feature = "file"), test))]
pub fn get_output_file(_config: &Config) -> ! {
panic!("Support for file hasn't been compiled in")
}

#[cfg(feature = "tls")]
fn get_output_tls(config: &Config) -> Box<dyn Output> {
Box::new(TlsOutput::new(config)) as Box<dyn Output>
Expand Down Expand Up @@ -274,12 +307,20 @@ fn get_encoder_passthrough(config: &Config) -> Box<dyn Encoder + Send> {
Box::new(PassthroughEncoder::new(config)) as Box<dyn Encoder + Send>
}

#[cfg(feature = "rfc3164")]
fn get_decoder_rfc3164(config: &Config) -> Box<dyn Decoder + Send> {
#[cfg(all(feature = "rfc3164", test))]
pub fn get_decoder_rfc3164(config: &Config) -> Box<dyn Decoder + Send> {
Box::new(RFC3164Decoder::new(config)) as Box<dyn Decoder + Send>
}
#[cfg(all(feature = "rfc3164", test))]
pub fn get_encoder_rfc3164(config: &Config) -> Box<dyn Encoder + Send> {
Box::new(RFC3164Encoder::new(config)) as Box<dyn Encoder + Send>
}

#[cfg(feature = "rfc3164")]
#[cfg(all(feature = "rfc3164", not(test)))]
fn get_decoder_rfc3164(config: &Config) -> Box<dyn Decoder + Send> {
Box::new(RFC3164Decoder::new(config)) as Box<dyn Decoder + Send>
}
#[cfg(all(feature = "rfc3164", not(test)))]
fn get_encoder_rfc3164(config: &Config) -> Box<dyn Encoder + Send> {
Box::new(RFC3164Encoder::new(config)) as Box<dyn Encoder + Send>
}
Expand Down
Loading
Loading