qrush 3.0.1

Lightweight Job Queue and Task Scheduler for Rust (Actix/Axum + Redis + Cron)
Documentation
//! Integration test for the Actix dashboard adapter.
//!
//! Exercises real route wiring + the basic-auth middleware against the
//! Redis-free `/metrics/health` route, so no Redis is required.
//!
//! Run with: `cargo test --features dashboard-actix`
#![cfg(feature = "dashboard-actix")]

use actix_web::{test, App};
use qrush::config::{set_basic_auth, QrushBasicAuthConfig};
use qrush::routes::metrics_route::qrush_metrics_routes;

#[actix_web::test]
async fn health_requires_and_accepts_basic_auth() {
    // Configure credentials once for this test process.
    set_basic_auth(Some(QrushBasicAuthConfig {
        username: "user".into(),
        password: "pass".into(),
    }));

    let app = test::init_service(App::new().configure(qrush_metrics_routes)).await;

    // No Authorization header -> 401 from the middleware.
    let req = test::TestRequest::get()
        .uri("/metrics/health")
        .to_request();
    let resp = test::call_service(&app, req).await;
    assert_eq!(resp.status().as_u16(), 401);
    assert!(resp.headers().contains_key("www-authenticate"));

    // Correct credentials (base64("user:pass")) -> 200 "healthy".
    let req = test::TestRequest::get()
        .uri("/metrics/health")
        .insert_header(("Authorization", "Basic dXNlcjpwYXNz"))
        .to_request();
    let resp = test::call_service(&app, req).await;
    assert_eq!(resp.status().as_u16(), 200);
    let body = test::read_body(resp).await;
    assert_eq!(&body[..], b"healthy");

    // Wrong credentials (base64("user:nope")) -> 401.
    let req = test::TestRequest::get()
        .uri("/metrics/health")
        .insert_header(("Authorization", "Basic dXNlcjpub3Bl"))
        .to_request();
    let resp = test::call_service(&app, req).await;
    assert_eq!(resp.status().as_u16(), 401);
}