rho-coding-agent 3.11.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use std::os::unix::fs::PermissionsExt;

use pretty_assertions::assert_eq;

use super::{connect_owned_by, current_uid, LocalListener};

// Covers: a private endpoint lives in a 0700 folder of its own, which goes
// with the listener; a connection goes through only to an endpoint whose
// listener runs as the user the caller expects, so a token sent next never
// reaches another user's socket at that address. Kills: the connecting
// side's owner check dropped (a token handed to whoever listens there), the
// folder made with the default mode, the folder left behind.
// Owner: daemon platform (Unix local endpoints).
#[tokio::test]
async fn a_private_endpoint_is_reached_only_as_its_owners() {
    let (listener, address) = LocalListener::bind_private("rho-test").unwrap();
    let dir = std::path::Path::new(&address).parent().unwrap().to_owned();
    let mode = std::fs::metadata(&dir).unwrap().permissions().mode() & 0o777;
    let mut connected = Vec::new();
    for uid in [current_uid(), current_uid().wrapping_add(1)] {
        let reached = connect_owned_by(&address, uid).await;
        connected.push(reached.map(drop).map_err(|error| error.kind()));
    }
    drop(listener);

    assert_eq!(
        (mode, connected, dir.exists()),
        (
            0o700,
            vec![Ok(()), Err(std::io::ErrorKind::PermissionDenied)],
            false
        )
    );
}