redaction.rs (1728B)
1 use harvestcircle_application::{AppSnapshot, RelayConfiguration, SessionState, SnapshotRevision}; 2 use harvestcircle_domain::{ 3 IdentityCreatedAt, LocalKeyringBinding, NostrIdentity, NostrIdentityReference, PublicKey, 4 SafeError, SafeErrorCode, SafeMessage, SignerAvailability, UnixTimestamp, 5 }; 6 7 const SECRET_HEX: &str = "1111111111111111111111111111111111111111111111111111111111111111"; 8 const SECRET_NSEC: &str = "nsec1vl029mgpspedva04g90vltkh6fvh240zqtv9k0t9af8935ke9laqsnlfe5"; 9 fn assert_redacted(text: &str) { 10 assert!(!text.contains(SECRET_HEX)); 11 assert!(!text.contains(SECRET_NSEC)); 12 assert!(!text.contains("nsec1")); 13 } 14 15 #[test] 16 fn redaction_guards_public_snapshot_and_safe_error_debug() { 17 let identity = NostrIdentity::new( 18 NostrIdentityReference::derive(PublicKey::from_bytes([7; 32]).expect("valid public key")) 19 .expect("identity"), 20 LocalKeyringBinding::new( 21 PublicKey::from_bytes([7; 32]).expect("valid public key"), 22 SignerAvailability::Available, 23 ), 24 None, 25 IdentityCreatedAt::new(UnixTimestamp::from_seconds(1).expect("time")), 26 None, 27 ) 28 .expect("identity"); 29 let snapshot = AppSnapshot::ready( 30 SnapshotRevision::from_value(1), 31 RelayConfiguration::default(), 32 vec![identity.clone()], 33 Some(identity.public_key()), 34 SessionState::SignedOut, 35 None, 36 None, 37 ) 38 .expect("snapshot"); 39 let error = SafeError::new( 40 SafeErrorCode::KeyringUnavailable, 41 SafeMessage::new("The operating system credential store is unavailable."), 42 ); 43 44 assert_redacted(&format!("{snapshot:?}")); 45 assert_redacted(&format!("{error:?} {error}")); 46 }