100 lines
3.1 KiB
Rust
100 lines
3.1 KiB
Rust
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
use rpki::source::pipeline::{
|
|
PayloadLoadConfig, load_payloads_from_latest_sources,
|
|
load_payloads_from_latest_sources_with_report,
|
|
};
|
|
use tempfile::tempdir;
|
|
|
|
fn data_dir() -> String {
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
.join("data")
|
|
.to_string_lossy()
|
|
.to_string()
|
|
}
|
|
|
|
#[test]
|
|
fn load_payloads_rejects_entire_slurm_set_when_any_file_is_invalid() {
|
|
let slurm_dir = tempdir().expect("create temp slurm dir");
|
|
|
|
let valid = r#"{
|
|
"slurmVersion": 1,
|
|
"validationOutputFilters": {
|
|
"prefixFilters": [],
|
|
"bgpsecFilters": []
|
|
},
|
|
"locallyAddedAssertions": {
|
|
"prefixAssertions": [],
|
|
"bgpsecAssertions": []
|
|
}
|
|
}"#;
|
|
|
|
fs::write(slurm_dir.path().join("01-valid.slurm"), valid).expect("write valid slurm");
|
|
fs::write(slurm_dir.path().join("02-invalid.slurm"), "{").expect("write invalid slurm");
|
|
|
|
let config = PayloadLoadConfig {
|
|
ccr_dir: data_dir(),
|
|
slurm_dir: Some(slurm_dir.path().to_string_lossy().to_string()),
|
|
strict_ccr_validation: false,
|
|
};
|
|
|
|
let err = load_payloads_from_latest_sources(&config).unwrap_err();
|
|
let text = err.to_string();
|
|
assert!(text.contains("failed to parse SLURM file"));
|
|
assert!(text.contains("02-invalid.slurm"));
|
|
}
|
|
|
|
#[test]
|
|
fn load_report_contains_source_and_quality_details() {
|
|
let config = PayloadLoadConfig {
|
|
ccr_dir: data_dir(),
|
|
slurm_dir: None,
|
|
strict_ccr_validation: false,
|
|
};
|
|
|
|
let result = load_payloads_from_latest_sources_with_report(&config).unwrap();
|
|
|
|
assert!(result.source.ccr_file.ends_with(".ccr"));
|
|
assert!(result.source.ccr_file_size_bytes > 0);
|
|
assert!(!result.source.slurm_enabled);
|
|
assert_eq!(result.source.slurm_file_count, 0);
|
|
assert_eq!(result.quality.before_slurm, result.quality.after_slurm);
|
|
assert_eq!(result.quality.after_slurm.total, result.payloads.len());
|
|
assert_eq!(
|
|
result.quality.ccr_input.total,
|
|
result.quality.ccr_input.vrp + result.quality.ccr_input.aspa
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn load_report_contains_slurm_metadata_and_rule_counts() {
|
|
let slurm_dir = tempdir().expect("create temp slurm dir");
|
|
let slurm = r#"{
|
|
"slurmVersion": 1,
|
|
"validationOutputFilters": {
|
|
"prefixFilters": [],
|
|
"bgpsecFilters": []
|
|
},
|
|
"locallyAddedAssertions": {
|
|
"prefixAssertions": [],
|
|
"bgpsecAssertions": []
|
|
}
|
|
}"#;
|
|
fs::write(slurm_dir.path().join("policy.slurm"), slurm).unwrap();
|
|
let config = PayloadLoadConfig {
|
|
ccr_dir: data_dir(),
|
|
slurm_dir: Some(slurm_dir.path().to_string_lossy().to_string()),
|
|
strict_ccr_validation: false,
|
|
};
|
|
|
|
let result = load_payloads_from_latest_sources_with_report(&config).unwrap();
|
|
|
|
assert!(result.source.slurm_enabled);
|
|
assert_eq!(result.source.slurm_file_count, 1);
|
|
assert_eq!(result.source.slurm_version, Some(1));
|
|
assert_eq!(result.quality.slurm_filters.prefix, 0);
|
|
assert_eq!(result.quality.slurm_assertions.prefix, 0);
|
|
assert_eq!(result.quality.before_slurm, result.quality.after_slurm);
|
|
}
|