Skip to content

Commit

Permalink
Add fuzzing test to flowgger (#79)
Browse files Browse the repository at this point in the history
* Add fuzzing test to flowgger

Co-authored-by: Chukwuemeka Ewurum <[email protected]>

* Add fuzzing test to flowgger

Co-authored-by: Chukwuemeka Ewurum <[email protected]>

* Add fuzzing test to flowgger

* Add fuzzing test to flowgger

Co-authored-by: Chukwuemeka Ewurum <[email protected]>

* Add fuzzing test to flowgger

Co-authored-by: Chukwuemeka Ewurum <[email protected]>

* Add fuzzing test to flowgger

Co-authored-by: Chukwuemeka Ewurum <[email protected]>

* Add fuzzing test to flowgger

Co-authored-by: Chukwuemeka Ewurum <[email protected]>

* Updated code formatting

Co-authored-by: Chukwuemeka Ewurum <[email protected]>

---------

Co-authored-by: Chukwuemeka Ewurum <[email protected]>
  • Loading branch information
cahakgeorge and Chukwuemeka Ewurum authored May 17, 2024
1 parent daf412b commit 72f86cf
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 12 deletions.
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 <[email protected]>", "Matteo Bigoi <[email protected]>", "Vivien Chene <[email protected]>", "Francesco Berni <[email protected]>"]
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;

#[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

0 comments on commit 72f86cf

Please sign in to comment.