command_obtained_tests.rs (5870B)
1 //! A refused storage descriptor must not discard authenticated original bytes. 2 use super::*; 3 use alloc::vec; 4 use radroots_domain::*; 5 use radroots_protocol::{ 6 command::CapturedOrderAcceptance, 7 commerce::{self, CommerceSigningPlan, EncodedCommerceRumor}, 8 intent::SigningReplay, 9 listing::{CapturedListingCommand, PublicSigningPlan, PublishInput}, 10 plan::SigningTarget, 11 }; 12 use radroots_signing::{ 13 issuance::{OutcomeKind, SigningIntent, SigningOutcome}, 14 provider::ProviderCall, 15 request::CancellationSignal, 16 }; 17 use radroots_storage::{ 18 command::{AdmissionRequest, BoundSigningPlan, PreparedOperation}, 19 workspace::{AttachmentInput, WorkspaceBinding, WorkspaceScope}, 20 }; 21 use std::num::NonZeroU64; 22 23 fn foreign_attempt() -> SigningAttempt { 24 let key = 25 PublicKey::from_hex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798") 26 .unwrap(); 27 let input = AttachmentInput::new( 28 WorkspaceId::from_bytes([1; 32]), 29 AuthorityRef::new(ExecutorId::from_bytes([2; 32]), Generation::new(1).unwrap()), 30 key, 31 "local://model", 32 key, 33 GrantId::from_bytes([3; 32]), 34 CheckpointRef::new( 35 CheckpointDigest::from_bytes([4; 32]), 36 Sequence::new(0).unwrap(), 37 Coverage::Partial, 38 vec![], 39 ) 40 .unwrap(), 41 RouteDigest::from_bytes([5; 32]), 42 ) 43 .unwrap(); 44 let binding = WorkspaceBinding::from_authenticated_host( 45 input.clone(), 46 WorkspaceScope::NewSellerOutbox, 47 ActorRef::new(key, ActorRole::Seller, None, Some(input.grant_id())), 48 "model", 49 Sequence::new(1).unwrap(), 50 UnixSeconds::new(200).unwrap(), 51 UnixSeconds::new(100).unwrap(), 52 ) 53 .unwrap(); 54 let context = CommandContextData::new( 55 OperationId::from_bytes([8; 32]), 56 binding.actor(), 57 input.workspace_id(), 58 input.authority(), 59 input.route_digest(), 60 None, 61 None, 62 UnixSeconds::new(150).unwrap(), 63 None, 64 ) 65 .unwrap(); 66 // Synthetic structural listing only; this descriptor has no store authority. 67 let listing = PublishInput::parse(br#"{ 68 "id":"01010101010101010101010101010101","title":"Carrots", 69 "summary":"Ask for terms","description_markdown":"Synthetic", 70 "published_at":"100","profile":{"profile":"radroots.listing","version":1, 71 "state":"active","product":{"name":"Carrots","description":"Synthetic","producer":null,"origin_summary":null}, 72 "default_option":"0202020202020202020202020202020202020202020202020202020202020202", 73 "options":[{"id":"0202020202020202020202020202020202020202020202020202020202020202", 74 "label":"Bunch","unit":{"type":"package","label":"bunch","contents":{"type":"unspecified"}}, 75 "minimum":"1","increment":"1","price":{"type":"quote_required"}, 76 "supply":{"type":"available","amount":"10"},"lead_seconds":"0"}], 77 "fulfillment":{"modes":["pickup"],"area":"Synthetic","lead_seconds":"0"}, 78 "authority":null,"media":[]}}"#).unwrap(); 79 let command = CapturedListingCommand::capture(context, listing).unwrap(); 80 let now = UnixSeconds::new(100).unwrap(); 81 let plan = PublicSigningPlan::capture( 82 &command, 83 now, 84 &["wss://synthetic.invalid".into()], 85 SigningReplay::NonReplayable, 86 ) 87 .unwrap(); 88 let prepared = PreparedOperation::from_committed_store( 89 AdmissionRequest::new(binding, command).unwrap(), 90 TransactionId::from_bytes([9; 32]), 91 Sequence::new(1).unwrap(), 92 IssuanceWindow::new(now, UnixSeconds::new(150).unwrap()).unwrap(), 93 ) 94 .unwrap(); 95 let bound = BoundSigningPlan::from_committed_store( 96 prepared, 97 plan, 98 TransactionId::from_bytes([10; 32]), 99 now, 100 ) 101 .unwrap(); 102 SigningAttempt::from_committed_store( 103 bound, 104 SigningTarget::PublicEvent, 105 SigningAttemptId::from_bytes([11; 32]), 106 TransactionId::from_bytes([12; 32]), 107 now, 108 ) 109 .unwrap() 110 } 111 112 #[test] 113 fn refused_descriptor_keeps_actual_obtained_bytes_and_original_observation() { 114 let command = CapturedOrderAcceptance::parse(include_bytes!( 115 "../../tests/fixtures/commerce_verification/command_wire.json" 116 )) 117 .unwrap(); 118 let record = commerce::decode(include_bytes!( 119 "../../tests/fixtures/commerce_verification/record_wire.json" 120 )) 121 .unwrap(); 122 let rumor = EncodedCommerceRumor::capture(record.content()).unwrap(); 123 let plan = CommerceSigningPlan::parse( 124 command.context().operation_id(), 125 command.digest(), 126 &rumor, 127 include_bytes!("../../tests/fixtures/commerce_verification/plan_wire.bin"), 128 ) 129 .unwrap(); 130 let intent = SigningIntent::from_commerce_seal( 131 &plan.seals()[0], 132 ProviderCall::new( 133 rumor.author(), 134 NonZeroU64::new(600000).unwrap(), 135 CancellationSignal::new(), 136 ), 137 ) 138 .unwrap(); 139 let wire = include_str!("../../tests/fixtures/commerce_verification/seal_signed.json"); 140 let (_, OutcomeKind::Obtained(artifact)) = 141 SigningOutcome::capture(&intent, wire.into(), None).into_parts() 142 else { 143 panic!("retained independent bytes must authenticate against the original intent") 144 }; 145 let event = artifact.event_id(); 146 let retained = Obtained::new(foreign_attempt(), artifact); 147 for _ in 0..2 { 148 assert!(matches!( 149 retained.evidence(), 150 Err(OperationError::InvalidEvidence) 151 )); 152 assert_eq!(retained.operation(), OperationId::from_bytes([8; 32])); 153 assert_eq!(retained.artifact.event_id(), event); 154 assert_eq!(retained.artifact.observed_at_unix_ms(), None); 155 retained.artifact.with_json(|raw| assert_eq!(raw, wire)); 156 } 157 }