added param to pause function for testability

This commit is contained in:
epi
2020-11-20 16:09:30 -06:00
parent 1b1190582a
commit 46a471c8a7
2 changed files with 29 additions and 30 deletions

View File

@@ -229,8 +229,7 @@ impl FeroxScans {
///
/// When the value stored in `PAUSE_SCAN` becomes `false`, the function returns, exiting the busy
/// loop
pub async fn pause(&self) {
log::trace!("enter: pause_scan");
pub async fn pause(&self, get_user_input: bool) {
// function uses tokio::time, not std
// local testing showed a pretty slow increase (less than linear) in CPU usage as # of
@@ -243,12 +242,14 @@ impl FeroxScans {
if INTERACTIVE_BARRIER.load(Ordering::Relaxed) == 0 {
INTERACTIVE_BARRIER.fetch_add(1, Ordering::Relaxed);
self.display_scans();
if get_user_input {
self.display_scans();
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
// todo actual logic for the scanning
PROGRESS_PRINTER.println(format!("Got {} from stdin", s.strip_suffix('\n').unwrap()));
let mut s = String::new();
std::io::stdin().read_line(&mut s).unwrap();
// todo actual logic for the scanning
PROGRESS_PRINTER.println(format!("Got {} from stdin", s.strip_suffix('\n').unwrap()));
}
}
loop {
@@ -317,29 +318,27 @@ impl FeroxScans {
mod tests {
use super::*;
// todo scanner_pause_scan_with_finished_spinner test need to be redone
#[tokio::test(core_threads = 1)]
/// tests that pause_scan pauses execution and releases execution when PAUSE_SCAN is toggled
/// the spinner used during the test has had .finish_and_clear called on it, meaning that
/// a new one will be created, taking the if branch within the function
async fn scanner_pause_scan_with_finished_spinner() {
let now = time::Instant::now();
let urls = FeroxScans::default();
// #[tokio::test(core_threads = 1)]
// /// tests that pause_scan pauses execution and releases execution when PAUSE_SCAN is toggled
// /// the spinner used during the test has had .finish_and_clear called on it, meaning that
// /// a new one will be created, taking the if branch within the function
// async fn scanner_pause_scan_with_finished_spinner() {
// let now = time::Instant::now();
// let urls = FeroxScans::default();
//
// PAUSE_SCAN.store(true, Ordering::Relaxed);
//
// let expected = time::Duration::from_secs(2);
//
// tokio::spawn(async move {
// time::delay_for(expected).await;
// PAUSE_SCAN.store(false, Ordering::Relaxed);
// });
//
// urls.pause().await;
//
// assert!(now.elapsed() > expected);
// }
PAUSE_SCAN.store(true, Ordering::Relaxed);
let expected = time::Duration::from_secs(2);
tokio::spawn(async move {
time::delay_for(expected).await;
PAUSE_SCAN.store(false, Ordering::Relaxed);
});
urls.pause(false).await;
assert!(now.elapsed() > expected);
}
#[test]
/// add an unknown url to the hashset, expect true

View File

@@ -557,7 +557,7 @@ pub async fn scan_url(
// for every word in the wordlist, check to see if PAUSE_SCAN is set to true
// when true; enter a busy loop that only exits by setting PAUSE_SCAN back
// to false
SCANNED_URLS.pause().await;
SCANNED_URLS.pause(true).await;
}
make_requests(&tgt, &word, base_depth, txd, txr).await
}),