use crate::runtime::auth::AuthService;
use crate::runtime::context::AuthContext;
#[derive(Debug, Clone)]
pub struct StaticAuthService {
context: AuthContext,
}
impl StaticAuthService {
pub fn new(app_name: impl Into<String>, user_name: impl Into<String>) -> Self {
Self {
context: AuthContext {
app_name: app_name.into(),
user_name: user_name.into(),
},
}
}
}
impl Default for StaticAuthService {
fn default() -> Self {
Self::new("default-app", "default-user")
}
}
impl AuthService for StaticAuthService {
fn get_auth_context(&self) -> AuthContext {
self.context.clone()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_uses_expected_values() {
let auth = StaticAuthService::default();
let context = auth.get_auth_context();
assert_eq!(context.app_name, "default-app");
assert_eq!(context.user_name, "default-user");
}
}