Skip to content

Commit 72f86cf

Browse files
cahakgeorgeChukwuemeka Ewurum
and
Chukwuemeka Ewurum
authored
Add fuzzing test to flowgger (#79)
* Add fuzzing test to flowgger Co-authored-by: Chukwuemeka Ewurum <cewurum@amazon.com> * Add fuzzing test to flowgger Co-authored-by: Chukwuemeka Ewurum <cewurum@amazon.com> * Add fuzzing test to flowgger * Add fuzzing test to flowgger Co-authored-by: Chukwuemeka Ewurum <cewurum@amazon.com> * Add fuzzing test to flowgger Co-authored-by: Chukwuemeka Ewurum <cewurum@amazon.com> * Add fuzzing test to flowgger Co-authored-by: Chukwuemeka Ewurum <cewurum@amazon.com> * Add fuzzing test to flowgger Co-authored-by: Chukwuemeka Ewurum <cewurum@amazon.com> * Updated code formatting Co-authored-by: Chukwuemeka Ewurum <cewurum@amazon.com> --------- Co-authored-by: Chukwuemeka Ewurum <cewurum@amazon.com>
1 parent daf412b commit 72f86cf

File tree

7 files changed

+303
-12
lines changed

7 files changed

+303
-12
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
edition = "2018"
33
name = "flowgger"
4-
version = "0.3.1"
4+
version = "0.3.2"
55
authors = ["Frank Denis <github@pureftpd.org>", "Matteo Bigoi <bigo@crisidev.org>", "Vivien Chene <viv.chene@gmail.com>", "Francesco Berni <kurojishi@kurojishi.me>"]
66
build = "build.rs"
77
repository = "https://github.com/awslabs/flowgger"
@@ -56,6 +56,7 @@ time-tz = "0.3"
5656

5757
[dev-dependencies]
5858
tempdir = "0.3"
59+
quickcheck = "1"
5960

6061
[profile.release]
6162
opt-level = 3

src/flowgger/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use toml::Value;
1111
/// [`Configuration`]: https://github.com/jedisct1/flowgger/wiki/Configuration
1212
#[derive(Clone)]
1313
pub struct Config {
14+
#[cfg(not(test))]
1415
config: Value,
16+
#[cfg(test)]
17+
pub config: Value,
1518
}
1619

1720
impl Config {

src/flowgger/encoder/ltsv_encoder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ use time::Month;
134134
#[test]
135135
fn test_ltsv_full_encode_no_sd() {
136136
let full_msg = "<23>Aug 6 11:15:24 testhostname appname[69]: 42 - some test message";
137-
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";
138-
let cfg = Config::from_string("[input]\n[input.ltsv_schema]\nformat = \"ltsv\"\n").unwrap();
139137
let ts = ts_from_partial_date_time(Month::August, 6, 11, 15, 24);
138+
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);
139+
let cfg = Config::from_string("[input]\n[input.ltsv_schema]\nformat = \"ltsv\"\n").unwrap();
140140

141141
let record = Record {
142142
ts,
@@ -159,9 +159,9 @@ fn test_ltsv_full_encode_no_sd() {
159159
#[test]
160160
fn test_ltsv_full_encode_multiple_sd() {
161161
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";
162-
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";
163-
let cfg = Config::from_string("[input]\n[input.ltsv_schema]\nformat = \"ltsv\"\n").unwrap();
164162
let ts = ts_from_partial_date_time(Month::August, 6, 11, 15, 24);
163+
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);
164+
let cfg = Config::from_string("[input]\n[input.ltsv_schema]\nformat = \"ltsv\"\n").unwrap();
165165

166166
let record = Record {
167167
ts,

src/flowgger/input/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ mod stdin_input;
66
mod tcp;
77
#[cfg(feature = "tls")]
88
mod tls;
9-
#[cfg(feature = "syslog")]
9+
#[cfg(all(feature = "syslog", not(test)))]
1010
mod udp_input;
11+
#[cfg(test)]
12+
pub mod udp_input;
1113

1214
#[cfg(feature = "file")]
1315
pub use self::file::FileInput;

src/flowgger/input/udp_input.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl Input for UdpInput {
9797
/// but could not be handled
9898
/// `Invalid UTF-8 input`: Bubble up from handle_record, the record is not in a valid utf-8 format, it could be a non
9999
/// supported compression format
100-
fn handle_record_maybe_compressed(
100+
pub fn handle_record_maybe_compressed(
101101
line: &[u8],
102102
tx: &SyncSender<Vec<u8>>,
103103
decoder: &Box<dyn Decoder>,

src/flowgger/mod.rs

+46-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,36 @@
1+
#[cfg(not(test))]
12
mod config;
3+
#[cfg(not(test))]
24
mod decoder;
5+
#[cfg(not(test))]
36
mod encoder;
7+
#[cfg(not(test))]
48
mod input;
9+
#[cfg(not(test))]
510
mod merger;
11+
#[cfg(not(test))]
612
mod output;
13+
14+
#[cfg(test)]
15+
pub mod config;
16+
#[cfg(test)]
17+
pub mod decoder;
18+
#[cfg(test)]
19+
pub mod encoder;
20+
#[cfg(test)]
21+
pub mod input;
22+
#[cfg(test)]
23+
pub mod merger;
24+
#[cfg(test)]
25+
pub mod output;
26+
727
mod record;
828
mod splitter;
929
mod utils;
1030

31+
#[cfg(test)]
32+
mod test_fuzzer;
33+
1134
use std::io::{stderr, Write};
1235

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

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

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

215+
#[cfg(all(feature = "file", test))]
216+
pub fn get_output_file(config: &Config) -> Box<dyn Output> {
217+
Box::new(FileOutput::new(config)) as Box<dyn Output>
218+
}
219+
220+
#[cfg(all(not(feature = "file"), test))]
221+
pub fn get_output_file(_config: &Config) -> ! {
222+
panic!("Support for file hasn't been compiled in")
223+
}
224+
192225
#[cfg(feature = "tls")]
193226
fn get_output_tls(config: &Config) -> Box<dyn Output> {
194227
Box::new(TlsOutput::new(config)) as Box<dyn Output>
@@ -274,12 +307,20 @@ fn get_encoder_passthrough(config: &Config) -> Box<dyn Encoder + Send> {
274307
Box::new(PassthroughEncoder::new(config)) as Box<dyn Encoder + Send>
275308
}
276309

277-
#[cfg(feature = "rfc3164")]
278-
fn get_decoder_rfc3164(config: &Config) -> Box<dyn Decoder + Send> {
310+
#[cfg(all(feature = "rfc3164", test))]
311+
pub fn get_decoder_rfc3164(config: &Config) -> Box<dyn Decoder + Send> {
279312
Box::new(RFC3164Decoder::new(config)) as Box<dyn Decoder + Send>
280313
}
314+
#[cfg(all(feature = "rfc3164", test))]
315+
pub fn get_encoder_rfc3164(config: &Config) -> Box<dyn Encoder + Send> {
316+
Box::new(RFC3164Encoder::new(config)) as Box<dyn Encoder + Send>
317+
}
281318

282-
#[cfg(feature = "rfc3164")]
319+
#[cfg(all(feature = "rfc3164", not(test)))]
320+
fn get_decoder_rfc3164(config: &Config) -> Box<dyn Decoder + Send> {
321+
Box::new(RFC3164Decoder::new(config)) as Box<dyn Decoder + Send>
322+
}
323+
#[cfg(all(feature = "rfc3164", not(test)))]
283324
fn get_encoder_rfc3164(config: &Config) -> Box<dyn Encoder + Send> {
284325
Box::new(RFC3164Encoder::new(config)) as Box<dyn Encoder + Send>
285326
}

0 commit comments

Comments
 (0)