parlov-elicit 0.5.0

Elicitation engine: strategy selection and probe plan generation for parlov.
Documentation
//! `EmgBola` -- BOLA body content differential.
//!
//! Sends identical GET requests to baseline and probe URLs with no header
//! manipulation. The oracle signal is a body-level difference: the server
//! returns different JSON error messages (e.g. "access denied" vs "not found")
//! for existing vs nonexistent resources while keeping the status code the same.

use http::Method;
use parlov_core::{
    always_applicable, NormativeStrength, OracleClass, SignalSurface, Technique, Vector,
};

use crate::context::ScanContext;
use crate::strategy::Strategy;
use crate::types::{ProbeSpec, RiskLevel, StrategyMetadata};
use crate::util::build_pair;

static METADATA: StrategyMetadata = StrategyMetadata {
    strategy_id: "emg-bola",
    strategy_name: "EMG: BOLA Body Diff",
    risk: RiskLevel::Safe,
};

static TECHNIQUE: Technique = Technique {
    id: "emg-bola",
    name: "BOLA body content differential",
    oracle_class: OracleClass::Existence,
    vector: Vector::ErrorMessageGranularity,
    strength: NormativeStrength::May,
    normalization_weight: None,
    inverted_signal_weight: None,
    method_relevant: false,
    parser_relevant: false,
    applicability: always_applicable,
    contradiction_surface: SignalSurface::Body,
};

/// Elicits existence differentials via body content differences on same-status responses.
pub struct EmgBola;

impl Strategy for EmgBola {
    fn metadata(&self) -> &'static StrategyMetadata {
        &METADATA
    }

    fn technique_def(&self) -> &'static Technique {
        &TECHNIQUE
    }

    fn methods(&self) -> &[Method] {
        &[Method::GET]
    }

    fn is_applicable(&self, _ctx: &ScanContext) -> bool {
        true
    }

    fn generate(&self, ctx: &ScanContext) -> Vec<ProbeSpec> {
        let pair = build_pair(
            ctx,
            Method::GET,
            ctx.headers.clone(),
            ctx.headers.clone(),
            None,
            METADATA.clone(),
            TECHNIQUE,
        );
        vec![ProbeSpec::Pair(pair)]
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::test_utils::minimal_ctx;

    #[test]
    fn generates_correct_technique_vector() {
        let specs = EmgBola.generate(&minimal_ctx());
        assert_eq!(specs[0].technique().vector, Vector::ErrorMessageGranularity);
    }

    #[test]
    fn generates_correct_technique_strength() {
        let specs = EmgBola.generate(&minimal_ctx());
        assert_eq!(specs[0].technique().strength, NormativeStrength::May);
    }

    #[test]
    fn is_always_applicable() {
        assert!(EmgBola.is_applicable(&minimal_ctx()));
    }

    #[test]
    fn risk_is_safe() {
        assert_eq!(EmgBola.risk(), RiskLevel::Safe);
    }

    #[test]
    fn generates_get_method() {
        let specs = EmgBola.generate(&minimal_ctx());
        let ProbeSpec::Pair(pair) = &specs[0] else {
            panic!("expected Pair variant")
        };
        assert_eq!(pair.baseline.method, Method::GET);
        assert_eq!(pair.probe.method, Method::GET);
    }
}