diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index 442bfe2..64f8fa3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,8 +12,58 @@ fn main() { #[cfg(test)] mod tests { + use super::*; + use std::collections::HashMap; + #[test] - fn it_starts_a_server() { + fn test_oauth_server_creation() { + let server = sts::http::Server::new("127.0.0.1:0".to_string()); + // If we get here without panicking, the server was created successfully assert!(true); } + + #[test] + fn test_authorization_code_generation() { + let config = sts::Config::from_env(); + let oauth_server = sts::OAuthServer::new(&config); + let mut params = HashMap::new(); + params.insert("client_id".to_string(), "test_client".to_string()); + params.insert("redirect_uri".to_string(), "http://localhost:3000/callback".to_string()); + params.insert("response_type".to_string(), "code".to_string()); + params.insert("state".to_string(), "test_state".to_string()); + + let result = oauth_server.handle_authorize(¶ms); + assert!(result.is_ok()); + + let redirect_url = result.unwrap(); + assert!(redirect_url.contains("code=")); + assert!(redirect_url.contains("state=test_state")); + } + + #[test] + fn test_missing_client_id() { + let config = sts::Config::from_env(); + let oauth_server = sts::OAuthServer::new(&config); + let mut params = HashMap::new(); + params.insert("redirect_uri".to_string(), "http://localhost:3000/callback".to_string()); + params.insert("response_type".to_string(), "code".to_string()); + + let result = oauth_server.handle_authorize(¶ms); + assert!(result.is_err()); + assert!(result.unwrap_err().contains("invalid_request")); + } + + #[test] + fn test_unsupported_response_type() { + let config = sts::Config::from_env(); + let oauth_server = sts::OAuthServer::new(&config); + let mut params = HashMap::new(); + params.insert("client_id".to_string(), "test_client".to_string()); + params.insert("redirect_uri".to_string(), "http://localhost:3000/callback".to_string()); + params.insert("response_type".to_string(), "token".to_string()); + + let result = oauth_server.handle_authorize(¶ms); + assert!(result.is_err()); + assert!(result.unwrap_err().contains("unsupported_response_type")); + } } |
