use super::{ScanContext, ScanPhase};
use crate::client_sim::simulator::ClientSimulator;
use crate::{Args, Result};
use async_trait::async_trait;
pub struct ClientSimPhase;
impl ClientSimPhase {
pub fn new() -> Self {
Self
}
}
impl Default for ClientSimPhase {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ScanPhase for ClientSimPhase {
fn name(&self) -> &'static str {
"Simulating Client Connections"
}
fn should_run(&self, args: &Args) -> bool {
args.scan.all
}
async fn execute(&self, context: &mut ScanContext) -> Result<()> {
let simulator = ClientSimulator::new(context.target());
let simulation_results = simulator.simulate_popular_clients().await?;
context.results.advanced_mut().client_simulations = Some(simulation_results);
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_client_sim_phase_should_run() {
let phase = ClientSimPhase::new();
let mut args = Args::default();
args.scan.all = true;
assert!(phase.should_run(&args));
let args = Args::default();
assert!(!phase.should_run(&args));
let mut args = Args::default();
args.target = Some("example.com".to_string());
assert!(!phase.should_run(&args));
}
#[test]
fn test_client_sim_phase_name() {
let phase = ClientSimPhase::new();
assert_eq!(phase.name(), "Simulating Client Connections");
}
}