diff --git a/src/api/jwt.rs b/src/api/jwt.rs index ce1e70894..30b8f0374 100644 --- a/src/api/jwt.rs +++ b/src/api/jwt.rs @@ -7,3 +7,32 @@ pub use crate::openhuman::credentials::{APP_SESSION_PROVIDER, DEFAULT_AUTH_PROFI pub fn bearer_authorization_value(token: &str) -> String { format!("Bearer {}", token.trim()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_bearer_authorization_value() { + // Standard token + assert_eq!(bearer_authorization_value("my_token"), "Bearer my_token"); + + // Token with leading/trailing spaces + assert_eq!( + bearer_authorization_value(" spaced_token "), + "Bearer spaced_token" + ); + + // Empty string + assert_eq!(bearer_authorization_value(""), "Bearer "); + + // Whitespace only string + assert_eq!(bearer_authorization_value(" "), "Bearer "); + + // Token with internal spaces (should not be trimmed) + assert_eq!( + bearer_authorization_value("token with spaces"), + "Bearer token with spaces" + ); + } +}