From 78e1b80d1cf2bdcf44fb8060907b22b512898a15 Mon Sep 17 00:00:00 2001 From: Colin Reeder Date: Sat, 6 Jan 2024 11:35:10 -0700 Subject: [PATCH] Add test for signature creation --- src/httpbis.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/httpbis.rs b/src/httpbis.rs index d576f82..8758a06 100644 --- a/src/httpbis.rs +++ b/src/httpbis.rs @@ -897,4 +897,50 @@ mod test { assert!(result); } + + #[test] + fn test_create_minimal() { + let req = get_sample_request(); + + let sig = HttpbisSignature::create_for_request( + "test_create_minimal", + SignatureParams { + created: Some(1618884473), + nonce: Some("b3k2pp5k7z-50gnwp.yemd".into()), + ..Default::default() + }, + &[][..], + &req, + |content| { + assert_eq!( + content, + br#""@signature-params": ();created=1618884473;nonce="b3k2pp5k7z-50gnwp.yemd""# + ); + Result::<_, std::convert::Infallible>::Ok(Vec::new()) + }, + ) + .unwrap(); + + let mut target = http::HeaderMap::new(); + sig.apply_headers(&mut target).unwrap(); + + assert_eq!(target.len(), 2); + + assert_eq!( + target + .get(SIGNATURE_INPUT_HEADER) + .unwrap() + .to_str() + .unwrap(), + r#"test_create_minimal=();created=1618884473;nonce="b3k2pp5k7z-50gnwp.yemd""# + ); + assert_eq!( + target + .get(crate::SIGNATURE_HEADER) + .unwrap() + .to_str() + .unwrap(), + r#"test_create_minimal=::"# + ); + } } -- 2.45.2