use axum::http::StatusCode;
use larust_core::AppError;
pub fn authorize(allowed: bool) -> Result<(), AppError> {
if allowed {
Ok(())
} else {
Err(AppError::Http {
status: StatusCode::FORBIDDEN,
message: "This action is unauthorized.".to_string(),
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn allows_when_true() {
assert!(authorize(true).is_ok());
}
#[test]
fn rejects_with_403_when_false() {
let err = authorize(false).unwrap_err();
assert!(matches!(
err,
AppError::Http {
status: StatusCode::FORBIDDEN,
..
}
));
}
}