#![cfg(all(feature = "net", feature = "cortex", feature = "fixtures"))]
use std::net::SocketAddr;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::Arc;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use bytes::Bytes;
use net::adapter::net::behavior::capability::CapabilitySet;
use net::adapter::net::behavior::org::{OrgId, OrgKeypair, OrgMembershipCert, OrgRevocationBundle};
use net::adapter::net::behavior::org_admission::OrgAdmission;
use net::adapter::net::behavior::org_authority::NodeAuthority;
use net::adapter::net::behavior::org_grant::{
CapabilityAuthorityId, DispatcherScope, GrantRights, GrantTargetScope, OrgCapabilityGrant,
OrgDispatcherGrant,
};
use net::adapter::net::behavior::subnet::{SubnetId as SubnetClaimTag, SUBNET_TAG_PREFIX};
use net::adapter::net::cortex::{
RpcContext, RpcHandler, RpcHandlerError, RpcResponsePayload, RpcStatus,
};
use net::adapter::net::identity::EntityId;
use net::adapter::net::mesh_rpc::{CallOptions, OrgProofIntent, RpcError, ServeError};
use net::adapter::net::subnet::route_hop::ROUTE_HOP_MAGIC;
use net::adapter::net::subnet::{
build_gateway_context_set, compile_gateway_context, ForwardDenial, GatewayAdvertisement,
SubnetAuthError, SubnetAuthPresentation, SubnetAuthorityConfig, SubnetBoundarySet,
SubnetControlFact, SubnetCredentialSet, SubnetDescriptor, SubnetExportBinding,
SubnetExportPolicy, SubnetFloorRegistry, SubnetGrant, SubnetRef, SubnetRevocationFloor,
SubnetRights, TopologySubnetId, VerifiedSubnetContext,
};
use net::adapter::net::{
ChannelConfig, ChannelConfigRegistry, ChannelId, ChannelName, ChannelPublisher, EntityKeypair,
MeshNode, MeshNodeConfig, NetHeader, OnFailure, PacketFlags, PermissionToken, PublishConfig,
Reliability, RoutingHeader, SocketBufferConfig, SubnetId, SubnetPolicy, SubnetRule, TokenCache,
TokenScope, NONCE_SIZE,
};
use net::error::AdapterError;
use tokio::net::UdpSocket;
const PSK: [u8; 32] = [0x42u8; 32];
const TEST_BUFFER_SIZE: usize = 256 * 1024;
const DAY: u64 = 24 * 60 * 60;
const ORG_ADMISSION_HEADER: &str = "net-org-admission";
const VEHICLE_A_SEED: [u8; 32] = [0xA1; 32];
const VEHICLE_B_SEED: [u8; 32] = [0xA2; 32];
const VB_SUBNET_ROOT_SEED: [u8; 32] = [0xC0; 32];
const VA_SUBNET_ROOT_SEED: [u8; 32] = [0xC5; 32];
const BMW_ORG_SEED: [u8; 32] = [0xB0; 32];
const VEHICLE: &[u8] = &[3];
const PERCEPTION: &[u8] = &[3, 7];
const WORLD_MODEL: &[u8] = &[3, 7, 1];
const CAMERA: &[u8] = &[3, 7, 2];
const RADAR: &[u8] = &[3, 7, 3];
const CHASSIS: &[u8] = &[3, 8];
const BRAKING: &[u8] = &[3, 8, 1];
const CAMERA_SEED: [u8; 32] = [0xA3; 32];
const SERVICE: &str = "perception.roi";
fn unix_now() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("clock")
.as_secs()
}
fn vb_subnet_root() -> EntityKeypair {
EntityKeypair::from_bytes(VB_SUBNET_ROOT_SEED)
}
fn va_subnet_root() -> EntityKeypair {
EntityKeypair::from_bytes(VA_SUBNET_ROOT_SEED)
}
fn bmw() -> OrgKeypair {
OrgKeypair::from_bytes(BMW_ORG_SEED)
}
fn vb_ref(levels: &[u8]) -> SubnetRef {
SubnetRef {
authority: vb_subnet_root().entity_id().clone(),
path: TopologySubnetId::new(levels),
}
}
fn base_config() -> MeshNodeConfig {
let addr: SocketAddr = "127.0.0.1:0".parse().unwrap();
let mut cfg = MeshNodeConfig::new(addr, PSK)
.with_heartbeat_interval(Duration::from_millis(200))
.with_session_timeout(Duration::from_secs(5))
.with_handshake(3, Duration::from_secs(2))
.with_capability_gc_interval(Duration::from_millis(250));
cfg.socket_buffers = SocketBufferConfig {
send_buffer_size: TEST_BUFFER_SIZE,
recv_buffer_size: TEST_BUFFER_SIZE,
};
cfg
}
async fn build_vehicle_b() -> Arc<MeshNode> {
let mut cfg = base_config().with_subnet_authority(SubnetAuthorityConfig {
authority: vb_subnet_root().entity_id().clone(),
roots: vec![vb_subnet_root().entity_id().clone()],
maximum_grant_lifetime_secs: 7 * DAY,
});
cfg.subnet_attachment = Some(TopologySubnetId::new(VEHICLE));
Arc::new(
MeshNode::new(EntityKeypair::from_bytes(VEHICLE_B_SEED), cfg)
.await
.expect("MeshNode::new vehicle B"),
)
}
async fn build_vehicle_a() -> Arc<MeshNode> {
Arc::new(
MeshNode::new(EntityKeypair::from_bytes(VEHICLE_A_SEED), base_config())
.await
.expect("MeshNode::new vehicle A"),
)
}
async fn bring_up(caller: &Arc<MeshNode>, server: &Arc<MeshNode>) {
let a_id = caller.node_id();
let b_id = server.node_id();
let b_pub = *server.public_key();
let b_addr = server.local_addr();
let b_clone = server.clone();
let accept = tokio::spawn(async move { b_clone.accept(a_id).await });
caller
.connect(b_addr, &b_pub, b_id)
.await
.expect("connect failed");
accept
.await
.expect("accept task panicked")
.expect("accept failed");
caller.start();
server.start();
server
.announce_capabilities(CapabilitySet::new())
.await
.expect("server announce");
caller
.announce_capabilities(CapabilitySet::new())
.await
.expect("caller announce");
assert!(
wait_until(Duration::from_secs(5), || {
caller.peer_entity_id(b_id).is_some() && server.peer_entity_id(a_id).is_some()
})
.await,
"entity pins established in both directions",
);
}
async fn wait_until<F: Fn() -> bool>(limit: Duration, cond: F) -> bool {
let start = Instant::now();
while start.elapsed() < limit {
if cond() {
return true;
}
tokio::time::sleep(Duration::from_millis(25)).await;
}
cond()
}
struct ScratchDir(std::path::PathBuf);
impl ScratchDir {
fn fresh(path: std::path::PathBuf) -> Self {
match std::fs::remove_dir_all(&path) {
Ok(()) => {}
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {}
Err(e) => panic!(
"refusing to adopt scratch path {}: stale residue not removable: {e}",
path.display()
),
}
Self(path)
}
}
impl std::ops::Deref for ScratchDir {
type Target = std::path::Path;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl AsRef<std::path::Path> for ScratchDir {
fn as_ref(&self) -> &std::path::Path {
&self.0
}
}
fn install_bmw_authority(server: &Arc<MeshNode>, tag: &str) -> ScratchDir {
let node_entity = server.entity_id().clone();
let node_cert =
OrgMembershipCert::try_issue(&bmw(), node_entity.clone(), 1, 3600).expect("node cert");
let dir = ScratchDir::fresh(
std::env::temp_dir().join(format!("net-subnet-e2e-{tag}-{}", std::process::id())),
);
let authority =
NodeAuthority::adopt(&dir, node_cert, &node_entity, 0, None).expect("adopt authority");
server
.install_node_authority(Arc::new(authority))
.expect("install authority");
dir
}
fn vb_grant_at(
subject: &EntityKeypair,
scope: &[u8],
rights: SubnetRights,
topology_epoch: u32,
generation: u32,
lifetime_secs: u64,
) -> SubnetCredentialSet {
SubnetCredentialSet::Direct(
SubnetGrant::try_issue(
&vb_subnet_root(),
vb_subnet_root().entity_id().clone(),
TopologySubnetId::new(scope),
topology_epoch,
subject.entity_id().clone(),
rights,
generation,
unix_now() - 60,
lifetime_secs,
)
.expect("issue subnet grant"),
)
}
fn vb_grant(subject: &EntityKeypair, scope: &[u8], rights: SubnetRights) -> SubnetCredentialSet {
vb_grant_at(subject, scope, rights, 0, 1, DAY)
}
fn gateway_credentials_with_export(vb_kp: &EntityKeypair) -> Vec<SubnetCredentialSet> {
vec![
vb_grant(
vb_kp,
VEHICLE,
SubnetRights::ATTACH.union(SubnetRights::ROUTE),
),
vb_grant(vb_kp, WORLD_MODEL, SubnetRights::EXPORT),
]
}
fn gateway_credentials_without_export(vb_kp: &EntityKeypair) -> Vec<SubnetCredentialSet> {
vec![vb_grant(
vb_kp,
VEHICLE,
SubnetRights::ATTACH.union(SubnetRights::ROUTE),
)]
}
fn declare_world_model_boundary(vehicle_b: &Arc<MeshNode>, topology_epoch: u32) {
vehicle_b.declare_subnet_boundaries(SubnetBoundarySet::new(
vb_subnet_root().entity_id().clone(),
topology_epoch,
[TopologySubnetId::new(WORLD_MODEL)],
));
}
fn world_model_binding(topology_epoch: u32) -> SubnetExportBinding {
SubnetExportBinding::new(vb_ref(WORLD_MODEL), topology_epoch)
}
fn fleet_intent(provider: EntityId) -> OrgProofIntent {
let caller_kp = EntityKeypair::from_bytes(VEHICLE_A_SEED);
let caller_entity = caller_kp.entity_id().clone();
let cap = CapabilityAuthorityId::for_tag(&format!("nrpc:{SERVICE}"));
let membership =
OrgMembershipCert::try_issue(&bmw(), caller_entity.clone(), 1, 3600).expect("membership");
let dispatcher =
OrgDispatcherGrant::try_issue(&bmw(), caller_entity, DispatcherScope::Exact(cap), 3600)
.expect("dispatcher");
OrgProofIntent {
caller: Arc::new(caller_kp),
membership,
dispatcher,
capability_grant: None,
acting_org: bmw().org_id(),
provider_owner_org: bmw().org_id(),
provider,
capability: cap,
proof_ttl_secs: 30,
}
}
fn call_opts(intent: Option<OrgProofIntent>) -> CallOptions {
CallOptions {
org_proof_intent: intent,
deadline: Some(Instant::now() + Duration::from_secs(5)),
..Default::default()
}
}
struct RoiHandler {
calls: Arc<AtomicUsize>,
attribution_ok: Arc<AtomicBool>,
proof_stripped: Arc<AtomicBool>,
expected_caller: EntityId,
expected_org: OrgId,
expected_provider: EntityId,
}
#[async_trait::async_trait]
impl RpcHandler for RoiHandler {
async fn call(&self, ctx: RpcContext) -> Result<RpcResponsePayload, RpcHandlerError> {
self.calls.fetch_add(1, Ordering::SeqCst);
if let Some(admitted) = ctx.org_admission.as_ref() {
if admitted.caller == self.expected_caller
&& admitted.acting_org == self.expected_org
&& admitted.provider_org == self.expected_org
&& admitted.provider == self.expected_provider
&& admitted.capability == CapabilityAuthorityId::for_tag("nrpc:perception.roi")
{
self.attribution_ok.store(true, Ordering::SeqCst);
}
}
let stripped = !ctx
.payload
.headers
.iter()
.any(|(name, _)| name == ORG_ADMISSION_HEADER);
self.proof_stripped.store(stripped, Ordering::SeqCst);
Ok(RpcResponsePayload {
status: RpcStatus::Ok,
headers: vec![],
body: Bytes::from_static(b"roi-window"),
})
}
}
async fn assert_handler_stays_at(calls: &Arc<AtomicUsize>, baseline: usize, what: &str) {
const SETTLE: Duration = Duration::from_millis(200);
const STEP: Duration = Duration::from_millis(10);
let deadline = Instant::now() + SETTLE;
loop {
let observed = calls.load(Ordering::SeqCst);
assert_eq!(
observed, baseline,
"{what}: the handler RAN ({observed} vs baseline {baseline}) despite the denial",
);
if Instant::now() >= deadline {
return;
}
tokio::time::sleep(STEP).await;
}
}
fn assert_explicit_denial(
result: Result<net::adapter::net::mesh_rpc::RpcReply, RpcError>,
what: &str,
) {
match result {
Err(RpcError::ServerError { status, .. }) => {
assert_eq!(
status, 0x0009,
"{what}: denial must be AdmissionDenied (0x0009), got {status:#06x}",
);
}
Err(other) => panic!(
"{what}: expected an explicit AdmissionDenied ServerError, got {other:?} \
(a Timeout here would be a denial masquerading as a timeout)"
),
Ok(_) => panic!("{what}: the call was ADMITTED — the removed plane did not gate it"),
}
}
struct FleetFixture {
vehicle_a: Arc<MeshNode>,
vehicle_b: Arc<MeshNode>,
vb_kp: EntityKeypair,
provider: EntityId,
calls: Arc<AtomicUsize>,
attribution_ok: Arc<AtomicBool>,
proof_stripped: Arc<AtomicBool>,
policy_allows: Arc<AtomicBool>,
serve: Option<net::adapter::net::mesh_rpc::ServeHandle>,
dir: ScratchDir,
}
async fn connect_no_start(initiator: &Arc<MeshNode>, responder: &Arc<MeshNode>) {
let i_id = initiator.node_id();
let r_id = responder.node_id();
let r_pub = *responder.public_key();
let r_addr = responder.local_addr();
let r = responder.clone();
let accept = tokio::spawn(async move { r.accept(i_id).await });
initiator
.connect(r_addr, &r_pub, r_id)
.await
.expect("connect failed");
accept
.await
.expect("accept task panicked")
.expect("accept failed");
}
async fn announce_and_pin(hub: &Arc<MeshNode>, spokes: &[&Arc<MeshNode>]) {
hub.announce_capabilities(CapabilitySet::new())
.await
.expect("hub announce");
for s in spokes {
s.announce_capabilities(CapabilitySet::new())
.await
.expect("spoke announce");
}
let hub_id = hub.node_id();
let spoke_ids: Vec<u64> = spokes.iter().map(|s| s.node_id()).collect();
assert!(
wait_until(Duration::from_secs(5), || {
spoke_ids.iter().all(|id| hub.peer_entity_id(*id).is_some())
&& spokes.iter().all(|s| s.peer_entity_id(hub_id).is_some())
})
.await,
"entity pins established in both directions across the topology",
);
}
async fn provision_fleet(
vehicle_a: Arc<MeshNode>,
vehicle_b: Arc<MeshNode>,
tag: &str,
) -> FleetFixture {
let vb_kp = EntityKeypair::from_bytes(VEHICLE_B_SEED);
let dir = install_bmw_authority(&vehicle_b, tag);
let provider = vehicle_b.entity_id().clone();
declare_world_model_boundary(&vehicle_b, 0);
vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_with_export(&vb_kp))
.expect("install gateway credentials with EXPORT");
let policy_allows = Arc::new(AtomicBool::new(true));
let policy_probe = policy_allows.clone();
let calls = Arc::new(AtomicUsize::new(0));
let attribution_ok = Arc::new(AtomicBool::new(false));
let proof_stripped = Arc::new(AtomicBool::new(false));
let serve = vehicle_b
.serve_rpc_subnet_exported(
SERVICE,
Arc::new(RoiHandler {
calls: calls.clone(),
attribution_ok: attribution_ok.clone(),
proof_stripped: proof_stripped.clone(),
expected_caller: vehicle_a.entity_id().clone(),
expected_org: bmw().org_id(),
expected_provider: provider.clone(),
}),
OrgAdmission::OwnerDelegated,
world_model_binding(0),
Arc::new(move |_| policy_probe.load(Ordering::SeqCst)),
)
.expect("serve perception.roi subnet-exported");
FleetFixture {
vehicle_a,
vehicle_b,
vb_kp,
provider,
calls,
attribution_ok,
proof_stripped,
policy_allows,
serve: Some(serve),
dir,
}
}
async fn fleet_fixture(tag: &str) -> FleetFixture {
let vehicle_b = build_vehicle_b().await;
let vehicle_a = build_vehicle_a().await;
bring_up(&vehicle_a, &vehicle_b).await;
provision_fleet(vehicle_a, vehicle_b, tag).await
}
async fn fleet_fixture_with_peers(
tag: &str,
seeds: &[[u8; 32]],
) -> (FleetFixture, Vec<Arc<MeshNode>>) {
let vehicle_b = build_vehicle_b().await;
let vehicle_a = build_vehicle_a().await;
let mut peers = Vec::with_capacity(seeds.len());
for seed in seeds {
peers.push(build_peer(*seed).await);
}
connect_no_start(&vehicle_a, &vehicle_b).await;
for p in &peers {
connect_no_start(p, &vehicle_b).await;
}
vehicle_a.start();
vehicle_b.start();
for p in &peers {
p.start();
}
let mut spokes: Vec<&Arc<MeshNode>> = vec![&vehicle_a];
spokes.extend(peers.iter());
announce_and_pin(&vehicle_b, &spokes).await;
let fixture = provision_fleet(vehicle_a, vehicle_b, tag).await;
(fixture, peers)
}
async fn fleet_fixture_with_camera(tag: &str) -> (FleetFixture, Arc<MeshNode>) {
let (f, mut peers) = fleet_fixture_with_peers(tag, &[CAMERA_SEED]).await;
(f, peers.remove(0))
}
fn control_channel() -> ChannelName {
ChannelName::new("vehicle-b/subnet/control").unwrap()
}
const CONTROL_PUB_SEED: [u8; 32] = [0xA5; 32];
fn publisher_for(name: ChannelName) -> ChannelPublisher {
ChannelPublisher::new(
name,
PublishConfig {
reliability: Reliability::FireAndForget,
on_failure: OnFailure::BestEffort,
max_inflight: 16,
},
)
}
async fn build_vehicle_b_with_control() -> Arc<MeshNode> {
let mut cfg = base_config()
.with_subnet_authority(SubnetAuthorityConfig {
authority: vb_subnet_root().entity_id().clone(),
roots: vec![vb_subnet_root().entity_id().clone()],
maximum_grant_lifetime_secs: 7 * DAY,
})
.with_subnet_control_channel(control_channel());
cfg.subnet_attachment = Some(TopologySubnetId::new(VEHICLE));
Arc::new(
MeshNode::new(EntityKeypair::from_bytes(VEHICLE_B_SEED), cfg)
.await
.expect("MeshNode::new vehicle B with control channel"),
)
}
async fn fleet_fixture_with_control(tag: &str) -> (FleetFixture, Arc<MeshNode>, Arc<MeshNode>) {
let vehicle_b = build_vehicle_b_with_control().await;
let vehicle_a = build_vehicle_a().await;
let camera = build_peer(CAMERA_SEED).await;
let publisher = build_peer(CONTROL_PUB_SEED).await;
connect_no_start(&vehicle_a, &vehicle_b).await;
connect_no_start(&camera, &vehicle_b).await;
connect_no_start(&publisher, &vehicle_b).await;
vehicle_a.start();
vehicle_b.start();
camera.start();
publisher.start();
announce_and_pin(&vehicle_b, &[&vehicle_a, &camera, &publisher]).await;
vehicle_b
.subscribe_channel(publisher.node_id(), control_channel())
.await
.expect("subscribe to the control channel");
let f = provision_fleet(vehicle_a, vehicle_b, tag).await;
(f, camera, publisher)
}
async fn publish_control_fact_and_await_epoch(
publisher: &Arc<MeshNode>,
vehicle_b: &Arc<MeshNode>,
bytes: Vec<u8>,
expect_epoch: u64,
) -> bool {
publisher
.publish(&publisher_for(control_channel()), Bytes::from(bytes))
.await
.expect("publish control fact");
wait_until(Duration::from_secs(5), || {
vehicle_b
.subnet_floor_registry()
.auth_epoch(vb_subnet_root().entity_id())
== expect_epoch
})
.await
}
impl FleetFixture {
async fn call(
&self,
with_proof: bool,
) -> Result<net::adapter::net::mesh_rpc::RpcReply, RpcError> {
let intent = with_proof.then(|| fleet_intent(self.provider.clone()));
self.vehicle_a
.call(
self.vehicle_b.node_id(),
SERVICE,
Bytes::from_static(b"roi?"),
call_opts(intent),
)
.await
}
fn assert_no_va_subnet_context(&self) {
assert!(
self.vehicle_b
.subnet_context_for(self.vehicle_a.node_id())
.is_none(),
"Vehicle A must never acquire a Vehicle B subnet context",
);
}
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn fleet_exported_provider_requires_gateway_export_and_org_authority() {
let f = fleet_fixture("four-plane").await;
let reply = f
.call(true)
.await
.expect("the fully-credentialed fleet call is admitted");
assert_eq!(reply.body.as_ref(), b"roi-window", "exact reply body");
assert_eq!(
f.calls.load(Ordering::SeqCst),
1,
"handler ran exactly once"
);
assert!(
f.attribution_ok.load(Ordering::SeqCst),
"attribution names Vehicle A, BMW (acting and provider org), Vehicle B, \
and nrpc:perception.roi exactly",
);
assert!(
f.proof_stripped.load(Ordering::SeqCst),
"raw proof material was stripped before the handler view",
);
f.assert_no_va_subnet_context();
f.vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_without_export(&f.vb_kp))
.expect("reinstall gateway credentials WITHOUT export");
let baseline = f.calls.load(Ordering::SeqCst);
assert_explicit_denial(f.call(true).await, "gateway-authority inverse");
assert_handler_stays_at(&f.calls, baseline, "gateway-authority inverse").await;
f.vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_with_export(&f.vb_kp))
.expect("restore gateway credentials with EXPORT");
let baseline = f.calls.load(Ordering::SeqCst);
assert_explicit_denial(f.call(false).await, "organization inverse");
assert_handler_stays_at(&f.calls, baseline, "organization inverse").await;
f.policy_allows.store(false, Ordering::SeqCst);
let baseline = f.calls.load(Ordering::SeqCst);
assert_explicit_denial(f.call(true).await, "provider inverse");
assert_handler_stays_at(&f.calls, baseline, "provider inverse").await;
f.policy_allows.store(true, Ordering::SeqCst);
let reply = f
.call(true)
.await
.expect("restored conjunction admits again");
assert_eq!(reply.body.as_ref(), b"roi-window");
f.assert_no_va_subnet_context();
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn exported_registration_requires_exact_boundary_and_exact_export() {
let vehicle_b = build_vehicle_b().await;
let vehicle_a = build_vehicle_a().await;
let vb_kp = EntityKeypair::from_bytes(VEHICLE_B_SEED);
bring_up(&vehicle_a, &vehicle_b).await;
let _dir = install_bmw_authority(&vehicle_b, "reg-shape");
let dark = Arc::new(AtomicUsize::new(0));
let serve = |vb: &Arc<MeshNode>, binding: SubnetExportBinding| {
vb.serve_rpc_subnet_exported(
SERVICE,
Arc::new(RoiHandler {
calls: dark.clone(),
attribution_ok: Arc::new(AtomicBool::new(false)),
proof_stripped: Arc::new(AtomicBool::new(false)),
expected_caller: vehicle_a.entity_id().clone(),
expected_org: bmw().org_id(),
expected_provider: vb.entity_id().clone(),
}),
OrgAdmission::OwnerDelegated,
binding,
Arc::new(|_| true),
)
};
vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_with_export(&vb_kp))
.expect("install credentials");
assert!(
matches!(
serve(&vehicle_b, world_model_binding(0)),
Err(ServeError::SubnetExportUnauthorized(_))
),
"registration must fail with no declared boundary set",
);
vehicle_b.declare_subnet_boundaries(SubnetBoundarySet::new(
vb_subnet_root().entity_id().clone(),
0,
[TopologySubnetId::new(CAMERA)],
));
assert!(
matches!(
serve(&vehicle_b, world_model_binding(0)),
Err(ServeError::SubnetExportUnauthorized(_))
),
"a binding must name an exactly-declared boundary",
);
declare_world_model_boundary(&vehicle_b, 0);
vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_without_export(&vb_kp))
.expect("install without export");
assert!(
matches!(
serve(&vehicle_b, world_model_binding(0)),
Err(ServeError::SubnetExportUnauthorized(_))
),
"registration must fail without exact EXPORT authority",
);
vehicle_b
.install_subnet_gateway_credentials(&[vb_grant(
&vb_kp,
VEHICLE,
SubnetRights::ATTACH
.union(SubnetRights::ROUTE)
.union(SubnetRights::EXPORT),
)])
.expect("install ancestor-export set");
assert!(
matches!(
serve(&vehicle_b, world_model_binding(0)),
Err(ServeError::SubnetExportUnauthorized(_))
),
"EXPORT at VEHICLE must not satisfy a service bound to WORLD_MODEL",
);
vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_with_export(&vb_kp))
.expect("restore canonical credentials");
let foreign = SubnetExportBinding::new(
SubnetRef {
authority: va_subnet_root().entity_id().clone(),
path: TopologySubnetId::new(WORLD_MODEL),
},
0,
);
assert!(
matches!(
serve(&vehicle_b, foreign),
Err(ServeError::SubnetExportUnauthorized(_))
),
"equal path bits under a different authority must not satisfy",
);
let handle = serve(&vehicle_b, world_model_binding(0)).expect("canonical shape registers");
drop(handle);
assert_eq!(
dark.load(Ordering::SeqCst),
0,
"no handler ran during shape checks"
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn live_exported_service_darkens_on_authority_movement_and_recovers() {
let f = fleet_fixture("darkness").await;
f.call(true).await.expect("baseline admits");
f.vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_without_export(&f.vb_kp))
.expect("replace without export");
let baseline = f.calls.load(Ordering::SeqCst);
assert_explicit_denial(f.call(true).await, "credential replacement");
assert_handler_stays_at(&f.calls, baseline, "credential replacement").await;
f.vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_with_export(&f.vb_kp))
.expect("restore export");
f.call(true)
.await
.expect("recovers after credential restore");
f.vehicle_b
.declare_subnet_boundaries(SubnetBoundarySet::new(
vb_subnet_root().entity_id().clone(),
0,
[TopologySubnetId::new(CAMERA)],
));
let baseline = f.calls.load(Ordering::SeqCst);
assert_explicit_denial(f.call(true).await, "boundary replacement");
assert_handler_stays_at(&f.calls, baseline, "boundary replacement").await;
declare_world_model_boundary(&f.vehicle_b, 0);
f.call(true).await.expect("recovers after boundary restore");
let floor = SubnetRevocationFloor::try_issue(
&vb_subnet_root(),
vb_ref(VEHICLE),
0,
5, 1,
unix_now(),
)
.expect("issue floor");
assert!(f.vehicle_b.apply_subnet_floor(&floor).expect("apply floor"));
let baseline = f.calls.load(Ordering::SeqCst);
assert_explicit_denial(f.call(true).await, "revocation floor");
assert_handler_stays_at(&f.calls, baseline, "revocation floor").await;
let fresh = vec![
vb_grant_at(
&f.vb_kp,
VEHICLE,
SubnetRights::ATTACH.union(SubnetRights::ROUTE),
0,
6,
DAY,
),
vb_grant_at(&f.vb_kp, WORLD_MODEL, SubnetRights::EXPORT, 0, 6, DAY),
];
f.vehicle_b
.install_subnet_gateway_credentials(&fresh)
.expect("install above-floor credentials");
f.call(true)
.await
.expect("recovers with above-floor credentials");
f.assert_no_va_subnet_context();
let short = vec![
vb_grant_at(
&f.vb_kp,
VEHICLE,
SubnetRights::ATTACH.union(SubnetRights::ROUTE),
0,
6,
62, ),
vb_grant_at(&f.vb_kp, WORLD_MODEL, SubnetRights::EXPORT, 0, 6, 62),
];
f.vehicle_b
.install_subnet_gateway_credentials(&short)
.expect("install short-lived credentials");
f.call(true)
.await
.expect("short-lived set admits while live");
let deadline = tokio::time::Instant::now() + Duration::from_secs(8);
let mut expired_denied = false;
while tokio::time::Instant::now() < deadline {
match f.call(true).await {
Err(RpcError::ServerError { status: 0x0009, .. }) => {
expired_denied = true;
break;
}
_ => tokio::time::sleep(Duration::from_millis(100)).await,
}
}
assert!(
expired_denied,
"an expired gateway credential set must darken the live registration",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn topology_epoch_movement_darkens_until_explicit_reregistration() {
let f = fleet_fixture("epoch").await;
f.call(true).await.expect("baseline admits");
let next_epoch = f.vehicle_b.advance_subnet_topology_epoch();
let baseline = f.calls.load(Ordering::SeqCst);
assert_explicit_denial(f.call(true).await, "topology epoch advance");
assert_handler_stays_at(&f.calls, baseline, "topology epoch advance").await;
declare_world_model_boundary(&f.vehicle_b, next_epoch);
let fresh = vec![
vb_grant_at(
&f.vb_kp,
VEHICLE,
SubnetRights::ATTACH.union(SubnetRights::ROUTE),
next_epoch,
1,
DAY,
),
vb_grant_at(
&f.vb_kp,
WORLD_MODEL,
SubnetRights::EXPORT,
next_epoch,
1,
DAY,
),
];
f.vehicle_b
.install_subnet_gateway_credentials(&fresh)
.expect("install fresh-epoch credentials");
let baseline = f.calls.load(Ordering::SeqCst);
assert_explicit_denial(f.call(true).await, "old binding under new epoch");
assert_handler_stays_at(&f.calls, baseline, "old binding under new epoch").await;
let mut f = f;
drop(f.serve.take());
let policy_probe = f.policy_allows.clone();
let _serve2 = f
.vehicle_b
.serve_rpc_subnet_exported(
SERVICE,
Arc::new(RoiHandler {
calls: f.calls.clone(),
attribution_ok: f.attribution_ok.clone(),
proof_stripped: f.proof_stripped.clone(),
expected_caller: f.vehicle_a.entity_id().clone(),
expected_org: bmw().org_id(),
expected_provider: f.provider.clone(),
}),
OrgAdmission::OwnerDelegated,
world_model_binding(next_epoch),
Arc::new(move |_| policy_probe.load(Ordering::SeqCst)),
)
.expect("re-register under the new epoch");
f.call(true)
.await
.expect("explicit re-registration recovers");
f.assert_no_va_subnet_context();
}
#[test]
fn gateway_compiler_accepts_delegated_descendant_export_but_not_attach() {
let vb_kp = EntityKeypair::from_bytes(VEHICLE_B_SEED);
let config = SubnetAuthorityConfig {
authority: vb_subnet_root().entity_id().clone(),
roots: vec![vb_subnet_root().entity_id().clone()],
maximum_grant_lifetime_secs: 7 * DAY,
};
let floors = SubnetFloorRegistry::new();
let attachment = TopologySubnetId::new(VEHICLE);
let compile = |set: &SubnetCredentialSet| {
compile_gateway_context(
set,
vb_kp.entity_id(),
attachment,
&config,
0,
&floors,
unix_now(),
30,
)
};
let attach_route = compile(&vb_grant(
&vb_kp,
VEHICLE,
SubnetRights::ATTACH.union(SubnetRights::ROUTE),
))
.expect("ATTACH/ROUTE at the attachment compiles");
let export_only = compile(&vb_grant(&vb_kp, WORLD_MODEL, SubnetRights::EXPORT))
.expect("delegated EXPORT-only at an exact descendant compiles");
build_gateway_context_set(
vb_subnet_root().entity_id(),
vec![attach_route, export_only],
)
.expect("the canonical Vehicle B set publishes");
assert_eq!(
compile(&vb_grant(&vb_kp, CAMERA, SubnetRights::ATTACH)).err(),
Some(SubnetAuthError::ScopeNotAncestor),
"an ATTACH-bearing credential must still contain the attachment",
);
assert_eq!(
compile(&vb_grant(
&vb_kp,
WORLD_MODEL,
SubnetRights::ATTACH.union(SubnetRights::EXPORT),
))
.err(),
Some(SubnetAuthError::ScopeNotAncestor),
"ATTACH | EXPORT at [3,7,1] under attachment [3] must be refused \
even though EXPORT alone at [3,7,1] compiles",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn publication_of_either_member_invalidates_captured_export_facts() {
use net::adapter::net::behavior::admission_clock::ClockSample;
use net::adapter::net::org_admission_gate::verify_subnet_export;
let f = fleet_fixture("coherent-stamp").await;
let binding = world_model_binding(0);
let facts =
verify_subnet_export(&f.vehicle_b, &binding, &ClockSample::now()).expect("capture facts");
assert!(
facts.is_current(&f.vehicle_b),
"freshly captured facts are current"
);
f.vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_with_export(&f.vb_kp))
.expect("republish identical credentials");
assert!(
!facts.is_current(&f.vehicle_b),
"captured facts must be invalidated by a credential publication",
);
let facts =
verify_subnet_export(&f.vehicle_b, &binding, &ClockSample::now()).expect("recapture");
assert!(facts.is_current(&f.vehicle_b));
declare_world_model_boundary(&f.vehicle_b, 0);
assert!(
!facts.is_current(&f.vehicle_b),
"captured facts must be invalidated by a boundary publication",
);
f.call(true)
.await
.expect("still admitted after republication");
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn concurrent_publication_loses_neither_authority_surface() {
let vehicle_b = build_vehicle_b().await;
let vb_kp = EntityKeypair::from_bytes(VEHICLE_B_SEED);
const ROUNDS: usize = 200;
let b1 = vehicle_b.clone();
let k1 = vb_kp.clone();
let creds = tokio::task::spawn_blocking(move || {
for i in 0..ROUNDS {
let set = if i % 2 == 0 {
gateway_credentials_without_export(&k1)
} else {
gateway_credentials_with_export(&k1)
};
b1.install_subnet_gateway_credentials(&set)
.expect("install");
}
b1.install_subnet_gateway_credentials(&gateway_credentials_with_export(&k1))
.expect("final install");
});
let b2 = vehicle_b.clone();
let bounds = tokio::task::spawn_blocking(move || {
for i in 0..ROUNDS {
let path = if i % 2 == 0 { CAMERA } else { WORLD_MODEL };
b2.declare_subnet_boundaries(SubnetBoundarySet::new(
vb_subnet_root().entity_id().clone(),
0,
[TopologySubnetId::new(path)],
));
}
declare_world_model_boundary(&b2, 0);
});
creds.await.expect("credential writer");
bounds.await.expect("boundary writer");
let gateway = vehicle_b
.subnet_gateway_contexts()
.expect("gateway member survived the storm");
assert_eq!(
gateway.entries().len(),
2,
"the credential writer's FINAL two-entry set must survive the boundary storm",
);
let boundaries = vehicle_b
.subnet_boundaries()
.expect("boundary member survived the storm");
assert_eq!(
boundaries.boundaries(),
&[TopologySubnetId::new(WORLD_MODEL)],
"the boundary writer's FINAL world-model set must survive the credential storm",
);
}
#[cfg(feature = "fixtures")]
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn a_held_stale_capture_cannot_lose_the_concurrent_publication() {
let vehicle_b = build_vehicle_b().await;
let vb_kp = EntityKeypair::from_bytes(VEHICLE_B_SEED);
vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_without_export(&vb_kp))
.expect("install G0");
vehicle_b.declare_subnet_boundaries(SubnetBoundarySet::new(
vb_subnet_root().entity_id().clone(),
0,
[TopologySubnetId::new(CAMERA)],
));
let captured = Arc::new(std::sync::Barrier::new(2));
let release = Arc::new(std::sync::Barrier::new(2));
let hook_calls = Arc::new(AtomicUsize::new(0));
let b = vehicle_b.clone();
let (cap, rel, calls) = (captured.clone(), release.clone(), hook_calls.clone());
let schedule = tokio::task::spawn_blocking(move || {
let writer_b = b.clone();
let boundary_writer = std::thread::spawn(move || {
writer_b.test_declare_subnet_boundaries_paced(
SubnetBoundarySet::new(
vb_subnet_root().entity_id().clone(),
0,
[TopologySubnetId::new(WORLD_MODEL)],
),
&|| {
if calls.fetch_add(1, Ordering::SeqCst) == 0 {
cap.wait();
rel.wait();
}
},
);
});
captured.wait();
b.install_subnet_gateway_credentials(&gateway_credentials_with_export(
&EntityKeypair::from_bytes(VEHICLE_B_SEED),
))
.expect("publish G1 mid-window");
release.wait();
boundary_writer.join().expect("boundary writer");
});
schedule.await.expect("schedule");
let observed_hook_calls = hook_calls.load(Ordering::SeqCst);
assert!(
observed_hook_calls >= 2,
"the boundary writer must LOSE its stale compare-and-swap and re-capture (saw {observed_hook_calls} hook call(s)): a single capture means its stale view was stored verbatim over the gateway publication",
);
assert_eq!(
vehicle_b
.subnet_gateway_contexts()
.expect("gateway member present")
.entries()
.len(),
2,
"G1 must survive the boundary writer's held stale capture",
);
assert_eq!(
vehicle_b
.subnet_boundaries()
.expect("boundary member present")
.boundaries(),
&[TopologySubnetId::new(WORLD_MODEL)],
"B1 must land beside the surviving G1",
);
let captured_b = Arc::new(std::sync::Barrier::new(2));
let release_b = Arc::new(std::sync::Barrier::new(2));
let gw_hook_calls = Arc::new(AtomicUsize::new(0));
let b = vehicle_b.clone();
let (cap_b, rel_b, gw_calls) = (captured_b.clone(), release_b.clone(), gw_hook_calls.clone());
let schedule_b = tokio::task::spawn_blocking(move || {
let writer_b = b.clone();
let gateway_writer = std::thread::spawn(move || {
writer_b
.test_install_subnet_gateway_credentials_paced(
&gateway_credentials_without_export(&EntityKeypair::from_bytes(VEHICLE_B_SEED)),
&|| {
if gw_calls.fetch_add(1, Ordering::SeqCst) == 0 {
cap_b.wait();
rel_b.wait();
}
},
)
.expect("paced gateway publish");
});
captured_b.wait();
b.declare_subnet_boundaries(SubnetBoundarySet::new(
vb_subnet_root().entity_id().clone(),
0,
[TopologySubnetId::new(CAMERA)],
));
release_b.wait();
gateway_writer.join().expect("gateway writer");
});
schedule_b.await.expect("schedule B");
let observed_gw_calls = gw_hook_calls.load(Ordering::SeqCst);
assert!(
observed_gw_calls >= 2,
"the GATEWAY writer must LOSE its stale compare-and-swap and re-capture (saw {observed_gw_calls} hook call(s)): a single capture means its stale view was stored verbatim over the boundary publication",
);
assert_eq!(
vehicle_b
.subnet_gateway_contexts()
.expect("gateway member present")
.entries()
.len(),
1,
"G2 must land beside the surviving B2",
);
assert_eq!(
vehicle_b
.subnet_boundaries()
.expect("boundary member present")
.boundaries(),
&[TopologySubnetId::new(CAMERA)],
"B2 must survive the gateway writer's held stale capture",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn provider_authority_churn_never_charges_the_caller() {
use net::adapter::net::behavior::org_admission_replay::AdmissionRateLimitConfig;
let vehicle_b = {
let mut cfg = base_config()
.with_subnet_authority(SubnetAuthorityConfig {
authority: vb_subnet_root().entity_id().clone(),
roots: vec![vb_subnet_root().entity_id().clone()],
maximum_grant_lifetime_secs: 7 * DAY,
})
.with_admission_rate_limit(AdmissionRateLimitConfig {
max_failed_per_peer: 2,
refill_per_sec: 1,
max_tracked_peers: 64,
});
cfg.subnet_attachment = Some(TopologySubnetId::new(VEHICLE));
Arc::new(
MeshNode::new(EntityKeypair::from_bytes(VEHICLE_B_SEED), cfg)
.await
.expect("MeshNode::new vehicle B"),
)
};
let vehicle_a = build_vehicle_a().await;
let vb_kp = EntityKeypair::from_bytes(VEHICLE_B_SEED);
bring_up(&vehicle_a, &vehicle_b).await;
let _dir = install_bmw_authority(&vehicle_b, "limiter-churn");
let provider = vehicle_b.entity_id().clone();
declare_world_model_boundary(&vehicle_b, 0);
vehicle_b
.install_subnet_gateway_credentials(&gateway_credentials_with_export(&vb_kp))
.expect("install credentials");
let calls = Arc::new(AtomicUsize::new(0));
let _serve = vehicle_b
.serve_rpc_subnet_exported(
SERVICE,
Arc::new(RoiHandler {
calls: calls.clone(),
attribution_ok: Arc::new(AtomicBool::new(false)),
proof_stripped: Arc::new(AtomicBool::new(false)),
expected_caller: vehicle_a.entity_id().clone(),
expected_org: bmw().org_id(),
expected_provider: provider.clone(),
}),
OrgAdmission::OwnerDelegated,
world_model_binding(0),
Arc::new(|_| true),
)
.expect("serve");
let stop = Arc::new(AtomicBool::new(false));
let churn_stop = stop.clone();
let churn_b = vehicle_b.clone();
let churn_kp = vb_kp.clone();
let churn = tokio::task::spawn_blocking(move || {
while !churn_stop.load(Ordering::SeqCst) {
churn_b
.install_subnet_gateway_credentials(&gateway_credentials_with_export(&churn_kp))
.expect("churn republish");
}
});
let mut denials = 0usize;
let mut admits = 0usize;
for _ in 0..300 {
if denials >= 8 {
break;
}
match vehicle_a
.call(
vehicle_b.node_id(),
SERVICE,
Bytes::from_static(b"roi?"),
call_opts(Some(fleet_intent(provider.clone()))),
)
.await
{
Ok(_) => admits += 1,
Err(RpcError::ServerError { status: 0x0009, .. }) => denials += 1,
Err(other) => panic!("churn denial must be explicit, got {other:?}"),
}
}
stop.store(true, Ordering::SeqCst);
churn.await.expect("churn writer");
assert!(
denials >= 8,
"the storm produced only {denials} stability denials in 300 calls — \
the witness needs the mid-verification window to be hit",
);
let reply = vehicle_a
.call(
vehicle_b.node_id(),
SERVICE,
Bytes::from_static(b"roi?"),
call_opts(Some(fleet_intent(provider.clone()))),
)
.await
.expect(
"a caller that only ever presented valid proofs must not be \
throttled by the provider's own authority churn",
);
assert_eq!(reply.body.as_ref(), b"roi-window");
assert_eq!(
calls.load(Ordering::SeqCst),
admits + 1,
"the handler ran exactly once per ADMITTED call — every churn \
denial left it dark",
);
}
async fn build_peer(seed: [u8; 32]) -> Arc<MeshNode> {
Arc::new(
MeshNode::new(EntityKeypair::from_bytes(seed), base_config())
.await
.expect("MeshNode::new peer"),
)
}
async fn try_admit_vb(
verifier: &Arc<MeshNode>,
peer: &Arc<MeshNode>,
peer_kp: &EntityKeypair,
scope: &[u8],
attachment: &[u8],
rights: SubnetRights,
) -> Result<VerifiedSubnetContext, SubnetAuthError> {
let set = vb_grant(peer_kp, scope, rights);
let node_id = peer.node_id();
let nonce = verifier
.issue_subnet_challenge(node_id)
.expect("verifier issues a challenge");
let session_id = verifier
.peer_session_id(node_id)
.expect("the peer has a live session");
let presentation = SubnetAuthPresentation::try_issue(
peer_kp,
set.credential_set_hash(),
session_id,
verifier.entity_id().clone(),
nonce,
vb_ref(attachment),
rights,
)
.expect("issue presentation");
verifier.admit_subnet_session(node_id, &presentation, &set)
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn vehicle_internal_authority_is_hierarchical() {
let vehicle_b = build_vehicle_b().await;
let camera = build_peer(CAMERA_SEED).await;
let camera_kp = EntityKeypair::from_bytes(CAMERA_SEED);
bring_up(&camera, &vehicle_b).await;
let ctx = try_admit_vb(
&vehicle_b,
&camera,
&camera_kp,
CAMERA,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect("evidence 6: the camera attaches at its own domain");
assert_eq!(ctx.attachment, TopologySubnetId::new(CAMERA));
assert_eq!(ctx.scope, TopologySubnetId::new(CAMERA));
for (target, what) in [
(PERCEPTION, "upward to its parent"),
(VEHICLE, "upward to the vehicle root"),
(RADAR, "sideways to radar"),
(CHASSIS, "sideways to chassis"),
(BRAKING, "sideways into the chassis subtree"),
] {
assert_eq!(
try_admit_vb(
&vehicle_b,
&camera,
&camera_kp,
CAMERA,
target,
SubnetRights::ATTACH,
)
.await
.expect_err("evidence 6: a camera-scoped grant must not reach elsewhere"),
SubnetAuthError::ScopeNotAncestor,
"camera attaching {what} must be refused as out of scope",
);
}
for target in [WORLD_MODEL, CAMERA, RADAR, PERCEPTION] {
try_admit_vb(
&vehicle_b,
&camera,
&camera_kp,
PERCEPTION,
target,
SubnetRights::ATTACH,
)
.await
.expect("evidence 7: a perception parent grant covers its whole subtree");
}
for target in [CHASSIS, VEHICLE] {
assert_eq!(
try_admit_vb(
&vehicle_b,
&camera,
&camera_kp,
PERCEPTION,
target,
SubnetRights::ATTACH,
)
.await
.expect_err("a perception grant must not escape perception"),
SubnetAuthError::ScopeNotAncestor,
);
}
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn equal_path_bits_under_two_authorities_are_unrelated() {
let vehicle_b = build_vehicle_b().await;
let camera = build_peer(CAMERA_SEED).await;
let camera_kp = EntityKeypair::from_bytes(CAMERA_SEED);
bring_up(&camera, &vehicle_b).await;
let va_set = SubnetCredentialSet::Direct(
SubnetGrant::try_issue(
&va_subnet_root(),
va_subnet_root().entity_id().clone(),
TopologySubnetId::new(WORLD_MODEL),
0,
camera_kp.entity_id().clone(),
SubnetRights::ATTACH,
1,
unix_now() - 60,
DAY,
)
.expect("issue Vehicle A grant"),
);
let node_id = camera.node_id();
let nonce = vehicle_b
.issue_subnet_challenge(node_id)
.expect("challenge");
let session_id = vehicle_b.peer_session_id(node_id).expect("session");
let presentation = SubnetAuthPresentation::try_issue(
&camera_kp,
va_set.credential_set_hash(),
session_id,
vehicle_b.entity_id().clone(),
nonce,
SubnetRef {
authority: va_subnet_root().entity_id().clone(),
path: TopologySubnetId::new(WORLD_MODEL),
},
SubnetRights::ATTACH,
)
.expect("presentation");
assert_eq!(
vehicle_b
.admit_subnet_session(node_id, &presentation, &va_set)
.expect_err("evidence 8: another vehicle's authority is not this vehicle's"),
SubnetAuthError::UnknownAuthority,
);
assert!(
vehicle_b.subnet_context_for(node_id).is_none(),
"no context may be installed from a foreign authority's grant",
);
try_admit_vb(
&vehicle_b,
&camera,
&camera_kp,
WORLD_MODEL,
WORLD_MODEL,
SubnetRights::ATTACH,
)
.await
.expect("the authority-qualified grant is what admits");
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn neither_plane_manufactures_the_other() {
let (f, camera) = fleet_fixture_with_camera("plane-independence").await;
let camera_kp = EntityKeypair::from_bytes(CAMERA_SEED);
f.call(true)
.await
.expect("the org-authorized fleet call admits");
f.assert_no_va_subnet_context();
try_admit_vb(
&f.vehicle_b,
&camera,
&camera_kp,
CAMERA,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect("the camera is admitted internally");
assert!(
f.vehicle_b.subnet_context_for(camera.node_id()).is_some(),
"precondition: the camera holds a live subnet context",
);
let baseline = f.calls.load(Ordering::SeqCst);
let result = camera
.call(
f.vehicle_b.node_id(),
SERVICE,
Bytes::from_static(b"roi?"),
call_opts(None),
)
.await;
assert_explicit_denial(result, "subnet context without org authority");
assert_handler_stays_at(&f.calls, baseline, "subnet context without org authority").await;
assert!(
f.vehicle_b.subnet_context_for(camera.node_id()).is_some(),
"an org-plane denial must not disturb the subnet plane",
);
}
const PARTNER_ORG_SEED: [u8; 32] = [0xB7; 32];
const PARTNER_SEED: [u8; 32] = [0xA4; 32];
const DIAGNOSTIC: &str = "diagnostic.snapshot";
const DIAGNOSTIC_TRACE: &str = "diagnostic.trace";
fn partner_org() -> OrgKeypair {
OrgKeypair::from_bytes(PARTNER_ORG_SEED)
}
fn partner_intent_granting(
provider: EntityId,
granted_service: &str,
invoked_service: &str,
target_scope: GrantTargetScope,
) -> OrgProofIntent {
let caller_kp = EntityKeypair::from_bytes(PARTNER_SEED);
let caller_entity = caller_kp.entity_id().clone();
let invoked_cap = CapabilityAuthorityId::for_tag(&format!("nrpc:{invoked_service}"));
let granted_cap = CapabilityAuthorityId::for_tag(&format!("nrpc:{granted_service}"));
let (grant, secret) = OrgCapabilityGrant::try_issue(
&bmw(),
partner_org().org_id(),
granted_cap,
GrantRights::INVOKE,
target_scope,
3600,
)
.expect("BMW issues the cross-org INVOKE grant");
assert!(
secret.is_none(),
"an INVOKE-only grant carries no audience material",
);
let membership = OrgMembershipCert::try_issue(&partner_org(), caller_entity.clone(), 1, 3600)
.expect("partner membership");
let dispatcher = OrgDispatcherGrant::try_issue(
&partner_org(),
caller_entity,
DispatcherScope::Exact(invoked_cap),
3600,
)
.expect("partner dispatcher");
OrgProofIntent {
caller: Arc::new(caller_kp),
membership,
dispatcher,
capability_grant: Some(grant),
acting_org: partner_org().org_id(),
provider_owner_org: bmw().org_id(),
provider,
capability: invoked_cap,
proof_ttl_secs: 30,
}
}
fn partner_intent(
provider: EntityId,
service: &str,
target_scope: GrantTargetScope,
) -> OrgProofIntent {
partner_intent_granting(provider, service, service, target_scope)
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn partner_diagnostic_is_exactly_bounded() {
let (f, peers) = fleet_fixture_with_peers("partner", &[PARTNER_SEED]).await;
let partner = &peers[0];
let provider = f.provider.clone();
let diag_calls = Arc::new(AtomicUsize::new(0));
let _diag = f
.vehicle_b
.serve_rpc_subnet_exported(
DIAGNOSTIC,
Arc::new(RoiHandler {
calls: diag_calls.clone(),
attribution_ok: Arc::new(AtomicBool::new(false)),
proof_stripped: Arc::new(AtomicBool::new(false)),
expected_caller: partner.entity_id().clone(),
expected_org: partner_org().org_id(),
expected_provider: provider.clone(),
}),
OrgAdmission::CrossOrgGranted,
world_model_binding(0),
Arc::new(|_| true),
)
.expect("serve the exported diagnostic");
let trace_calls = Arc::new(AtomicUsize::new(0));
let _trace = f
.vehicle_b
.serve_rpc_subnet_exported(
DIAGNOSTIC_TRACE,
Arc::new(RoiHandler {
calls: trace_calls.clone(),
attribution_ok: Arc::new(AtomicBool::new(false)),
proof_stripped: Arc::new(AtomicBool::new(false)),
expected_caller: partner.entity_id().clone(),
expected_org: partner_org().org_id(),
expected_provider: provider.clone(),
}),
OrgAdmission::CrossOrgGranted,
world_model_binding(0),
Arc::new(|_| true),
)
.expect("serve the exported diagnostic trace");
let reply = partner
.call(
f.vehicle_b.node_id(),
DIAGNOSTIC,
Bytes::from_static(b"snapshot?"),
call_opts(Some(partner_intent(
provider.clone(),
DIAGNOSTIC,
GrantTargetScope::ExactNode(provider.clone()),
))),
)
.await
.expect("evidence 9: the exact partner grant reaches its exported provider");
assert_eq!(reply.body.as_ref(), b"roi-window");
assert_eq!(
diag_calls.load(Ordering::SeqCst),
1,
"the diagnostic handler ran exactly once",
);
let reply = partner
.call(
f.vehicle_b.node_id(),
DIAGNOSTIC_TRACE,
Bytes::from_static(b"trace?"),
call_opts(Some(partner_intent(
provider.clone(),
DIAGNOSTIC_TRACE,
GrantTargetScope::ExactNode(provider.clone()),
))),
)
.await
.expect("control: the trace-granting intent reaches diagnostic.trace");
assert_eq!(reply.body.as_ref(), b"roi-window");
assert_eq!(
trace_calls.load(Ordering::SeqCst),
1,
"the trace handler ran exactly once",
);
let trace_baseline = trace_calls.load(Ordering::SeqCst);
let result = partner
.call(
f.vehicle_b.node_id(),
DIAGNOSTIC_TRACE,
Bytes::from_static(b"trace?"),
call_opts(Some(partner_intent_granting(
provider.clone(),
DIAGNOSTIC,
DIAGNOSTIC_TRACE,
GrantTargetScope::ExactNode(provider.clone()),
))),
)
.await;
assert_explicit_denial(result, "the diagnostic grant invoking diagnostic.trace");
assert_handler_stays_at(
&trace_calls,
trace_baseline,
"the diagnostic grant invoking diagnostic.trace",
)
.await;
let roi_baseline = f.calls.load(Ordering::SeqCst);
let result = partner
.call(
f.vehicle_b.node_id(),
SERVICE,
Bytes::from_static(b"roi?"),
call_opts(Some(partner_intent(
provider.clone(),
SERVICE,
GrantTargetScope::ExactNode(provider.clone()),
))),
)
.await;
assert_explicit_denial(
result,
"a cross-org intent reaching an owner-delegated service",
);
assert_handler_stays_at(
&f.calls,
roi_baseline,
"a cross-org intent reaching an owner-delegated service",
)
.await;
let diag_baseline = diag_calls.load(Ordering::SeqCst);
let elsewhere = EntityKeypair::from_bytes([0xEE; 32]).entity_id().clone();
let result = partner
.call(
f.vehicle_b.node_id(),
DIAGNOSTIC,
Bytes::from_static(b"snapshot?"),
call_opts(Some(partner_intent(
provider.clone(),
DIAGNOSTIC,
GrantTargetScope::ExactNode(elsewhere),
))),
)
.await;
assert_explicit_denial(result, "partner grant scoped to another provider");
assert_handler_stays_at(&diag_calls, diag_baseline, "partner grant scoped elsewhere").await;
assert!(
f.vehicle_b.subnet_context_for(partner.node_id()).is_none(),
"the Partner client must acquire no Vehicle B subnet context",
);
let partner_kp = EntityKeypair::from_bytes(PARTNER_SEED);
let foreign_root = va_subnet_root();
for internal in [CAMERA, RADAR, CHASSIS] {
let set = SubnetCredentialSet::Direct(
SubnetGrant::try_issue(
&foreign_root,
foreign_root.entity_id().clone(),
TopologySubnetId::new(internal),
0,
partner_kp.entity_id().clone(),
SubnetRights::ATTACH,
1,
unix_now() - 60,
DAY,
)
.expect("issue foreign-authority grant"),
);
let node_id = partner.node_id();
let nonce = f
.vehicle_b
.issue_subnet_challenge(node_id)
.expect("challenge");
let session_id = f.vehicle_b.peer_session_id(node_id).expect("session");
let presentation = SubnetAuthPresentation::try_issue(
&partner_kp,
set.credential_set_hash(),
session_id,
f.vehicle_b.entity_id().clone(),
nonce,
SubnetRef {
authority: foreign_root.entity_id().clone(),
path: TopologySubnetId::new(internal),
},
SubnetRights::ATTACH,
)
.expect("presentation");
assert_eq!(
f.vehicle_b
.admit_subnet_session(node_id, &presentation, &set)
.expect_err("the Partner has no Vehicle B subnet authority"),
SubnetAuthError::UnknownAuthority,
"no internal attachment is reachable for the Partner",
);
}
assert!(
f.vehicle_b.subnet_context_for(partner.node_id()).is_none(),
"and still no context after every attempt",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn channel_authority_remains_independent_of_subnet_authority() {
let vehicle_b = {
let mut cfg = base_config().with_subnet_authority(SubnetAuthorityConfig {
authority: vb_subnet_root().entity_id().clone(),
roots: vec![vb_subnet_root().entity_id().clone()],
maximum_grant_lifetime_secs: 7 * DAY,
});
cfg.subnet_attachment = Some(TopologySubnetId::new(VEHICLE));
let mut node = MeshNode::new(EntityKeypair::from_bytes(VEHICLE_B_SEED), cfg)
.await
.expect("MeshNode::new vehicle B");
let registry = Arc::new(ChannelConfigRegistry::new());
let channel = ChannelName::new("vehicle-b/perception/internal").unwrap();
registry.insert(
ChannelConfig::new(ChannelId::new(channel)).with_token_roots(vec![
EntityKeypair::from_bytes(VEHICLE_B_SEED)
.entity_id()
.clone(),
]),
);
registry
.install_rpc_service_defaults("vehicle-b.protected.telemetry")
.expect("the fixture's service name must be installable");
node.set_channel_configs(registry);
node.set_token_cache(Arc::new(TokenCache::new()));
Arc::new(node)
};
let vb_kp = EntityKeypair::from_bytes(VEHICLE_B_SEED);
let camera = build_peer(CAMERA_SEED).await;
let camera_kp = EntityKeypair::from_bytes(CAMERA_SEED);
bring_up(&camera, &vehicle_b).await;
let channel = ChannelName::new("vehicle-b/perception/internal").unwrap();
try_admit_vb(
&vehicle_b,
&camera,
&camera_kp,
PERCEPTION,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect("the camera is admitted under a parent perception grant");
assert!(
vehicle_b.subnet_context_for(camera.node_id()).is_some(),
"precondition: a live parent subnet context",
);
let denied = camera
.subscribe_channel(vehicle_b.node_id(), channel.clone())
.await
.expect_err(
"evidence 10: a valid parent subnet context must not admit a \
token-gated internal channel",
);
match denied {
AdapterError::Connection(ref msg) => assert!(
msg.contains("membership request rejected") && msg.contains("Unauthorized"),
"the denial must be the publisher's explicit Unauthorized \
membership rejection, not a transport failure: {msg}",
),
other => panic!(
"expected the publisher's explicit membership rejection, got {other:?} \
(a timeout here would be a denial masquerading as a timeout)"
),
}
let token = PermissionToken::issue(
&vb_kp,
camera_kp.entity_id().clone(),
TokenScope::SUBSCRIBE,
channel.hash(),
300,
0,
);
camera
.subscribe_channel_with_token(vehicle_b.node_id(), channel.clone(), token)
.await
.expect("the channel token is what admits the channel");
assert_eq!(
try_admit_vb(
&vehicle_b,
&camera,
&camera_kp,
CAMERA,
CHASSIS,
SubnetRights::ATTACH,
)
.await
.expect_err("a channel token grants no ATTACH anywhere"),
SubnetAuthError::ScopeNotAncestor,
);
assert!(
vehicle_b.subnet_gateway_contexts().is_none(),
"a channel subscription must not publish gateway authority",
);
let dir = install_bmw_authority(&vehicle_b, "channel-independence");
let guarded_calls = Arc::new(AtomicUsize::new(0));
let _guarded = vehicle_b
.serve_rpc_protected(
"vehicle-b.protected.telemetry",
Arc::new(RoiHandler {
calls: guarded_calls.clone(),
attribution_ok: Arc::new(AtomicBool::new(false)),
proof_stripped: Arc::new(AtomicBool::new(false)),
expected_caller: camera_kp.entity_id().clone(),
expected_org: bmw().org_id(),
expected_provider: vehicle_b.entity_id().clone(),
}),
OrgAdmission::OwnerDelegated,
Arc::new(|_| true),
)
.expect("serve the org-protected telemetry provider");
let baseline = guarded_calls.load(Ordering::SeqCst);
let result = camera
.call(
vehicle_b.node_id(),
"vehicle-b.protected.telemetry",
Bytes::from_static(b"probe"),
call_opts(None),
)
.await;
assert_explicit_denial(
result,
"a channel-token holder invoking a protected provider",
);
assert_handler_stays_at(
&guarded_calls,
baseline,
"a channel-token holder invoking a protected provider",
)
.await;
assert!(
vehicle_b.subnet_context_for(camera.node_id()).is_some(),
"the provider denial must not disturb the subnet plane",
);
let token = PermissionToken::issue(
&vb_kp,
camera_kp.entity_id().clone(),
TokenScope::SUBSCRIBE,
channel.hash(),
300,
0,
);
camera
.subscribe_channel_with_token(vehicle_b.node_id(), channel.clone(), token)
.await
.expect("the channel plane survives the provider denial");
drop(dir);
}
fn readopt_bmw_authority(server: &Arc<MeshNode>, dir: &std::path::Path, generation: u32) {
let node_entity = server.entity_id().clone();
let node_cert = OrgMembershipCert::try_issue(&bmw(), node_entity.clone(), generation, 3600)
.expect("node cert");
let authority =
NodeAuthority::adopt(dir, node_cert, &node_entity, 0, None).expect("re-adopt authority");
server
.install_node_authority(Arc::new(authority))
.expect("install re-adopted authority");
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn org_and_subnet_revocation_are_independent_live() {
let (f, camera, publisher) = fleet_fixture_with_control("indep-revocation").await;
let camera_kp = EntityKeypair::from_bytes(CAMERA_SEED);
f.call(true).await.expect("baseline fleet call admits");
try_admit_vb(
&f.vehicle_b,
&camera,
&camera_kp,
PERCEPTION,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect("camera admitted under perception");
assert!(f.vehicle_b.subnet_context_for(camera.node_id()).is_some());
let subnet_epoch_before = f
.vehicle_b
.subnet_floor_registry()
.auth_epoch(vb_subnet_root().entity_id());
let mut floors = std::collections::BTreeMap::new();
floors.insert(f.vehicle_b.entity_id().clone(), 9u32);
let bundle = OrgRevocationBundle::try_issue(&bmw(), &floors).expect("issue org bundle");
f.vehicle_b
.node_authority()
.expect("authority installed")
.revocation
.apply_bundle(&bundle)
.expect("apply org floor");
let baseline = f.calls.load(Ordering::SeqCst);
assert_explicit_denial(f.call(true).await, "org membership revoked");
assert_handler_stays_at(&f.calls, baseline, "org membership revoked").await;
assert_eq!(
f.vehicle_b
.subnet_floor_registry()
.auth_epoch(vb_subnet_root().entity_id()),
subnet_epoch_before,
"evidence 12: an org revocation must not touch the subnet auth epoch",
);
assert!(
f.vehicle_b.subnet_context_for(camera.node_id()).is_some(),
"evidence 12: the internal subnet context survives an org revocation",
);
readopt_bmw_authority(&f.vehicle_b, &f.dir, 10);
f.call(true)
.await
.expect("current BMW credentials restore the fleet call");
let floor = SubnetRevocationFloor::try_issue(
&vb_subnet_root(),
vb_ref(PERCEPTION),
0,
5, 1,
unix_now(),
)
.expect("issue perception floor");
assert!(
publish_control_fact_and_await_epoch(
&publisher,
&f.vehicle_b,
SubnetControlFact::RevocationFloor(floor).to_bytes(),
subnet_epoch_before + 1,
)
.await,
"the signed perception floor must be accepted over the control channel",
);
assert_eq!(
try_admit_vb(
&f.vehicle_b,
&camera,
&camera_kp,
PERCEPTION,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect_err("evidence 13: perception-scoped grants below the floor are revoked"),
SubnetAuthError::Revoked,
);
try_admit_vb(
&f.vehicle_b,
&camera,
&camera_kp,
CHASSIS,
BRAKING,
SubnetRights::ATTACH,
)
.await
.expect("evidence 13: a chassis-scoped grant is unaffected by a perception floor");
try_admit_vb(
&f.vehicle_b,
&camera,
&camera_kp,
VEHICLE,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect("evidence 13: the vehicle-root grant stays structurally dominant");
let baseline = f.calls.load(Ordering::SeqCst);
assert_explicit_denial(
f.call(true).await,
"export credential below the subnet floor",
);
assert_handler_stays_at(
&f.calls,
baseline,
"export credential below the subnet floor",
)
.await;
let above_floor = vec![
vb_grant_at(
&f.vb_kp,
VEHICLE,
SubnetRights::ATTACH.union(SubnetRights::ROUTE),
0,
6,
DAY,
),
vb_grant_at(&f.vb_kp, WORLD_MODEL, SubnetRights::EXPORT, 0, 6, DAY),
];
f.vehicle_b
.install_subnet_gateway_credentials(&above_floor)
.expect("install above-floor gateway credentials");
f.call(true).await.expect(
"evidence 13: repairing only the SUBNET plane restores the call — \
BMW membership was never disturbed by the subnet floor",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn replayed_credentials_and_presentations_prove_nothing() {
const OUTSIDER_SEED: [u8; 32] = [0xEF; 32];
let (f, peers) = fleet_fixture_with_peers("replay", &[CAMERA_SEED, OUTSIDER_SEED]).await;
let (camera, outsider) = (&peers[0], &peers[1]);
let camera_kp = EntityKeypair::from_bytes(CAMERA_SEED);
let outsider_kp = EntityKeypair::from_bytes(OUTSIDER_SEED);
let set = vb_grant(&camera_kp, CAMERA, SubnetRights::ATTACH);
let camera_node = camera.node_id();
let nonce = f
.vehicle_b
.issue_subnet_challenge(camera_node)
.expect("challenge");
let session_id = f.vehicle_b.peer_session_id(camera_node).expect("session");
let genuine = SubnetAuthPresentation::try_issue(
&camera_kp,
set.credential_set_hash(),
session_id,
f.vehicle_b.entity_id().clone(),
nonce,
vb_ref(CAMERA),
SubnetRights::ATTACH,
)
.expect("presentation");
f.vehicle_b
.admit_subnet_session(camera_node, &genuine, &set)
.expect("the genuine presentation admits");
assert_eq!(
f.vehicle_b
.admit_subnet_session(camera_node, &genuine, &set)
.expect_err("evidence 15: a captured presentation cannot be replayed"),
SubnetAuthError::WrongChallenge,
);
let outsider_node = outsider.node_id();
let out_nonce = f
.vehicle_b
.issue_subnet_challenge(outsider_node)
.expect("challenge");
let out_session = f.vehicle_b.peer_session_id(outsider_node).expect("session");
let stolen = SubnetAuthPresentation::try_issue(
&outsider_kp,
set.credential_set_hash(),
out_session,
f.vehicle_b.entity_id().clone(),
out_nonce,
vb_ref(CAMERA),
SubnetRights::ATTACH,
)
.expect("presentation");
assert_eq!(
f.vehicle_b
.admit_subnet_session(outsider_node, &stolen, &set)
.expect_err("evidence 14: a stolen credential set proves nothing"),
SubnetAuthError::WrongSubject,
);
assert!(
f.vehicle_b.subnet_context_for(outsider_node).is_none(),
"the outsider acquires no context",
);
let fresh_nonce = f
.vehicle_b
.issue_subnet_challenge(camera_node)
.expect("challenge");
let stale_session = SubnetAuthPresentation::try_issue(
&camera_kp,
set.credential_set_hash(),
session_id.wrapping_add(1),
f.vehicle_b.entity_id().clone(),
fresh_nonce,
vb_ref(CAMERA),
SubnetRights::ATTACH,
)
.expect("presentation");
assert_eq!(
f.vehicle_b
.admit_subnet_session(camera_node, &stale_session, &set)
.expect_err("evidence 15: the proof is bound to one incarnation"),
SubnetAuthError::WrongSession,
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn each_axis_recovers_only_itself() {
let (f, camera, publisher) = fleet_fixture_with_control("axis-recovery").await;
let camera_kp = EntityKeypair::from_bytes(CAMERA_SEED);
try_admit_vb(
&f.vehicle_b,
&camera,
&camera_kp,
PERCEPTION,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect("camera admitted");
let floor = SubnetRevocationFloor::try_issue(
&vb_subnet_root(),
vb_ref(PERCEPTION),
0,
5,
1,
unix_now(),
)
.expect("floor");
assert!(
publish_control_fact_and_await_epoch(
&publisher,
&f.vehicle_b,
SubnetControlFact::RevocationFloor(floor).to_bytes(),
1,
)
.await,
"the floor applies",
);
assert!(
f.vehicle_b.subnet_context_for(camera.node_id()).is_none(),
"the auth-epoch move invalidated the stale context",
);
assert_eq!(
try_admit_vb(
&f.vehicle_b,
&camera,
&camera_kp,
PERCEPTION,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect_err("a below-floor credential cannot re-prove the axis"),
SubnetAuthError::Revoked,
);
let above = SubnetCredentialSet::Direct(
SubnetGrant::try_issue(
&vb_subnet_root(),
vb_subnet_root().entity_id().clone(),
TopologySubnetId::new(PERCEPTION),
0,
camera_kp.entity_id().clone(),
SubnetRights::ATTACH,
6,
unix_now() - 60,
DAY,
)
.expect("above-floor grant"),
);
let node_id = camera.node_id();
let nonce = f
.vehicle_b
.issue_subnet_challenge(node_id)
.expect("challenge");
let session_id = f.vehicle_b.peer_session_id(node_id).expect("session");
let presentation = SubnetAuthPresentation::try_issue(
&camera_kp,
above.credential_set_hash(),
session_id,
f.vehicle_b.entity_id().clone(),
nonce,
vb_ref(CAMERA),
SubnetRights::ATTACH,
)
.expect("presentation");
f.vehicle_b
.admit_subnet_session(node_id, &presentation, &above)
.expect("evidence 15: above-floor credentials recover the subnet axis");
assert!(f.vehicle_b.subnet_context_for(node_id).is_some());
let baseline = f.calls.load(Ordering::SeqCst);
let result = camera
.call(
f.vehicle_b.node_id(),
SERVICE,
Bytes::from_static(b"roi?"),
call_opts(None),
)
.await;
assert_explicit_denial(result, "recovered subnet axis without org proof");
assert_handler_stays_at(
&f.calls,
baseline,
"recovered subnet axis without org proof",
)
.await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn topology_epoch_invalidates_old_contexts_before_forwarding() {
let (f, camera, publisher) = fleet_fixture_with_control("epoch-invalidation").await;
let camera_kp = EntityKeypair::from_bytes(CAMERA_SEED);
try_admit_vb(
&f.vehicle_b,
&camera,
&camera_kp,
PERCEPTION,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect("camera admitted under epoch 0");
assert!(f.vehicle_b.subnet_context_for(camera.node_id()).is_some());
let next_epoch = f.vehicle_b.advance_subnet_topology_epoch();
assert_eq!(next_epoch, 1);
assert!(
f.vehicle_b.subnet_context_for(camera.node_id()).is_none(),
"evidence 16: every context minted under the old meaning is dropped",
);
assert_eq!(
try_admit_vb(
&f.vehicle_b,
&camera,
&camera_kp,
PERCEPTION,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect_err("an old-epoch credential must not re-admit"),
SubnetAuthError::WrongTopologyEpoch,
);
let stale_descriptor =
SubnetDescriptor::try_issue(&vb_subnet_root(), vb_ref(PERCEPTION), 0, 1, unix_now())
.expect("old-epoch descriptor");
publisher
.publish(
&publisher_for(control_channel()),
Bytes::from(SubnetControlFact::Descriptor(stale_descriptor).to_bytes()),
)
.await
.expect("publish old-epoch fact");
let current_descriptor = SubnetDescriptor::try_issue(
&vb_subnet_root(),
vb_ref(CHASSIS),
next_epoch,
1,
unix_now(),
)
.expect("current-epoch descriptor");
publisher
.publish(
&publisher_for(control_channel()),
Bytes::from(SubnetControlFact::Descriptor(current_descriptor).to_bytes()),
)
.await
.expect("publish current-epoch fact");
assert!(
wait_until(Duration::from_secs(5), || f
.vehicle_b
.subnet_control_store()
.descriptor_for(
vb_subnet_root().entity_id(),
next_epoch,
TopologySubnetId::new(CHASSIS)
)
.is_some())
.await,
"the current-epoch marker fact applied",
);
assert!(
f.vehicle_b.subnet_context_for(camera.node_id()).is_none(),
"evidence 16: an old-epoch control fact must not revive a dropped context",
);
let fresh = SubnetCredentialSet::Direct(
SubnetGrant::try_issue(
&vb_subnet_root(),
vb_subnet_root().entity_id().clone(),
TopologySubnetId::new(PERCEPTION),
next_epoch,
camera_kp.entity_id().clone(),
SubnetRights::ATTACH,
1,
unix_now() - 60,
DAY,
)
.expect("fresh-epoch grant"),
);
let node_id = camera.node_id();
let nonce = f
.vehicle_b
.issue_subnet_challenge(node_id)
.expect("challenge");
let session_id = f.vehicle_b.peer_session_id(node_id).expect("session");
let presentation = SubnetAuthPresentation::try_issue(
&camera_kp,
fresh.credential_set_hash(),
session_id,
f.vehicle_b.entity_id().clone(),
nonce,
vb_ref(CAMERA),
SubnetRights::ATTACH,
)
.expect("presentation");
f.vehicle_b
.admit_subnet_session(node_id, &presentation, &fresh)
.expect("evidence 16: fresh-epoch credentials restore authority");
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn hostile_control_publisher_is_inert_in_the_full_topology() {
let (f, camera, publisher) = fleet_fixture_with_control("hostile").await;
let camera_kp = EntityKeypair::from_bytes(CAMERA_SEED);
let hostile_root = EntityKeypair::from_bytes([0xDD; 32]);
f.call(true).await.expect("baseline fleet call");
try_admit_vb(
&f.vehicle_b,
&camera,
&camera_kp,
PERCEPTION,
CAMERA,
SubnetRights::ATTACH,
)
.await
.expect("camera admitted");
let calls_before = f.calls.load(Ordering::SeqCst);
let epoch_before = f
.vehicle_b
.subnet_floor_registry()
.auth_epoch(vb_subnet_root().entity_id());
let wrong_root_scope = SubnetRef {
authority: hostile_root.entity_id().clone(),
path: TopologySubnetId::new(PERCEPTION),
};
let mut malformed = SubnetControlFact::Descriptor(
SubnetDescriptor::try_issue(&vb_subnet_root(), vb_ref(PERCEPTION), 0, 99, unix_now())
.expect("descriptor"),
)
.to_bytes();
malformed.truncate(malformed.len() / 2);
let mut trailing = SubnetControlFact::Descriptor(
SubnetDescriptor::try_issue(&vb_subnet_root(), vb_ref(PERCEPTION), 0, 98, unix_now())
.expect("descriptor"),
)
.to_bytes();
trailing.push(0);
let SubnetControlFact::Descriptor(mut unsigned) = SubnetControlFact::Descriptor(
SubnetDescriptor::try_issue(&vb_subnet_root(), vb_ref(PERCEPTION), 0, 97, unix_now())
.expect("descriptor"),
) else {
unreachable!()
};
unsigned.signature = [0u8; 64];
let hostile_payloads: Vec<Bytes> = vec![
Bytes::from_static(b""),
Bytes::from_static(b"not a control fact"),
Bytes::from(vec![0xFFu8; 2048]),
Bytes::from(malformed),
Bytes::from(trailing),
Bytes::from(SubnetControlFact::Descriptor(unsigned).to_bytes()),
Bytes::from(
SubnetControlFact::Descriptor(
SubnetDescriptor::try_issue(
&hostile_root,
wrong_root_scope.clone(),
0,
1,
unix_now(),
)
.expect("hostile descriptor"),
)
.to_bytes(),
),
Bytes::from(
SubnetControlFact::GatewayAdvertisement(
GatewayAdvertisement::try_issue(
&hostile_root,
wrong_root_scope.clone(),
0,
publisher.entity_id().clone(),
publisher.node_id(),
1,
unix_now() - 60,
unix_now() + 3600,
)
.expect("hostile advertisement"),
)
.to_bytes(),
),
Bytes::from(
SubnetControlFact::ExportPolicy(
SubnetExportPolicy::try_issue(
&hostile_root,
wrong_root_scope.clone(),
0,
vec![0xDEAD_BEEF],
1,
unix_now() - 60,
unix_now() + 3600,
)
.expect("hostile export policy"),
)
.to_bytes(),
),
Bytes::from(
SubnetControlFact::RevocationFloor(
SubnetRevocationFloor::try_issue(
&hostile_root,
wrong_root_scope,
0,
999,
1,
unix_now(),
)
.expect("hostile floor"),
)
.to_bytes(),
),
];
for payload in hostile_payloads {
publisher
.publish(&publisher_for(control_channel()), payload)
.await
.expect("publish hostile payload");
}
let good =
SubnetDescriptor::try_issue(&vb_subnet_root(), vb_ref(WORLD_MODEL), 0, 7, unix_now())
.expect("legitimate descriptor");
publisher
.publish(
&publisher_for(control_channel()),
Bytes::from(SubnetControlFact::Descriptor(good).to_bytes()),
)
.await
.expect("publish the legitimate fact");
assert!(
wait_until(Duration::from_secs(5), || f
.vehicle_b
.subnet_control_store()
.descriptor_for(
vb_subnet_root().entity_id(),
0,
TopologySubnetId::new(WORLD_MODEL)
)
.is_some())
.await,
"evidence 17: a correctly signed fact is still accepted after the barrage",
);
assert!(
f.vehicle_b
.subnet_control_store()
.descriptor_for(
hostile_root.entity_id(),
0,
TopologySubnetId::new(PERCEPTION)
)
.is_none(),
"no hostile descriptor state",
);
assert!(
f.vehicle_b
.subnet_control_store()
.gateway_for(
hostile_root.entity_id(),
0,
TopologySubnetId::new(PERCEPTION),
unix_now(),
30
)
.is_none(),
"no hostile gateway advertisement state",
);
assert!(
f.vehicle_b
.subnet_control_store()
.export_policy_for(
hostile_root.entity_id(),
0,
TopologySubnetId::new(PERCEPTION),
unix_now(),
30
)
.is_none(),
"no hostile export-policy state",
);
assert!(
f.vehicle_b
.subnet_control_store()
.descriptor_for(
vb_subnet_root().entity_id(),
0,
TopologySubnetId::new(PERCEPTION)
)
.is_none(),
"the unsigned/malformed descriptors named a real scope and still applied nothing",
);
assert_eq!(
f.vehicle_b
.subnet_floor_registry()
.auth_epoch(vb_subnet_root().entity_id()),
epoch_before,
"no hostile floor moved the auth epoch",
);
assert_eq!(
f.vehicle_b
.subnet_floor_registry()
.auth_epoch(hostile_root.entity_id()),
0,
"and the hostile authority has no epoch of its own here",
);
assert!(
f.vehicle_b.subnet_context_for(camera.node_id()).is_some(),
"evidence 17: no admitted context disappears",
);
assert!(
f.vehicle_b
.subnet_context_for(publisher.node_id())
.is_none(),
"evidence 17: the publisher gains no subnet presence",
);
assert_eq!(
f.calls.load(Ordering::SeqCst),
calls_before,
"evidence 17: no handler ran on hostile input",
);
f.call(true)
.await
.expect("evidence 17: the node remains healthy and still serves the fleet");
}
const INNER_TAG: &[u8] = b"vehicle-b-inner-payload";
async fn wire() -> UdpSocket {
UdpSocket::bind("127.0.0.1:0").await.expect("bind watcher")
}
fn route_hops(datagrams: &[Vec<u8>]) -> Vec<&Vec<u8>> {
datagrams
.iter()
.filter(|d| d.len() >= 2 && u16::from_le_bytes([d[0], d[1]]) == ROUTE_HOP_MAGIC)
.collect()
}
async fn received_within(sock: &UdpSocket, dur: Duration) -> Vec<Vec<u8>> {
let mut out = Vec::new();
let deadline = tokio::time::Instant::now() + dur;
let mut buf = vec![0u8; 2048];
while tokio::time::Instant::now() < deadline {
let remaining = deadline - tokio::time::Instant::now();
match tokio::time::timeout(remaining, sock.recv_from(&mut buf)).await {
Ok(Ok((n, _))) => out.push(buf[..n].to_vec()),
_ => break,
}
}
out
}
struct TwoGatewayFixture {
source: Arc<MeshNode>,
gw1: Arc<MeshNode>,
gw2: Arc<MeshNode>,
dest: Arc<MeshNode>,
outsider: Arc<MeshNode>,
}
async fn vb_node(seed: [u8; 32], attachment: &[u8]) -> Arc<MeshNode> {
vb_node_with_policy(seed, attachment, None).await
}
async fn vb_node_with_policy(
seed: [u8; 32],
attachment: &[u8],
subnet_policy: Option<Arc<SubnetPolicy>>,
) -> Arc<MeshNode> {
let mut cfg = base_config().with_subnet_authority(SubnetAuthorityConfig {
authority: vb_subnet_root().entity_id().clone(),
roots: vec![vb_subnet_root().entity_id().clone()],
maximum_grant_lifetime_secs: 7 * DAY,
});
cfg.subnet_attachment = Some(TopologySubnetId::new(attachment));
cfg.subnet_policy = subnet_policy;
Arc::new(
MeshNode::new(EntityKeypair::from_bytes(seed), cfg)
.await
.expect("MeshNode::new"),
)
}
async fn two_gateway_fixture(gw2_rights: SubnetRights) -> TwoGatewayFixture {
two_gateway_fixture_with_gw1_policy(gw2_rights, None).await
}
async fn two_gateway_fixture_with_gw1_policy(
gw2_rights: SubnetRights,
gw1_policy: Option<Arc<SubnetPolicy>>,
) -> TwoGatewayFixture {
let (s_kp, g1_kp, g2_kp, d_kp) = (
EntityKeypair::from_bytes([0xD1; 32]),
EntityKeypair::from_bytes([0xD2; 32]),
EntityKeypair::from_bytes([0xD3; 32]),
EntityKeypair::from_bytes([0xD4; 32]),
);
let source = vb_node([0xD1; 32], CAMERA).await;
let gw1 = vb_node_with_policy([0xD2; 32], VEHICLE, gw1_policy).await;
let gw2 = vb_node([0xD3; 32], VEHICLE).await;
let dest = vb_node([0xD4; 32], WORLD_MODEL).await;
let outsider = vb_node([0xD9; 32], CAMERA).await;
connect_no_start(&source, &gw1).await;
connect_no_start(&gw2, &gw1).await;
connect_no_start(&dest, &gw2).await;
connect_no_start(&outsider, &gw1).await;
source.start();
gw1.start();
gw2.start();
dest.start();
outsider.start();
for (verifier, peer, kp, attach) in [
(&gw1, &source, &s_kp, CAMERA),
(&gw1, &gw2, &g2_kp, VEHICLE),
(&gw2, &gw1, &g1_kp, VEHICLE),
(&gw2, &dest, &d_kp, WORLD_MODEL),
] {
try_admit_vb(verifier, peer, kp, VEHICLE, attach, SubnetRights::ATTACH)
.await
.expect("adjacent edge admitted at its exact attachment");
}
gw1.install_subnet_gateway_credentials(&[vb_grant(
&g1_kp,
VEHICLE,
SubnetRights::ATTACH.union(SubnetRights::ROUTE),
)])
.expect("gw1 credentials");
gw2.install_subnet_gateway_credentials(&[vb_grant(
&g2_kp,
VEHICLE,
SubnetRights::ATTACH.union(gw2_rights),
)])
.expect("gw2 credentials");
for gw in [&gw1, &gw2] {
gw.declare_subnet_boundaries(SubnetBoundarySet::new(
vb_subnet_root().entity_id().clone(),
0,
[],
));
}
dest.announce_capabilities(CapabilitySet::new().add_tag("two-gateway-witness"))
.await
.expect("dest announce");
gw2.announce_capabilities(CapabilitySet::new())
.await
.expect("gw2 announce");
let dest_id = dest.node_id();
let gw2_id = gw2.node_id();
let deadline = tokio::time::Instant::now() + Duration::from_secs(10);
loop {
if let Some(hop) = gw1.authenticated_next_hop(dest_id) {
assert_eq!(
hop.node_id, gw2_id,
"the learned route must bind the ADJACENT authenticated peer",
);
break;
}
assert!(
tokio::time::Instant::now() < deadline,
"gw1 never learned an identity-bound route to dest through \
production propagation",
);
tokio::time::sleep(Duration::from_millis(50)).await;
}
TwoGatewayFixture {
source,
gw1,
gw2,
dest,
outsider,
}
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn a_two_gateway_route_reauthenticates_every_hop() {
let f = two_gateway_fixture(SubnetRights::ROUTE).await;
let dest_id = f.dest.node_id();
let watcher = wire().await;
assert!(f
.gw2
.set_peer_addr_for_test(dest_id, watcher.local_addr().expect("addr")));
let header = RoutingHeader::new(dest_id, f.source.node_id() as u32, 8);
let envelope = f
.source
.seal_route_hop_to_peer(f.gw1.node_id(), &header, INNER_TAG)
.expect("the source seals ONLY to its adjacent gateway");
let sock = wire().await;
sock.send_to(&envelope, f.gw1.local_addr())
.await
.expect("send");
let got = received_within(&watcher, Duration::from_millis(1500)).await;
let hops = route_hops(&got);
assert_eq!(
hops.len(),
1,
"exactly one hop reaches the destination side"
);
let (out_header, out_inner) = f
.dest
.open_route_hop_from_peer(f.gw2.node_id(), hops[0])
.expect("the final hop verifies under the gw2↔dest edge key");
assert_eq!(
out_header.dest_id, dest_id,
"the destination rides through BOTH relays unchanged",
);
assert_eq!(
out_inner, INNER_TAG,
"evidence 20: the inner packet is preserved byte for byte",
);
assert_eq!(
out_header.ttl,
header.ttl - 2,
"outer TTL decrements exactly once per relay",
);
assert_eq!(
out_header.hop_count,
header.hop_count + 2,
"outer hop_count increments exactly once per relay",
);
assert_eq!(
got.iter()
.filter(|d| d.len() >= 2 && u16::from_le_bytes([d[0], d[1]]) != ROUTE_HOP_MAGIC)
.count(),
got.len() - hops.len(),
"no protected packet may degrade to the legacy path",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn removing_the_second_gateways_exact_right_stops_the_hop() {
let f = two_gateway_fixture(SubnetRights::ATTACH).await;
let dest_id = f.dest.node_id();
let watcher = wire().await;
assert!(f
.gw2
.set_peer_addr_for_test(dest_id, watcher.local_addr().expect("addr")));
let gw1_forwarded = f.gw1.protected_relay_stats().forwarded();
let gw2_forwarded = f.gw2.protected_relay_stats().forwarded();
let gw2_denied = |d: ForwardDenial| f.gw2.protected_relay_stats().denied(d);
let gw2_route_missing = gw2_denied(ForwardDenial::RouteMissing);
let gw2_other_denials = [
ForwardDenial::ContextNotCurrent,
ForwardDenial::AttachMissing,
ForwardDenial::ExportMissing,
]
.map(&gw2_denied);
let header = RoutingHeader::new(dest_id, f.source.node_id() as u32, 8);
let envelope = f
.source
.seal_route_hop_to_peer(f.gw1.node_id(), &header, INNER_TAG)
.expect("seal to gw1");
let sock = wire().await;
sock.send_to(&envelope, f.gw1.local_addr())
.await
.expect("send");
let got = received_within(&watcher, Duration::from_millis(800)).await;
assert!(
route_hops(&got).is_empty(),
"without ROUTE at the second gateway no protected hop may reach \
the destination side — the first relay's authority must not \
carry the packet through the second",
);
assert!(
wait_until(Duration::from_secs(5), || {
f.gw1.protected_relay_stats().forwarded() == gw1_forwarded + 1
})
.await,
"gw1 must have forwarded the envelope toward gw2 (got {}, baseline {})",
f.gw1.protected_relay_stats().forwarded(),
gw1_forwarded,
);
assert!(
wait_until(Duration::from_secs(5), || {
gw2_denied(ForwardDenial::RouteMissing) == gw2_route_missing + 1
})
.await,
"gw2 must have denied exactly one transition as RouteMissing \
(got {}, baseline {})",
gw2_denied(ForwardDenial::RouteMissing),
gw2_route_missing,
);
assert_eq!(
[
ForwardDenial::ContextNotCurrent,
ForwardDenial::AttachMissing,
ForwardDenial::ExportMissing,
]
.map(&gw2_denied),
gw2_other_denials,
"no other denial reason may move — the mutated axis is ROUTE",
);
assert_eq!(
f.gw2.protected_relay_stats().forwarded(),
gw2_forwarded,
"gw2 forwarded nothing while its ROUTE right was absent",
);
let g2_kp = EntityKeypair::from_bytes([0xD3; 32]);
f.gw2
.install_subnet_gateway_credentials(&[vb_grant(
&g2_kp,
VEHICLE,
SubnetRights::ATTACH.union(SubnetRights::ROUTE),
)])
.expect("restore gw2's ROUTE credential");
let header = RoutingHeader::new(dest_id, f.source.node_id() as u32, 8);
let envelope = f
.source
.seal_route_hop_to_peer(f.gw1.node_id(), &header, INNER_TAG)
.expect("seal to gw1 after restoration");
sock.send_to(&envelope, f.gw1.local_addr())
.await
.expect("send after restoration");
let got = received_within(&watcher, Duration::from_millis(1500)).await;
let hops = route_hops(&got);
assert_eq!(
hops.len(),
1,
"with ROUTE restored the hop reaches the destination side",
);
let (out_header, out_inner) = f
.dest
.open_route_hop_from_peer(f.gw2.node_id(), hops[0])
.expect("the restored hop verifies under the gw2↔dest edge key");
assert_eq!(out_header.dest_id, dest_id);
assert_eq!(out_inner, INNER_TAG, "the inner packet is preserved");
assert_eq!(
f.gw2.protected_relay_stats().forwarded(),
gw2_forwarded + 1,
"recovery is attributable to gw2's restored authority",
);
assert_eq!(
gw2_denied(ForwardDenial::RouteMissing),
gw2_route_missing + 1,
"and no further RouteMissing denial was recorded",
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn forged_locator_fields_select_no_authority() {
let f = two_gateway_fixture(SubnetRights::ROUTE).await;
let dest_id = f.dest.node_id();
let outsider = f.outsider.clone();
let watcher = wire().await;
assert!(f
.gw2
.set_peer_addr_for_test(dest_id, watcher.local_addr().expect("addr")));
let forged = RoutingHeader::new(dest_id, f.source.node_id() as u32, 8);
let envelope = outsider
.seal_route_hop_to_peer(f.gw1.node_id(), &forged, INNER_TAG)
.expect("the outsider has a session to gw1");
let sock = wire().await;
sock.send_to(&envelope, f.gw1.local_addr())
.await
.expect("send");
assert!(
route_hops(&received_within(&watcher, Duration::from_millis(800)).await).is_empty(),
"evidence 19: neither a forged RoutingHeader.src_id nor a forged \
UDP source may select an ingress context",
);
let header = RoutingHeader::new(dest_id, f.source.node_id() as u32, 8);
let good = f
.source
.seal_route_hop_to_peer(f.gw1.node_id(), &header, INNER_TAG)
.expect("seal to gw1");
let sock2 = wire().await;
sock2
.send_to(&good, f.gw1.local_addr())
.await
.expect("send");
assert_eq!(
route_hops(&received_within(&watcher, Duration::from_millis(1500)).await).len(),
1,
"the admitted source is forwarded regardless of source address",
);
}
const HOSTILE_CLAIM: [u8; 16] = [0xC1; 16];
const HOSTILE_CLAIM_LEVEL: u8 = 7;
fn hostile_claim_policy() -> Arc<SubnetPolicy> {
let tag = SubnetClaimTag::from_bytes(HOSTILE_CLAIM).to_tag();
let value = tag
.strip_prefix(SUBNET_TAG_PREFIX)
.expect("to_tag renders the canonical prefix")
.to_string();
Arc::new(
SubnetPolicy::new()
.add_rule(SubnetRule::new(SUBNET_TAG_PREFIX, 0).map(value, HOSTILE_CLAIM_LEVEL)),
)
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn a_forged_inner_subnet_id_and_topology_claim_select_no_authority() {
let f = two_gateway_fixture_with_gw1_policy(SubnetRights::ROUTE, Some(hostile_claim_policy()))
.await;
let dest_id = f.dest.node_id();
let outsider = f.outsider.clone();
assert!(
f.gw1.peer_subnet(outsider.node_id()).is_none(),
"gw1 must have derived no subnet for the outsider yet",
);
outsider
.announce_capabilities(
CapabilitySet::new()
.add_tag(SubnetClaimTag::from_bytes(HOSTILE_CLAIM).to_tag())
.add_tag("vehicle:b")
.add_tag("perception"),
)
.await
.expect("outsider announces");
let claimed = SubnetId::new(&[HOSTILE_CLAIM_LEVEL]);
assert!(
wait_until(Duration::from_secs(5), || f
.gw1
.peer_subnet(outsider.node_id())
== Some(claimed))
.await,
"gw1 must ACTUALLY record the outsider's self-declared subnet in \
peer_subnets — asserting against a weaker observation (an entity \
pin the handshake already established) would prove nothing about \
the claim being powerless downstream",
);
assert!(
f.gw1.subnet_context_for(outsider.node_id()).is_none(),
"evidence 19: a topology claim that reached peer_subnets installs \
no admitted ingress context",
);
let watcher = wire().await;
assert!(f
.gw2
.set_peer_addr_for_test(dest_id, watcher.local_addr().expect("addr")));
let mut inner = NetHeader::new(
0,
0,
1,
[0u8; NONCE_SIZE],
INNER_TAG.len() as u16,
1,
PacketFlags::NONE,
);
inner.subnet_id = TopologySubnetId::new(VEHICLE).raw();
let mut forged_inner = inner.to_bytes().to_vec();
forged_inner.extend_from_slice(INNER_TAG);
let header = RoutingHeader::new(dest_id, f.source.node_id() as u32, 8);
let envelope = outsider
.seal_route_hop_to_peer(f.gw1.node_id(), &header, &forged_inner)
.expect("the outsider has a session to gw1");
let sock = wire().await;
sock.send_to(&envelope, f.gw1.local_addr())
.await
.expect("send");
assert!(
route_hops(&received_within(&watcher, Duration::from_millis(800)).await).is_empty(),
"evidence 19: a forged inner NetHeader.subnet_id — with a published \
topology claim behind it — must not pass a protected relay",
);
let good = f
.source
.seal_route_hop_to_peer(f.gw1.node_id(), &header, &forged_inner)
.expect("seal from the admitted source");
let sock2 = wire().await;
sock2
.send_to(&good, f.gw1.local_addr())
.await
.expect("send");
assert_eq!(
route_hops(&received_within(&watcher, Duration::from_millis(1500)).await).len(),
1,
"the admitted source carries the identical inner bytes through — \
the inner subnet_id was never what authorized anything",
);
}