run tree from tal pass
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use rpki::audit::{DiscoveredFrom, PublicationPointAudit};
|
||||
use rpki::report::Warning;
|
||||
use rpki::storage::{PackFile, PackTime, VerifiedPublicationPointPack};
|
||||
use rpki::validation::manifest::PublicationPointSource;
|
||||
use rpki::validation::tree::{
|
||||
CaInstanceHandle, PublicationPointRunResult, PublicationPointRunner, TreeRunConfig,
|
||||
run_tree_serial,
|
||||
};
|
||||
use rpki::validation::objects::{ObjectsOutput, ObjectsStats};
|
||||
use rpki::audit::PublicationPointAudit;
|
||||
use rpki::validation::tree::{
|
||||
CaInstanceHandle, DiscoveredChildCaInstance, PublicationPointRunResult, PublicationPointRunner,
|
||||
TreeRunConfig, run_tree_serial, run_tree_serial_audit,
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
struct MockRunner {
|
||||
@@ -58,10 +58,7 @@ fn empty_pack(manifest_uri: &str, pp_uri: &str) -> VerifiedPublicationPointPack
|
||||
rfc3339_utc: "2026-02-06T00:00:00Z".to_string(),
|
||||
},
|
||||
manifest_bytes: vec![1, 2, 3],
|
||||
files: vec![PackFile::from_bytes_compute_sha256(
|
||||
manifest_uri,
|
||||
vec![1],
|
||||
)],
|
||||
files: vec![PackFile::from_bytes_compute_sha256(manifest_uri, vec![1])],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +76,25 @@ fn ca_handle(manifest_uri: &str) -> CaInstanceHandle {
|
||||
}
|
||||
}
|
||||
|
||||
fn discovered_child(
|
||||
parent_manifest_uri: &str,
|
||||
child_manifest_uri: &str,
|
||||
) -> DiscoveredChildCaInstance {
|
||||
let name = child_manifest_uri
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or("child.mft")
|
||||
.trim_end_matches(".mft");
|
||||
DiscoveredChildCaInstance {
|
||||
handle: ca_handle(child_manifest_uri),
|
||||
discovered_from: DiscoveredFrom {
|
||||
parent_manifest_rsync_uri: parent_manifest_uri.to_string(),
|
||||
child_ca_certificate_rsync_uri: format!("rsync://example.test/repo/{name}.cer"),
|
||||
child_ca_certificate_sha256_hex: "00".repeat(32),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tree_enqueues_children_only_for_fresh_publication_points() {
|
||||
let root_manifest = "rsync://example.test/repo/root.mft";
|
||||
@@ -86,8 +102,11 @@ fn tree_enqueues_children_only_for_fresh_publication_points() {
|
||||
let child2_manifest = "rsync://example.test/repo/child2.mft";
|
||||
let grandchild_manifest = "rsync://example.test/repo/grandchild.mft";
|
||||
|
||||
let root_children = vec![ca_handle(child1_manifest), ca_handle(child2_manifest)];
|
||||
let child1_children = vec![ca_handle(grandchild_manifest)];
|
||||
let root_children = vec![
|
||||
discovered_child(root_manifest, child1_manifest),
|
||||
discovered_child(root_manifest, child2_manifest),
|
||||
];
|
||||
let child1_children = vec![discovered_child(child1_manifest, grandchild_manifest)];
|
||||
|
||||
let runner = MockRunner::default()
|
||||
.with(
|
||||
@@ -150,10 +169,15 @@ fn tree_enqueues_children_only_for_fresh_publication_points() {
|
||||
assert_eq!(out.instances_failed, 0);
|
||||
|
||||
let called = runner.called();
|
||||
assert_eq!(called, vec![root_manifest, child1_manifest, child2_manifest]);
|
||||
assert_eq!(
|
||||
called,
|
||||
vec![root_manifest, child1_manifest, child2_manifest]
|
||||
);
|
||||
|
||||
assert!(
|
||||
out.warnings.iter().any(|w| w.message.contains("child1 warning")),
|
||||
out.warnings
|
||||
.iter()
|
||||
.any(|w| w.message.contains("child1 warning")),
|
||||
"expected child1 warning propagated"
|
||||
);
|
||||
assert!(
|
||||
@@ -184,7 +208,7 @@ fn tree_respects_max_depth_and_max_instances() {
|
||||
audit: Vec::new(),
|
||||
},
|
||||
audit: PublicationPointAudit::default(),
|
||||
discovered_children: vec![ca_handle(child_manifest)],
|
||||
discovered_children: vec![discovered_child(root_manifest, child_manifest)],
|
||||
},
|
||||
)
|
||||
.with(
|
||||
@@ -229,3 +253,65 @@ fn tree_respects_max_depth_and_max_instances() {
|
||||
assert_eq!(out.instances_processed, 1);
|
||||
assert_eq!(out.instances_failed, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tree_audit_includes_parent_and_discovered_from_for_non_root_nodes() {
|
||||
let root_manifest = "rsync://example.test/repo/root.mft";
|
||||
let child_manifest = "rsync://example.test/repo/child.mft";
|
||||
|
||||
let runner = MockRunner::default()
|
||||
.with(
|
||||
root_manifest,
|
||||
PublicationPointRunResult {
|
||||
source: PublicationPointSource::Fresh,
|
||||
pack: empty_pack(root_manifest, "rsync://example.test/repo/"),
|
||||
warnings: Vec::new(),
|
||||
objects: ObjectsOutput {
|
||||
vrps: Vec::new(),
|
||||
aspas: Vec::new(),
|
||||
warnings: Vec::new(),
|
||||
stats: ObjectsStats::default(),
|
||||
audit: Vec::new(),
|
||||
},
|
||||
audit: PublicationPointAudit::default(),
|
||||
discovered_children: vec![discovered_child(root_manifest, child_manifest)],
|
||||
},
|
||||
)
|
||||
.with(
|
||||
child_manifest,
|
||||
PublicationPointRunResult {
|
||||
source: PublicationPointSource::Fresh,
|
||||
pack: empty_pack(child_manifest, "rsync://example.test/repo/child/"),
|
||||
warnings: Vec::new(),
|
||||
objects: ObjectsOutput {
|
||||
vrps: Vec::new(),
|
||||
aspas: Vec::new(),
|
||||
warnings: Vec::new(),
|
||||
stats: ObjectsStats::default(),
|
||||
audit: Vec::new(),
|
||||
},
|
||||
audit: PublicationPointAudit::default(),
|
||||
discovered_children: Vec::new(),
|
||||
},
|
||||
);
|
||||
|
||||
let out = run_tree_serial_audit(ca_handle(root_manifest), &runner, &TreeRunConfig::default())
|
||||
.expect("run tree audit");
|
||||
|
||||
assert_eq!(out.tree.instances_processed, 2);
|
||||
assert_eq!(out.publication_points.len(), 2);
|
||||
|
||||
let root_audit = &out.publication_points[0];
|
||||
assert_eq!(root_audit.node_id, Some(0));
|
||||
assert_eq!(root_audit.parent_node_id, None);
|
||||
assert!(root_audit.discovered_from.is_none());
|
||||
|
||||
let child_audit = &out.publication_points[1];
|
||||
assert_eq!(child_audit.node_id, Some(1));
|
||||
assert_eq!(child_audit.parent_node_id, Some(0));
|
||||
let df = child_audit
|
||||
.discovered_from
|
||||
.as_ref()
|
||||
.expect("child discovered_from");
|
||||
assert_eq!(df.parent_manifest_rsync_uri, root_manifest);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user