pub trait AuthIdentity: Send + Sync {
fn id(&self) -> String;
fn is_authenticated(&self) -> bool;
fn is_admin(&self) -> bool;
fn is_account_active(&self) -> bool {
true
}
}
#[cfg(test)]
mod tests {
use super::AuthIdentity;
struct LegacyIdentity;
impl AuthIdentity for LegacyIdentity {
fn id(&self) -> String {
"legacy".to_string()
}
fn is_authenticated(&self) -> bool {
true
}
fn is_admin(&self) -> bool {
false
}
}
#[test]
fn legacy_identity_defaults_to_active() {
let identity = LegacyIdentity;
assert!(identity.is_account_active());
}
}