-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test and remove once_cell dependency
- Loading branch information
Showing
7 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Test rustscan logging utilities, ensuring library doesn't log to stdout. | ||
*/ | ||
use std::{ | ||
io::Read, | ||
process::{Command, Stdio}, | ||
}; | ||
|
||
// need to import here, otherwise cargo thinks I'm not using the test | ||
mod log_mode_test_binary; | ||
|
||
#[test] | ||
fn no_logging_scanner() { | ||
let mut child = Command::new("target/debug/examples/log_mode_test_binary") | ||
.stderr(Stdio::piped()) | ||
.stdout(Stdio::piped()) | ||
.spawn() | ||
.unwrap(); | ||
|
||
child.wait().unwrap(); | ||
|
||
let buf = &mut Vec::new(); | ||
child.stdout.take().unwrap().read_to_end(buf).unwrap(); | ||
assert!(buf.is_empty()); | ||
|
||
child.stderr.take().unwrap().read_to_end(buf).unwrap(); | ||
assert!(buf.is_empty()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//! File used just to build a binary for testing if stdout is being logged. | ||
//! Older versions of the library rustscan would write to stdout. This file | ||
//! helps ensure the library only writes to stdout if log is initialized, | ||
//! otherwise it shouldn't write at all. | ||
//! | ||
//! It was necessary to create this file because checking if some code write to | ||
//! stdout is very orthogonal to rust's testing tools. There are utilities but | ||
//! only on unstable rust. This file is used to create a binary that can | ||
//! be executed as child process for testing the behavior. | ||
#![allow(unused)] | ||
|
||
use std::{net::IpAddr, str::FromStr, time::Duration}; | ||
|
||
use futures::executor::block_on; | ||
use rustscan::{input::ScanOrder, port_strategy::PortStrategy, scanner::Scanner}; | ||
|
||
fn main() { | ||
// "open" tcp connection on random port | ||
let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); | ||
// get the port from above connection | ||
let port = listener.local_addr().unwrap().port(); | ||
|
||
// execute | ||
block_on( | ||
Scanner::new( | ||
&[IpAddr::from_str("127.0.0.1").unwrap()], | ||
100, | ||
Duration::from_secs(5), | ||
3, | ||
false, | ||
PortStrategy::pick(&None, Some(vec![port]), ScanOrder::Random), | ||
true, | ||
vec![], | ||
false, | ||
) | ||
.run(), | ||
); | ||
} |