diff --git a/src/control_plane.rs b/src/control_plane.rs index 8d33260..84dd4d2 100644 --- a/src/control_plane.rs +++ b/src/control_plane.rs @@ -13671,6 +13671,9 @@ mod tests { ForeignChallengeId, /// An HTTP error where the snapshot should be. HttpFailure, + /// A first Odin candidate answering its Warming challenge: the + /// detail names the challenge as `idunn-warming:`. + FirstOdinWarming, } impl RuntimeStub { @@ -13704,7 +13707,10 @@ mod tests { .collect(), health_contract: expected.health_contract.clone(), state: (*self.state.lock().unwrap()).into(), - detail: format!("route-observation:{message_id}"), + detail: match *self.reply.lock().unwrap() { + Reply::FirstOdinWarming => format!("idunn-warming:{message_id}"), + _ => format!("route-observation:{message_id}"), + }, write_lease_sha256: self.lease.lock().unwrap().clone(), signer_identity_id: self.provider.entry().identity_id.clone(), publisher_sequence: self.sequence.fetch_add(1, Ordering::SeqCst) + 1, @@ -14900,9 +14906,18 @@ mod tests { routed: &RoutedWorld, transaction: &DeploymentTransaction, sequence: u64, + ) -> Result { + odin_receipt_with(routed, transaction, sequence, true) + } + + fn odin_receipt_with( + routed: &RoutedWorld, + transaction: &DeploymentTransaction, + sequence: u64, + ready: bool, ) -> Result { let now = now_millis()?; - let bytes = signed_correlation(&routed.world, transaction, sequence, true)?; + let bytes = signed_correlation(&routed.world, transaction, sequence, ready)?; let authenticated = routed.world.engine.authenticate_topology_bytes( &ControlSnapshot::read(&routed.world.state_store)?, transaction, @@ -15011,14 +15026,18 @@ mod tests { let snapshot = ControlSnapshot::read(&routed.world.state_store)?; let current = snapshot.admitted.first().context("nothing was admitted")?; - let receipt = odin_receipt_for(&routed, &at_routing, 9)?; + // Receipts that would not survive being re-proved: authentic, but + // not Ready. Boot re-proves against the current Odin authority and + // requires exact semantic Ready, never what a generation stores, so + // this record is only bootable if boot does not re-prove it. + let receipt = odin_receipt_with(&routed, &at_routing, 9, false)?; let mut legacy = current.value.clone(); legacy.ready = ReadinessEvidence::OdinCorrelated { evidence: receipt.clone(), }; legacy.latest_odin_observation = Some(receipt); - // Receipts that would not authenticate if they were re-proved: the - // authority is another key's. Held generations are not re-proved. + // The stored authority is present because an Odin-tagged record + // carries one; it is not what boot reads. let stranger = cultnet_rs::enroll_service_identity_at::( &routed.world.root.join("identities/stranger.cc"), )?; @@ -15205,6 +15224,43 @@ mod tests { Ok(()) } + #[test] + fn a_stateful_target_that_provides_the_rendezvous_is_observed_directly_whatever_it_is_named() + -> Result<()> { + let provider = build_routed_world(Odin::Unreachable, 1, DeploymentPhase::Warming, true, true)?; + let transaction = provider.transaction()?; + assert_eq!(transaction.target, "service"); + assert!(transaction.expected.as_ref().unwrap().write_lease_required); + provider.stub.set_state("warming"); + *provider.stub.reply.lock().unwrap() = Reply::FirstOdinWarming; + let challenged_at = now_millis()?; + let answer = provider.stub.answer("warming-probe")?; + provider.world.engine.authenticate_first_odin_warming_presence( + &transaction, + "warming-probe", + challenged_at, + now_millis()?, + &answer, + )?; + + // The reverse: named odin, stateful, but nothing provides the + // rendezvous. + let stateful = stateful_routed_world(Odin::Unreachable, DeploymentPhase::Warming)?; + let mut named = stateful.transaction()?; + assert!(named.expected.as_ref().unwrap().write_lease_required); + named.target = "odin".into(); + let error = stateful + .world + .engine + .authenticate_first_odin_warming_presence(&named, "warming-probe", 1, 2, &[1]) + .expect_err("a stateful target named odin that does not provide the rendezvous"); + assert!( + format!("{error:#}").contains("reserved for a stateful Odin incarnation"), + "{error:#}" + ); + Ok(()) + } + // ----------------------------------------------------------------- // A bad answer is an error. Only silence waits. // ----------------------------------------------------------------- diff --git a/src/drivers.rs b/src/drivers.rs index 749ac22..edb4699 100644 --- a/src/drivers.rs +++ b/src/drivers.rs @@ -8350,7 +8350,7 @@ mod tests { "a body that is not CultNet", ); assert_refused( - challenge(scripted_peer(|_| b"HTTP/1.1 200 OK + challenge(scripted_peer(|_| b"HTTP/1.1 200 OK Content-Le".to_vec()), |_| {}), "a response that never finished its headers", ); @@ -8391,6 +8391,44 @@ Content-Le".to_vec()), |_| {}), ); } + /// The candidate path renders the Expected first, and rendering parses the + /// same endpoints, so it never reaches the parse in the challenge. The + /// stable path does not render: a bound stable endpoint that is not a plain + /// host and port is caught by the challenge's own parse, and it is a + /// configuration error, not a listener that has not answered yet. + #[test] + fn a_stable_endpoint_that_does_not_parse_is_an_error_not_a_wait() { + let temp = tempfile::tempdir().expect("a temporary directory"); + let driver = NginxRouteDriver::new(RouteBinding { + driver: RouteDriver::NginxStreamTcp, + route_id: "service".into(), + stable_endpoint: "http://127.0.0.1:17999".into(), + private_host: "127.0.0.1".into(), + private_port_start: 17998, + private_port_end: 17998, + config_path: temp.path().join("service.conf"), + reload_unit: "nginx.service".into(), + }); + let mut candidate = expected(); + candidate.route = Some(cultnet_rs::IdunnExpectedRoute { + route_id: "service".into(), + transport: "http".into(), + stable_endpoint: "http://127.0.0.1:17999".into(), + candidate_endpoint: "http://127.0.0.1:17998".into(), + }); + for endpoint in [ + "http://127.0.0.1", + "http://127.0.0.1:0", + "http://127.0.0.1:17999/path", + "tcp://127.0.0.1:17999", + ] { + assert_refused( + driver.request_runtime_presence_at(&candidate, "stable-probe", endpoint), + endpoint, + ); + } + } + #[test] fn route_connect_retries_connection_refused_until_listener_is_ready() -> Result<()> { let reservation = std::net::TcpListener::bind("127.0.0.1:0")?;