use super::{ScanContext, ScanPhase};
use crate::protocols::alpn::AlpnTester;
use crate::{Args, Result};
use async_trait::async_trait;
pub struct AlpnPhase;
impl AlpnPhase {
pub fn new() -> Self {
Self
}
}
impl Default for AlpnPhase {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ScanPhase for AlpnPhase {
fn name(&self) -> &'static str {
"Testing ALPN Protocol Negotiation"
}
fn should_run(&self, args: &Args) -> bool {
args.scan.all
}
async fn execute(&self, context: &mut ScanContext) -> Result<()> {
let tester = AlpnTester::new(context.target());
let alpn_results = tester.get_comprehensive_report().await?;
context.results.advanced_mut().alpn_result = Some(alpn_results);
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_alpn_phase_should_run() {
let phase = AlpnPhase::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_alpn_phase_name() {
let phase = AlpnPhase::new();
assert_eq!(phase.name(), "Testing ALPN Protocol Negotiation");
}
}