From bc3cdabe9cad993d515b1cd019c4bd381613a594 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 1 Aug 2025 15:52:43 -0400 Subject: [PATCH] Added test --- src/token.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/token.rs b/src/token.rs index 205c524..2def3fd 100644 --- a/src/token.rs +++ b/src/token.rs @@ -66,10 +66,12 @@ pub fn get_issued() -> time::Result { Ok(time::OffsetDateTime::now_utc()) } +/* pub fn get_expiration(issued: &time::OffsetDateTime) -> Result { let duration_expire = time::Duration::hours(4); Ok(*issued + duration_expire) } +*/ mod util { pub fn time_to_std_time( @@ -143,4 +145,25 @@ mod tests { check_scope, token.scope ); } + + #[test] + fn test_token_creation() { + let key = String::from("c3092urmc2219ix320i40m293ic29IM09IN0u879Y8B98YB8yb86TN7B55R4yv4RCVU6Bi8YO8U"); + let test_token_resource = TokenResource { + issuer: String::from("icarus_auth_test"), + message: String::from("Authorization"), + audiences: vec![String::from("icarus_test")] + }; + let token_expiration_duration = time::Duration::hours(2); + + match create_token(&key, &test_token_resource, token_expiration_duration) { + Ok((token, expire_duration)) => { + assert_eq!(false, token.is_empty(), "Error: Token is empty"); + assert!(expire_duration > 0, "Token expire duration is invalid {expire_duration:?}"); + } + Err(err) => { + assert!(false, "Error: {err:?}"); + } + } + } }