2021-05-20 17:18:15 +00:00
|
|
|
use async_trait::async_trait;
|
2021-05-23 14:20:26 +00:00
|
|
|
use std::collections::HashSet;
|
2021-05-20 17:18:15 +00:00
|
|
|
|
2021-11-21 10:33:11 +00:00
|
|
|
use crate::domain::error::Result;
|
2021-05-20 17:18:15 +00:00
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
pub trait TcpBackendHandler {
|
|
|
|
async fn get_jwt_blacklist(&self) -> anyhow::Result<HashSet<u64>>;
|
2021-11-21 10:33:11 +00:00
|
|
|
async fn create_refresh_token(&self, user: &str) -> Result<(String, chrono::Duration)>;
|
|
|
|
async fn check_token(&self, refresh_token_hash: u64, user: &str) -> Result<bool>;
|
|
|
|
async fn blacklist_jwts(&self, user: &str) -> Result<HashSet<u64>>;
|
|
|
|
async fn delete_refresh_token(&self, refresh_token_hash: u64) -> Result<()>;
|
|
|
|
|
|
|
|
/// Request a token to reset a user's password.
|
|
|
|
/// If the user doesn't exist, returns `Ok(None)`, otherwise `Ok(Some(token))`.
|
|
|
|
async fn start_password_reset(&self, user: &str) -> Result<Option<String>>;
|
|
|
|
|
|
|
|
/// Get the user ID associated with a password reset token.
|
|
|
|
async fn get_user_id_for_password_reset_token(&self, token: &str) -> Result<String>;
|
2021-11-21 17:09:29 +00:00
|
|
|
|
|
|
|
async fn delete_password_reset_token(&self, token: &str) -> Result<()>;
|
2021-05-20 17:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
use crate::domain::handler::*;
|
|
|
|
#[cfg(test)]
|
|
|
|
mockall::mock! {
|
|
|
|
pub TestTcpBackendHandler{}
|
|
|
|
impl Clone for TestTcpBackendHandler {
|
|
|
|
fn clone(&self) -> Self;
|
|
|
|
}
|
|
|
|
#[async_trait]
|
2021-06-16 20:04:11 +00:00
|
|
|
impl LoginHandler for TestTcpBackendHandler {
|
2021-11-21 10:33:11 +00:00
|
|
|
async fn bind(&self, request: BindRequest) -> Result<()>;
|
2021-06-16 20:04:11 +00:00
|
|
|
}
|
|
|
|
#[async_trait]
|
|
|
|
impl BackendHandler for TestTcpBackendHandler {
|
2022-02-11 08:10:28 +00:00
|
|
|
async fn list_users(&self, filters: Option<UserRequestFilter>) -> Result<Vec<User>>;
|
2022-02-12 10:00:02 +00:00
|
|
|
async fn list_groups(&self, filters: Option<GroupRequestFilter>) -> Result<Vec<Group>>;
|
2021-11-21 10:33:11 +00:00
|
|
|
async fn get_user_details(&self, user_id: &str) -> Result<User>;
|
|
|
|
async fn get_group_details(&self, group_id: GroupId) -> Result<GroupIdAndName>;
|
|
|
|
async fn get_user_groups(&self, user: &str) -> Result<HashSet<GroupIdAndName>>;
|
|
|
|
async fn create_user(&self, request: CreateUserRequest) -> Result<()>;
|
|
|
|
async fn update_user(&self, request: UpdateUserRequest) -> Result<()>;
|
|
|
|
async fn update_group(&self, request: UpdateGroupRequest) -> Result<()>;
|
|
|
|
async fn delete_user(&self, user_id: &str) -> Result<()>;
|
|
|
|
async fn create_group(&self, group_name: &str) -> Result<GroupId>;
|
|
|
|
async fn delete_group(&self, group_id: GroupId) -> Result<()>;
|
|
|
|
async fn add_user_to_group(&self, user_id: &str, group_id: GroupId) -> Result<()>;
|
|
|
|
async fn remove_user_from_group(&self, user_id: &str, group_id: GroupId) -> Result<()>;
|
2021-05-20 17:18:15 +00:00
|
|
|
}
|
|
|
|
#[async_trait]
|
|
|
|
impl TcpBackendHandler for TestTcpBackendHandler {
|
|
|
|
async fn get_jwt_blacklist(&self) -> anyhow::Result<HashSet<u64>>;
|
2021-11-21 10:33:11 +00:00
|
|
|
async fn create_refresh_token(&self, user: &str) -> Result<(String, chrono::Duration)>;
|
|
|
|
async fn check_token(&self, refresh_token_hash: u64, user: &str) -> Result<bool>;
|
|
|
|
async fn blacklist_jwts(&self, user: &str) -> Result<HashSet<u64>>;
|
|
|
|
async fn delete_refresh_token(&self, refresh_token_hash: u64) -> Result<()>;
|
|
|
|
async fn start_password_reset(&self, user: &str) -> Result<Option<String>>;
|
|
|
|
async fn get_user_id_for_password_reset_token(&self, token: &str) -> Result<String>;
|
2021-11-21 17:09:29 +00:00
|
|
|
async fn delete_password_reset_token(&self, token: &str) -> Result<()>;
|
2021-05-20 17:18:15 +00:00
|
|
|
}
|
|
|
|
}
|