use limes_proto::{AuthFailure, AuthRequest};
use crate::auth::traits::{AuthBackend, AuthenticatedLogin};
#[derive(Debug, Clone, Copy, Default)]
pub struct NoopLockBackend;
impl AuthBackend for NoopLockBackend {
fn authenticate(
&self,
_request: &AuthRequest,
) -> std::result::Result<AuthenticatedLogin, AuthFailure> {
Err(AuthFailure::BackendUnavailable(
"no lock authentication backend is configured".to_owned(),
))
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::auth::traits::LockAuthBackend;
#[test]
fn noop_lock_backend_rejects_authentication() {
assert!(matches!(
AuthBackend::authenticate(&NoopLockBackend, &AuthRequest::new("alice", "secret")),
Err(AuthFailure::BackendUnavailable(_))
));
}
#[test]
fn noop_lock_backend_is_usable_as_lock_auth_backend() {
let backend: &dyn LockAuthBackend = &NoopLockBackend;
assert!(matches!(
backend.authenticate(&AuthRequest::new("alice", "secret")),
Err(AuthFailure::BackendUnavailable(_))
));
}
}