fix: accept exact recovery inventory and preserve native durable replay
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -99,10 +99,11 @@ pub fn validate_for_scope(
|
||||
serde_json::from_value(item.clone()).map_err(|_| "INVALID_OBSERVATION")?;
|
||||
if !o.scope.starts_with(prefix)
|
||||
|| o.scope.len() > 64
|
||||
|| !o
|
||||
|| !(o
|
||||
.scope
|
||||
.bytes()
|
||||
.all(|c| c.is_ascii_lowercase() || b"._".contains(&c))
|
||||
|| (scope == "linux.base" && o.scope == "linux.apt.recovery-planning"))
|
||||
|| !scopes.insert(o.scope)
|
||||
{
|
||||
return Err("INVALID_OBSERVATION_SCOPE");
|
||||
@@ -177,4 +178,38 @@ mod tests {
|
||||
v["observations"][0]["scope"] = json!("windows.os");
|
||||
assert!(validate_for_scope(&serde_json::to_vec(&v).unwrap(), now, "windows.base").is_ok());
|
||||
}
|
||||
#[test]
|
||||
fn exact_linux_recovery_scope_does_not_admit_other_hyphens_or_windows() {
|
||||
let now = Utc::now();
|
||||
let mut v = base();
|
||||
v["collection_started_at"] = json!(now);
|
||||
v["collection_completed_at"] = json!(now);
|
||||
v["observations"] = json!([{"scope":"linux.apt.recovery-planning","source_id":"root-helper:apt_recovery_planning_v1","observed_at":now,"quality":"valid","completeness":"complete","truncated":false,"error_code":null,"data":{"native_recovery":{"schema_version":1}}}]);
|
||||
let original = serde_json::to_vec(&v).unwrap();
|
||||
assert_eq!(validate(&original, now).unwrap(), v);
|
||||
for rejected in [
|
||||
"linux.apt.other-planning",
|
||||
"linux.apt.recovery-planning-extra",
|
||||
"linux.other-scope",
|
||||
] {
|
||||
v["observations"][0]["scope"] = json!(rejected);
|
||||
assert_eq!(
|
||||
validate(&serde_json::to_vec(&v).unwrap(), now).unwrap_err(),
|
||||
"INVALID_OBSERVATION_SCOPE"
|
||||
);
|
||||
}
|
||||
v["os"] = json!("Windows 11 Pro");
|
||||
v["root_available_inodes"] = Value::Null;
|
||||
for rejected in [
|
||||
"linux.apt.recovery-planning",
|
||||
"windows.apt.recovery-planning",
|
||||
] {
|
||||
v["observations"][0]["scope"] = json!(rejected);
|
||||
assert_eq!(
|
||||
validate_for_scope(&serde_json::to_vec(&v).unwrap(), now, "windows.base")
|
||||
.unwrap_err(),
|
||||
"INVALID_OBSERVATION_SCOPE"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user