pub trait AuthChecker: Send + Sync {
fn is_authenticated(&self) -> bool;
fn check_status(&self) -> AuthCheckResult;
}
#[derive(Debug, Clone)]
pub struct AuthCheckResult {
pub authenticated: bool,
pub user: Option<String>,
pub reason: Option<String>,
pub hint: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_should_create_authenticated_result() {
let result = AuthCheckResult {
authenticated: true,
user: Some("testuser".to_string()),
reason: None,
hint: None,
};
assert!(result.authenticated);
assert_eq!(result.user, Some("testuser".to_string()));
}
#[test]
fn test_should_create_not_authenticated_result() {
let result = AuthCheckResult {
authenticated: false,
user: None,
reason: Some("Not logged in".to_string()),
hint: Some("Run `gc auth login`".to_string()),
};
assert!(!result.authenticated);
assert!(result.reason.is_some());
assert!(result.hint.is_some());
}
#[test]
fn test_auth_checker_trait_is_object_safe() {
fn _takes_checker(_checker: &dyn AuthChecker) {}
}
}