servlet 1.0.0

A small application runtime with an explicit operational contract
Documentation
//! Rejected targets cannot redirect configured credentials or corrupt framing.
use super::*;
#[test]
fn destination_and_header_policy_precede_network_work() {
    for bad in [
        "https://user:secret@example.com",
        "file:///etc/passwd",
        "https://example.com/path",
        "https://example.com/?secret=1",
        "http://localhost:0",
        " https://example.com",
    ] {
        assert_eq!(origin(bad).unwrap_err(), ClientError::Configuration);
    }
    let approved = origin("https://example.com:443").unwrap();
    for bad in [
        "https://evil.test/",
        "//evil.test/",
        "/\\evil.test/",
        "/#secret",
        "/\r\nHost: evil",
    ] {
        assert_eq!(
            resolve(&approved, bad).unwrap_err(),
            ClientError::Destination
        );
    }
    assert_eq!(
        resolve(&approved, "/a/../b?secret=1").unwrap().as_str(),
        "https://example.com/b?secret=1"
    );
    let mut headers = HeaderMap::new();
    for reserved in [
        "Host",
        "content-length",
        "transfer-encoding",
        "connection",
        "upgrade",
        "proxy-authorization",
        "traceparent",
        "tracestate",
        "baggage",
    ] {
        assert_eq!(
            header(&mut headers, reserved, "secret"),
            Err(ClientError::Configuration)
        );
    }
    header(&mut headers, "authorization", "Bearer secret").unwrap();
    assert!(headers["authorization"].is_sensitive());
    assert!(!format!("{headers:?}").contains("Bearer secret"));
    for index in 0..31 {
        header(&mut headers, &format!("x-{index}"), "v").unwrap();
    }
    let before = headers.clone();
    assert_eq!(
        header(&mut headers, "too-many", "v"),
        Err(ClientError::Configuration)
    );
    assert_eq!(headers, before);
    assert_eq!(
        header(&mut headers, "authorization", &"x".repeat(4097)),
        Err(ClientError::Configuration)
    );
}
#[test]
fn explicit_configuration_and_errors_redact_values() {
    let config = crate::client::ClientConfig::new("https://secret-host.invalid")
        .unwrap()
        .with_header("authorization", "Bearer topsecret")
        .unwrap();
    let printed = format!("{config:?}");
    assert!(!printed.contains("secret-host"));
    assert!(!printed.contains("topsecret"));
    assert!(
        crate::client::ClientConfig::new("https://example.com")
            .unwrap()
            .with_limits(crate::client::ClientLimits {
                total_timeout: std::time::Duration::ZERO,
                ..Default::default()
            })
            .is_err()
    );
}