use os_release_acceptance::reproduction::{ compute_release_acceptance_reproduction_binding_digest, ReleaseAcceptanceReproductionCoordinator, ReleaseAcceptanceReproductionError, ReleaseAcceptanceReproductionRequest, EXPECTED_CLEAN_BUILD_ATTESTATIONS, EXPECTED_HASH_CHAIN_LINKS, EXPECTED_ISOLATED_REPRODUCTION_STAGES, EXPECTED_REUSED_TARGET_CACHE_ARTIFACTS, RELEASE_ACCEPTANCE_REPRODUCTION_ACCEPTANCE, RELEASE_ACCEPTANCE_REPRODUCTION_COUNTEREXAMPLE, RELEASE_ACCEPTANCE_REPRODUCTION_INVARIANT, RELEASE_ACCEPTANCE_REPRODUCTION_POSITIVE, RELEASE_ACCEPTANCE_REPRODUCTION_SCHEMA, }; const PREVIOUS_REPRODUCTION_EPOCH: u64 = 86; const REPRODUCTION_EPOCH: u64 = 87; const REPRODUCTION_CHAIN_DIGEST: u64 = 0x2485_5245_5052_4f44; fn valid_request() -> ReleaseAcceptanceReproductionRequest { let binding = compute_release_acceptance_reproduction_binding_digest( EXPECTED_ISOLATED_REPRODUCTION_STAGES, EXPECTED_HASH_CHAIN_LINKS, EXPECTED_CLEAN_BUILD_ATTESTATIONS, EXPECTED_REUSED_TARGET_CACHE_ARTIFACTS, REPRODUCTION_EPOCH, REPRODUCTION_CHAIN_DIGEST, ); ReleaseAcceptanceReproductionRequest { old_target_copied_into_build: false, target_cache_or_old_report_counted_as_new_evidence: false, source_to_output_hash_chain_measured: true, isolated_reproduction_stages: EXPECTED_ISOLATED_REPRODUCTION_STAGES, hash_chain_links: EXPECTED_HASH_CHAIN_LINKS, clean_build_attestations: EXPECTED_CLEAN_BUILD_ATTESTATIONS, reproduction_epoch: REPRODUCTION_EPOCH, previous_reproduction_epoch: PREVIOUS_REPRODUCTION_EPOCH, reproduction_chain_digest: REPRODUCTION_CHAIN_DIGEST, reproduction_binding_digest: binding, } } #[test] fn os_release_acceptance_reproduction_schema_and_constants() { assert_eq!( RELEASE_ACCEPTANCE_REPRODUCTION_SCHEMA, "turkos.os.release_acceptance.reproduction.v1" ); assert_eq!( RELEASE_ACCEPTANCE_REPRODUCTION_INVARIANT, "Target cache ve eski rapor yeni kanıt olmaz" ); assert_eq!( RELEASE_ACCEPTANCE_REPRODUCTION_POSITIVE, "İzole source toolchain imaj site" ); assert_eq!( RELEASE_ACCEPTANCE_REPRODUCTION_COUNTEREXAMPLE, "Eski target kopyalanır" ); assert_eq!( RELEASE_ACCEPTANCE_REPRODUCTION_ACCEPTANCE, "Kaynak ve çıktı hash zinciri ölçülür" ); } #[test] fn os_release_acceptance_reproduction_positive() { let mut coord = ReleaseAcceptanceReproductionCoordinator::new(); let req = valid_request(); let rec = coord.commit_clean_reproduction(&req).expect("positive commit"); assert!(coord.is_committed()); assert_eq!(coord.committed_total(), 1); assert_eq!(coord.rejected_total(), 0); assert_eq!( rec.isolated_reproduction_stages, EXPECTED_ISOLATED_REPRODUCTION_STAGES ); assert_eq!(rec.hash_chain_links, EXPECTED_HASH_CHAIN_LINKS); assert_eq!( rec.clean_build_attestations, EXPECTED_CLEAN_BUILD_ATTESTATIONS ); assert_eq!( rec.reused_target_cache_artifacts, EXPECTED_REUSED_TARGET_CACHE_ARTIFACTS ); assert!(rec.source_to_output_hash_chain_measured); assert_eq!(rec.reproduction_epoch, REPRODUCTION_EPOCH); assert_eq!(rec.reproduction_chain_digest, REPRODUCTION_CHAIN_DIGEST); assert_eq!( rec.receipt_digest, req.reproduction_binding_digest ^ 0x2485_ACE0_5250_5231 ); assert_eq!(coord.committed_receipt(), Some(rec)); assert_eq!( coord.commit_clean_reproduction(&req), Err(ReleaseAcceptanceReproductionError::AlreadyCommitted) ); assert_eq!(coord.rejected_total(), 1); } #[test] fn os_release_acceptance_reproduction_negative() { let mut coord = ReleaseAcceptanceReproductionCoordinator::new(); let base = valid_request(); let mut r1 = base; r1.old_target_copied_into_build = true; assert_eq!( coord.commit_clean_reproduction(&r1), Err(ReleaseAcceptanceReproductionError::OldTargetCopiedIntoBuild) ); assert_eq!(coord.reproduction_hygiene_refusals(), 1); let mut r2 = base; r2.target_cache_or_old_report_counted_as_new_evidence = true; assert_eq!( coord.commit_clean_reproduction(&r2), Err(ReleaseAcceptanceReproductionError::TargetCacheOrOldReportCountedAsNewEvidence) ); assert_eq!(coord.reproduction_hygiene_refusals(), 2); let mut r3 = base; r3.source_to_output_hash_chain_measured = false; assert_eq!( coord.commit_clean_reproduction(&r3), Err(ReleaseAcceptanceReproductionError::SourceToOutputHashChainUnmeasured) ); assert_eq!(coord.reproduction_hygiene_refusals(), 3); let mut r4 = base; r4.isolated_reproduction_stages = 0; assert_eq!( coord.commit_clean_reproduction(&r4), Err(ReleaseAcceptanceReproductionError::IsolatedReproductionStagesMismatch) ); assert_eq!(coord.reproduction_accounting_refusals(), 1); let mut r5 = base; r5.hash_chain_links = 0; assert_eq!( coord.commit_clean_reproduction(&r5), Err(ReleaseAcceptanceReproductionError::HashChainLinksMismatch) ); assert_eq!(coord.reproduction_accounting_refusals(), 2); let mut r6 = base; r6.clean_build_attestations = 0; assert_eq!( coord.commit_clean_reproduction(&r6), Err(ReleaseAcceptanceReproductionError::CleanBuildAttestationsMismatch) ); assert_eq!(coord.reproduction_accounting_refusals(), 3); let mut r7 = base; r7.reproduction_binding_digest ^= 1; assert_eq!( coord.commit_clean_reproduction(&r7), Err(ReleaseAcceptanceReproductionError::UnboundReleaseAcceptanceReproductionDigest) ); assert_eq!(coord.reproduction_accounting_refusals(), 4); assert_eq!(coord.rejected_total(), 7); assert!(!coord.is_committed()); assert_eq!(coord.committed_receipt(), None); } #[test] fn os_release_acceptance_reproduction_validation_and_bounds() { let mut coord = ReleaseAcceptanceReproductionCoordinator::new(); let base = valid_request(); let mut r1 = base; r1.reproduction_epoch = 0; assert_eq!( coord.commit_clean_reproduction(&r1), Err(ReleaseAcceptanceReproductionError::ZeroReproductionEpoch) ); let mut r2 = base; r2.reproduction_epoch = PREVIOUS_REPRODUCTION_EPOCH; assert_eq!( coord.commit_clean_reproduction(&r2), Err(ReleaseAcceptanceReproductionError::NonMonotonicReproductionEpoch) ); let mut r3 = base; r3.reproduction_chain_digest = 0; assert_eq!( coord.commit_clean_reproduction(&r3), Err(ReleaseAcceptanceReproductionError::ZeroReproductionChainDigest) ); assert_eq!(coord.rejected_total(), 3); }