impl std::fmt::Debug for super::MachineHttp {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("MachineHttp")
.field("http", &self.http)
.field("pass", &crate::link_pass::debug::PassLength(&self.pass))
.finish()
}
}
#[cfg(test)]
mod tests {
use super::super::{HttpLys, MachineHttp};
#[test]
fn machine_http_debug_reports_pass_length() -> Result<(), Box<dyn std::error::Error>> {
let (root, machine) = crate::link_pass::debug::test_machine()?;
let pass = crate::link_pass::MachinePass::configured(&machine)?;
let token = pass.current()?;
let runtime = tokio::runtime::Builder::new_current_thread().build()?;
let http = MachineHttp {
http: HttpLys::new("https://issuer.example", runtime.handle().clone())?,
pass,
};
let debug = format!("{http:?}");
assert!(
debug.contains(&format!("pass: {}", token.len())),
"pass length absent"
);
assert!(!debug.contains(token.as_str()), "credential bytes escaped");
assert!(debug.contains("http:"));
root.close()?;
Ok(())
}
}