diff --git a/.all-contributorsrc b/.all-contributorsrc index 70d7ac6..8163ae9 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -249,6 +249,16 @@ "contributions": [ "code" ] + }, + { + "login": "okrplay", + "name": "Oskar", + "avatar_url": "https://avatars3.githubusercontent.com/u/32576280?v=4", + "profile": "https://github.com/okrplay", + "contributions": [ + "code", + "test" + ] } ], "contributorsPerLine": 7, diff --git a/fixtures/test_script.pl b/fixtures/.rustscan_scripts/test_script.pl similarity index 100% rename from fixtures/test_script.pl rename to fixtures/.rustscan_scripts/test_script.pl diff --git a/fixtures/test_script.py b/fixtures/.rustscan_scripts/test_script.py similarity index 100% rename from fixtures/test_script.py rename to fixtures/.rustscan_scripts/test_script.py diff --git a/fixtures/test_script.sh b/fixtures/.rustscan_scripts/test_script.sh similarity index 100% rename from fixtures/test_script.sh rename to fixtures/.rustscan_scripts/test_script.sh diff --git a/fixtures/test_script.txt b/fixtures/.rustscan_scripts/test_script.txt similarity index 82% rename from fixtures/test_script.txt rename to fixtures/.rustscan_scripts/test_script.txt index a5e0b73..fbb58c4 100644 --- a/fixtures/test_script.txt +++ b/fixtures/.rustscan_scripts/test_script.txt @@ -4,6 +4,6 @@ #ports_separator = "," #call_format = "nmap -vvv -p {{port}} {{ip}}" -# Sriptfile parser stops at the first blank line with parsing. +# Scriptfile parser stops at the first blank line with parsing. # This script will run the system installed nmap, ports will be concatenated with "," . # Unused field: trigger_port = "80" \ No newline at end of file diff --git a/fixtures/.rustscan_scripts/test_script_invalid_headers.txt b/fixtures/.rustscan_scripts/test_script_invalid_headers.txt new file mode 100644 index 0000000..455cc67 --- /dev/null +++ b/fixtures/.rustscan_scripts/test_script_invalid_headers.txt @@ -0,0 +1,7 @@ +#!intentional_blank_line +#tags = "core_approved" +#developer = [ "example", "https://example.org" ] +#ports_separator = "," +#call_format = "nmap -vvv -p {{port}} {{ip}}" + +# tags has to be an array, thus this file won't be parsed \ No newline at end of file diff --git a/pictures/brew.png b/pictures/brew.png new file mode 100644 index 0000000..a341fc2 Binary files /dev/null and b/pictures/brew.png differ diff --git a/src/scripts/mod.rs b/src/scripts/mod.rs index 0416fd0..89559a1 100644 --- a/src/scripts/mod.rs +++ b/src/scripts/mod.rs @@ -60,6 +60,7 @@ ports_separator = "," call_format = "nmap -vvv -p {{port}} {{ip}}" "#; +#[cfg(not(tarpaulin_include))] pub fn init_scripts(scripts: ScriptsRequired) -> Result> { let mut scripts_to_run: Vec = Vec::new(); @@ -353,10 +354,72 @@ impl ScriptConfig { #[cfg(test)] mod tests { - use super::{Script, ScriptFile}; + use super::{find_scripts, parse_scripts, Script, ScriptFile}; + + // Function for testing only, it inserts static values into ip and open_ports + // Doesn't use impl in case it's implemented in the super module at some point + fn into_script(script_f: ScriptFile) -> Script { + Script::build( + script_f.path, + "127.0.0.1".parse().unwrap(), + vec![80, 8080], + script_f.port, + script_f.ports_separator, + script_f.tags, + script_f.call_format, + ) + } + #[test] - fn parse_script() { - let script_f = ScriptFile::new("fixtures/test_script.txt".into()).unwrap(); + fn find_and_parse_scripts() { + let scripts = find_scripts("fixtures/".into()).unwrap(); + let scripts = parse_scripts(scripts); + assert_eq!(scripts.len(), 4); + } + + #[test] + #[should_panic] + fn find_invalid_folder() { + let scripts = find_scripts("Cargo.toml".into()).unwrap(); + } + + #[test] + #[should_panic] + fn open_script_file_invalid_headers() { + ScriptFile::new("fixtures/.rustscan_scripts/test_script_invalid_headers.txt".into()) + .unwrap(); + } + + #[test] + #[should_panic] + fn open_script_file_invalid_call_format() { + let mut script_f = + ScriptFile::new("fixtures/.rustscan_scripts/test_script.txt".into()).unwrap(); + script_f.call_format = Some("qwertyuiop".to_string()); + let script: Script = into_script(script_f); + let output = script.run().unwrap(); + } + + #[test] + #[should_panic] + fn open_script_file_missing_call_format() { + let mut script_f = + ScriptFile::new("fixtures/.rustscan_scripts/test_script.txt".into()).unwrap(); + script_f.call_format = None; + let script: Script = into_script(script_f); + let output = script.run().unwrap(); + } + + #[test] + #[should_panic] + fn open_nonexisting_script_file() { + ScriptFile::new("qwertyuiop.txt".into()).unwrap(); + } + + #[test] + fn parse_txt_script() { + let script_f = + ScriptFile::new("fixtures/.rustscan_scripts/test_script.txt".into()).unwrap(); assert_eq!( script_f.tags, Some(vec!["core_approved".to_string(), "example".to_string()]) @@ -377,16 +440,8 @@ mod tests { #[test] fn run_bash_script() { - let script_f = ScriptFile::new("fixtures/test_script.sh".into()).unwrap(); - let script = Script::build( - script_f.path, - "127.0.0.1".parse().unwrap(), - vec![80, 8080], - script_f.port, - script_f.ports_separator, - script_f.tags, - script_f.call_format, - ); + let script_f = ScriptFile::new("fixtures/.rustscan_scripts/test_script.sh".into()).unwrap(); + let script: Script = into_script(script_f); let output = script.run().unwrap(); // output has a newline at the end by default, .trim() trims it assert_eq!(output.trim(), "127.0.0.1 80,8080"); @@ -394,38 +449,22 @@ mod tests { #[test] fn run_python_script() { - let script_f = ScriptFile::new("fixtures/test_script.py".into()).unwrap(); - let script = Script::build( - script_f.path, - "127.0.0.1".parse().unwrap(), - vec![80, 8080], - script_f.port, - script_f.ports_separator, - script_f.tags, - script_f.call_format, - ); + let script_f = ScriptFile::new("fixtures/.rustscan_scripts/test_script.py".into()).unwrap(); + let script: Script = into_script(script_f); let output = script.run().unwrap(); // output has a newline at the end by default, .trim() trims it assert_eq!( output.trim(), - "Python script ran with arguments ['fixtures/test_script.py', '127.0.0.1', '80,8080']" + "Python script ran with arguments ['fixtures/.rustscan_scripts/test_script.py', '127.0.0.1', '80,8080']" ); } #[test] fn run_perl_script() { - let script_f = ScriptFile::new("fixtures/test_script.pl".into()).unwrap(); - let script = Script::build( - script_f.path, - "127.0.0.1".parse().unwrap(), - vec![80, 8080], - script_f.port, - script_f.ports_separator, - script_f.tags, - script_f.call_format, - ); + let script_f = ScriptFile::new("fixtures/.rustscan_scripts/test_script.pl".into()).unwrap(); + let script: Script = into_script(script_f); let output = script.run().unwrap(); // output has a newline at the end by default, .trim() trims it - assert_eq!(output.trim(), "Total args passed to fixtures/test_script.pl : 2\nArg # 1 : 127.0.0.1\nArg # 2 : 80,8080"); + assert_eq!(output.trim(), "Total args passed to fixtures/.rustscan_scripts/test_script.pl : 2\nArg # 1 : 127.0.0.1\nArg # 2 : 80,8080"); } } diff --git a/tests/timelimits.rs b/tests/timelimits.rs index 9851a3e..0692e73 100644 --- a/tests/timelimits.rs +++ b/tests/timelimits.rs @@ -13,6 +13,7 @@ use wait_timeout::ChildExt; const TIMEOUT_MARGIN: u32 = 3; +#[cfg(not(tarpaulin_include))] fn run_rustscan_with_timeout(args: &[&str], timeout: Duration) { println!("Running: target/debug/rustscan: {}", args.join(" "));