mirror of
https://github.com/NLnetLabs/krill.git
synced 2026-09-18 15:37:42 +02:00
97 lines
3.5 KiB
Rust
97 lines
3.5 KiB
Rust
extern crate krill;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use krill::commons::api::Handle;
|
|
use krill::commons::eventsourcing::{AggregateStore, DiskAggregateStore};
|
|
use krill::commons::util::softsigner::OpenSslSigner;
|
|
use krill::constants::PUBSERVER_DFLT;
|
|
use krill::daemon::ca::CertAuth;
|
|
use krill::pubd::Repository;
|
|
|
|
/// This tests that we can understand all events as they have been implemented since 0.4.0,
|
|
/// in order to guarantee that upgrades will work.
|
|
///
|
|
/// The `test-resources/events` directory contains old event files that we will need to keep
|
|
/// supporting in future versions.
|
|
///
|
|
/// They are typically generated by the functional tests in the `tests` dir, and then copied and
|
|
/// preserved here for testing. Because, programmatically generating the json and then parsing
|
|
/// would of course not work for this purpose, new code would understand what it generates itself,
|
|
/// we want to be sure that new code understands old code json.
|
|
///
|
|
/// So, for each release of krill that may have introduced new event types and/or ways of serializing
|
|
/// them, you will find a directory here with the events that were generated by those tests, and you
|
|
/// will find a test that will attempt to create `CertAuth` and `Repository` instances by replaying
|
|
/// them.
|
|
///
|
|
/// Directory lay-out is as follows:
|
|
///
|
|
/// test-resources/
|
|
/// events/
|
|
/// 0.4.0/
|
|
/// ca_keyroll_under_rfc6492_ta/
|
|
/// /cas
|
|
/// /ta
|
|
/// /ca
|
|
/// .. CertAuth events for each instance
|
|
/// /pubd
|
|
/// .. Repository events and snapshot
|
|
/// other tests.
|
|
/// new versions
|
|
#[test]
|
|
fn upgrades() {
|
|
since_0_4_0("ca_embedded", &["ta", "child"]);
|
|
since_0_4_0("ca_grandchildren", &["ta", "CA1", "CA2", "CA3", "CA4"]);
|
|
since_0_4_0("ca_keyroll_rfc6492", &["ta", "rfc6492"]);
|
|
since_0_4_0("ca_rfc6492", &["ta", "rfc6492"]);
|
|
since_0_4_0("ca_roas", &["ta", "child"]);
|
|
publication_since_0_4_0();
|
|
}
|
|
|
|
fn since_0_4_0(scenario: &str, cas: &[&str]) {
|
|
let work_dir = PathBuf::from(format!("test-resources/events/0.4.0/{}/", scenario));
|
|
test_cas(&work_dir, cas);
|
|
test_repo(&work_dir, "pubd");
|
|
}
|
|
|
|
fn publication_since_0_4_0() {
|
|
let work_dir = PathBuf::from("test-resources/events/0.4.0/remote_publication/");
|
|
test_cas(&work_dir, &["ta", "child"]);
|
|
test_repo(&work_dir, "pubd");
|
|
test_repo(&work_dir, "remote-pubd");
|
|
}
|
|
|
|
fn test_cas(work_dir: &PathBuf, cas: &[&str]) {
|
|
let ca_store = DiskAggregateStore::<CertAuth<OpenSslSigner>>::new(&work_dir, "cas").unwrap();
|
|
|
|
for ca in cas {
|
|
assert_no_snapshot(work_dir, &format!("cas/{}", ca));
|
|
let ca_handle = Handle::from_str_unsafe(ca);
|
|
if let Err(e) = ca_store.get_latest(&ca_handle) {
|
|
panic!("Could not rebuild state for ca '{}', error: {}", ca, e);
|
|
}
|
|
}
|
|
}
|
|
|
|
fn test_repo(work_dir: &PathBuf, repo: &str) {
|
|
let repo_store = DiskAggregateStore::<Repository>::new(&work_dir, repo).unwrap();
|
|
assert_no_snapshot(work_dir, &format!("{}/{}", repo, PUBSERVER_DFLT));
|
|
let handle = Handle::from_str_unsafe(PUBSERVER_DFLT);
|
|
if let Err(e) = repo_store.get_latest(&handle) {
|
|
panic!("Could not rebuild state for repository: {}", e)
|
|
}
|
|
}
|
|
|
|
fn assert_no_snapshot(workdir: &PathBuf, rel: &str) {
|
|
let mut snapshot_file = workdir.clone();
|
|
snapshot_file.push(rel);
|
|
snapshot_file.push("snapshot.json");
|
|
if snapshot_file.exists() {
|
|
panic!(
|
|
"Snapshot file should not exist for this test, remove: {}",
|
|
snapshot_file.to_string_lossy().to_string()
|
|
);
|
|
}
|
|
}
|