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
|
|
|
|
|
|
|
pub type DomainResult<T> = crate::domain::error::Result<T>;
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
pub trait TcpBackendHandler {
|
|
|
|
async fn get_jwt_blacklist(&self) -> anyhow::Result<HashSet<u64>>;
|
|
|
|
async fn create_refresh_token(&self, user: &str) -> DomainResult<(String, chrono::Duration)>;
|
2021-05-23 14:26:24 +00:00
|
|
|
async fn check_token(&self, refresh_token_hash: u64, user: &str) -> DomainResult<bool>;
|
2021-05-23 14:20:26 +00:00
|
|
|
async fn blacklist_jwts(&self, user: &str) -> DomainResult<HashSet<u64>>;
|
2021-05-23 14:26:24 +00:00
|
|
|
async fn delete_refresh_token(&self, refresh_token_hash: u64) -> DomainResult<()>;
|
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-05-20 17:18:15 +00:00
|
|
|
async fn bind(&self, request: BindRequest) -> DomainResult<()>;
|
2021-06-16 20:04:11 +00:00
|
|
|
}
|
|
|
|
#[async_trait]
|
|
|
|
impl BackendHandler for TestTcpBackendHandler {
|
2021-08-30 08:18:59 +00:00
|
|
|
async fn list_users(&self, filters: Option<RequestFilter>) -> DomainResult<Vec<User>>;
|
2021-05-20 17:18:15 +00:00
|
|
|
async fn list_groups(&self) -> DomainResult<Vec<Group>>;
|
2021-08-31 13:48:45 +00:00
|
|
|
async fn get_user_details(&self, user_id: &str) -> DomainResult<User>;
|
2021-09-16 07:26:31 +00:00
|
|
|
async fn get_user_groups(&self, user: &str) -> DomainResult<HashSet<GroupIdAndName>>;
|
2021-05-26 06:43:31 +00:00
|
|
|
async fn create_user(&self, request: CreateUserRequest) -> DomainResult<()>;
|
2021-09-01 08:00:51 +00:00
|
|
|
async fn update_user(&self, request: UpdateUserRequest) -> DomainResult<()>;
|
2021-08-31 13:53:51 +00:00
|
|
|
async fn delete_user(&self, user_id: &str) -> DomainResult<()>;
|
2021-08-31 14:16:17 +00:00
|
|
|
async fn create_group(&self, group_name: &str) -> DomainResult<GroupId>;
|
2021-09-24 15:35:46 +00:00
|
|
|
async fn delete_group(&self, group_id: GroupId) -> DomainResult<()>;
|
2021-08-31 14:16:17 +00:00
|
|
|
async fn add_user_to_group(&self, user_id: &str, group_id: GroupId) -> DomainResult<()>;
|
2021-09-15 07:45:17 +00:00
|
|
|
async fn remove_user_from_group(&self, user_id: &str, group_id: GroupId) -> DomainResult<()>;
|
2021-05-20 17:18:15 +00:00
|
|
|
}
|
|
|
|
#[async_trait]
|
|
|
|
impl TcpBackendHandler for TestTcpBackendHandler {
|
|
|
|
async fn get_jwt_blacklist(&self) -> anyhow::Result<HashSet<u64>>;
|
|
|
|
async fn create_refresh_token(&self, user: &str) -> DomainResult<(String, chrono::Duration)>;
|
2021-05-23 14:26:24 +00:00
|
|
|
async fn check_token(&self, refresh_token_hash: u64, user: &str) -> DomainResult<bool>;
|
2021-05-23 14:20:26 +00:00
|
|
|
async fn blacklist_jwts(&self, user: &str) -> DomainResult<HashSet<u64>>;
|
2021-05-23 14:26:24 +00:00
|
|
|
async fn delete_refresh_token(&self, refresh_token_hash: u64) -> DomainResult<()>;
|
2021-05-20 17:18:15 +00:00
|
|
|
}
|
|
|
|
}
|