http_auth.rs (1593B)
1 #![forbid(unsafe_code)] 2 3 use crate::kinds::KIND_HTTP_AUTH as KIND_HTTP_AUTH_EVENT; 4 5 #[cfg(not(feature = "std"))] 6 use alloc::string::String; 7 8 pub const KIND_HTTP_AUTH: u32 = KIND_HTTP_AUTH_EVENT; 9 10 #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] 11 #[derive(Clone, Debug, PartialEq, Eq)] 12 pub struct RadrootsHttpAuth { 13 pub url: String, 14 pub method: String, 15 pub payload_sha256: Option<String>, 16 } 17 18 #[cfg(all(test, feature = "serde"))] 19 mod tests { 20 use super::*; 21 22 #[test] 23 fn http_auth_kind_matches_nip98() { 24 assert_eq!(KIND_HTTP_AUTH, 27235); 25 } 26 27 #[test] 28 fn http_auth_serializes_optional_payload_hash() { 29 let value = serde_json::to_value(RadrootsHttpAuth { 30 url: "https://media.example.invalid/upload".to_string(), 31 method: "POST".to_string(), 32 payload_sha256: Some( 33 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef".to_string(), 34 ), 35 }) 36 .unwrap(); 37 38 assert_eq!(value["url"], "https://media.example.invalid/upload"); 39 assert_eq!(value["method"], "POST"); 40 assert_eq!( 41 value["payload_sha256"], 42 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" 43 ); 44 } 45 46 #[test] 47 fn http_auth_allows_absent_payload_hash() { 48 let auth = RadrootsHttpAuth { 49 url: "https://media.example.invalid/download".to_string(), 50 method: "GET".to_string(), 51 payload_sha256: None, 52 }; 53 54 assert_eq!(auth.payload_sha256, None); 55 } 56 }