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-08-26 08:00:49 +00:00
|
|
|
async fn get_user_groups(&self, user: &str) -> DomainResult<HashSet<String>>;
|
2021-05-26 06:43:31 +00:00
|
|
|
async fn create_user(&self, request: CreateUserRequest) -> 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>;
|
|
|
|
async fn add_user_to_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
|
|
|
}
|
|
|
|
}
|