fix: redact tunnel keys, preserve cached login and correct HIP handling

This commit is contained in:
Kevin Yue committed 2026-11-18 18:08:01 +08:00
1 parent 65fce7bcf0
commit 9a43880c4d
18 files changed
+412 -196

No files matched your search

+18 -10
View File
@@ -246,11 +246,10 @@ pub fn generate_report(input: &ReportInput) -> anyhow::Result<String> {
/// Identity-only maintenance report. This deliberately does not enumerate the
/// interfaces or execute posture collectors; addresses come from the session owner.
/// Native profiles read the computer domain, consistent with generated and refreshed reports.
pub fn generate_identity_report(input: &ReportInput) -> anyhow::Result<String> {
pub fn generate_identity_report(input: &ReportInput, control: &dyn CollectionControl) -> anyhow::Result<String> {
let params = cookie_params(input);
let budget = CollectionBudget::new(Duration::from_secs(60));
let domain =
native_domain(&input.profile, &budget)?.unwrap_or_else(|| params.get("domain").cloned().unwrap_or_default());
native_domain(&input.profile, control)?.unwrap_or_else(|| params.get("domain").cloned().unwrap_or_default());
let mut report = Element::new("hip-report");
for (name, value) in [
("md5-sum", input.context.md5()),
@@ -569,9 +568,7 @@ impl<'p, 'a> HostInfoCollector<'p, 'a> {
#[cfg(windows)]
if self.profile.client_os() == ClientOs::Windows && self.profile.is_native() {
let report = windows::collect(&commands, control)?;
info.windows_updates = Some(gpapi::hip::WindowsUpdateStatus {
checked_at: report.patches_checked_at,
});
info.windows_updates = Some(report.update_status());
info.windows_categories = Some(report.render()?);
}
@@ -813,6 +810,17 @@ mod tests {
gpapi::os_profile::desktop::collect_profile(OsProfileBuilder::new(client_os), None)
}
#[test]
fn cancelled_identity_report_stops_before_domain_collection() {
let input = make_input(make_profile(ClientOs::Linux));
let cancelled = || Err(io::Error::from(io::ErrorKind::Interrupted));
let error = generate_identity_report(&input, &cancelled).unwrap_err();
assert_eq!(
error.downcast_ref::<io::Error>().unwrap().kind(),
io::ErrorKind::Interrupted
);
}
#[test]
fn identity_report_contains_session_identity_without_posture() {
for os in [ClientOs::Linux, ClientOs::Mac, ClientOs::Windows] {
@@ -823,7 +831,7 @@ mod tests {
client_ipv6: Some("2001:db8::7".into()),
md5: "identity-token".into(),
};
let xml = generate_identity_report(&input).unwrap();
let xml = generate_identity_report(&input, &|| Ok(())).unwrap();
let root = Element::parse(xml.as_bytes()).unwrap();
assert_eq!(
unique_child(&root, "user-name").unwrap().get_text().unwrap(),
@@ -988,7 +996,7 @@ mod tests {
"emulated-domain.internal"
);
assert!(report.contains("<domain>emulated-domain.internal</domain>"));
let identity = Element::parse(generate_identity_report(&input).unwrap().as_bytes()).unwrap();
let identity = Element::parse(generate_identity_report(&input, &|| Ok(())).unwrap().as_bytes()).unwrap();
assert_eq!(
unique_child(&identity, "domain").unwrap().get_text().unwrap(),
"emulated-domain"
@@ -1063,7 +1071,7 @@ mod tests {
expected_domain
);
}
let identity = Element::parse(generate_identity_report(&input).unwrap().as_bytes()).unwrap();
let identity = Element::parse(generate_identity_report(&input, &|| Ok(())).unwrap().as_bytes()).unwrap();
assert_eq!(
unique_child(&identity, "domain").unwrap().get_text().unwrap(),
"emulated-domain"
@@ -1128,7 +1136,7 @@ mod tests {
set_field(host_info_mut(&mut stale).unwrap(), "domain", "stale.internal").unwrap();
let refreshed = refresh_edited_report(&write_xml(&stale).unwrap(), &input).unwrap();
let refreshed = validate_edited_report(&refreshed).unwrap();
let identity = Element::parse(generate_identity_report(&input).unwrap().as_bytes()).unwrap();
let identity = Element::parse(generate_identity_report(&input, &|| Ok(())).unwrap().as_bytes()).unwrap();
for report in [&generated, &refreshed, &identity] {
assert_eq!(
unique_child(report, "domain")
+24
View File
@@ -85,6 +85,16 @@ impl MissingPatch {
}
impl WindowsReport {
pub(super) fn update_status(&self) -> gpapi::hip::WindowsUpdateStatus {
let mut status = gpapi::hip::WindowsUpdateStatus::default();
if self.missing_patches.is_some() {
status.checked_at = self.patches_checked_at;
} else {
status.omitted_snapshot_at = self.patches_checked_at;
}
status
}
pub fn render(&self) -> std::io::Result<String> {
let mut categories = Vec::new();
categories.push(category(
@@ -245,6 +255,20 @@ fn category(name: &str, products: impl Iterator<Item = Element>) -> Element {
mod tests {
use super::*;
#[test]
fn omitted_snapshot_can_be_refreshed_without_claiming_patch_details() {
let mut report = WindowsReport::default();
assert_eq!(report.update_status().refresh_cursor(), None);
report.patches_checked_at = Some(123);
let status = report.update_status();
assert_eq!(status.checked_at, None);
assert_eq!(status.refresh_cursor(), Some(123));
assert!(!report.render().unwrap().contains("missing-patches"));
report.missing_patches = Some(Vec::new());
assert_eq!(report.update_status().checked_at, Some(123));
assert_eq!(report.update_status().refresh_cursor(), Some(123));
}
#[test]
fn real_posture_preserves_unavailable_values_and_escapes_product_text() {
let report: WindowsReport = serde_json::from_str(