liminal-server 0.25.4

Standalone server for the liminal messaging bus
Documentation
use super::CertificateRefusal;
use super::offer::{configured, pack, unpack};

type TestResult = Result<(), Box<dyn std::error::Error>>;

#[test]
fn a_recorded_key_offer_keeps_its_original_noise_bytes() -> TestResult {
    let first = [9; 48];
    assert_eq!(configured(None, &first, "", 1024, 1024)?, first);
    let (certificate, received) = unpack(&first, 1024, 1024)?;
    assert!(certificate.is_none());
    assert_eq!(received, first);
    Ok(())
}

#[test]
fn a_certificate_offer_is_exactly_bounded_and_carries_the_fresh_proof() -> TestResult {
    let first = [9; 48];
    let der = [3; 128];
    let packed = pack(&der, &first, "signed-proof", 256, 256)?;
    let (certificate, received) = unpack(&packed, 256, 256)?;
    let certificate = certificate.ok_or("certificate absent")?;
    assert_eq!(certificate.der, der);
    assert_eq!(certificate.proof, "signed-proof");
    assert_eq!(received, first);
    assert!(matches!(
        unpack(&packed, 127, 256),
        Err(CertificateRefusal::Bound)
    ));
    assert!(matches!(
        unpack(&packed, 256, 1),
        Err(CertificateRefusal::Proof)
    ));
    Ok(())
}

#[test]
fn the_filled_device_template_parses_with_lys_and_explicit_peer_bounds() -> TestResult {
    let template = super::setup::DEVICE_TEMPLATE
        .replace("LYS_HOST", "issuer.example")
        .replace("BROKER_HOST", "broker.example")
        .replace("BROKER_IP", "127.0.0.1")
        .replace("RELAY_HOST", "relay.example")
        .replace("OFFICE_ED25519_PUBLIC_KEY_64_HEX", &"01".repeat(32))
        .replace("ADMISSION_RESOURCE_KIND", "liminal.network")
        .replace("ADMISSION_RESOURCE_ID", "office")
        .replace("ADMISSION_ACTION", "call");
    let config: crate::config::ServerConfig = toml::from_str(&template)?;
    assert!(config.listen_address.ip().is_loopback());
    let lys = config
        .auth
        .ok_or("auth missing")?
        .lys
        .ok_or("Lys missing")?;
    assert!(
        lys.grant_stream
            .ok_or("grant reader missing")?
            .enforce_revocation
    );
    let peers = lys
        .machine
        .ok_or("machine missing")?
        .carrier_choice
        .peers
        .ok_or("peers missing")?;
    peers.validate()?;
    assert_eq!(peers.max_pending_calls.get(), 32);
    assert_eq!(peers.max_call_bytes.get(), 61_440);
    Ok(())
}