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 DomainError = crate::domain::error::Error;
|
|
|
|
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]
|
|
|
|
impl BackendHandler for TestTcpBackendHandler {
|
|
|
|
async fn bind(&self, request: BindRequest) -> DomainResult<()>;
|
|
|
|
async fn list_users(&self, request: ListUsersRequest) -> DomainResult<Vec<User>>;
|
|
|
|
async fn list_groups(&self) -> DomainResult<Vec<Group>>;
|
|
|
|
async fn get_user_groups(&self, user: String) -> DomainResult<HashSet<String>>;
|
2021-05-26 06:43:31 +00:00
|
|
|
async fn create_user(&self, request: CreateUserRequest) -> DomainResult<()>;
|
2021-05-30 19:11:13 +00:00
|
|
|
async fn delete_user(&self, request: DeleteUserRequest) -> DomainResult<()>;
|
2021-05-26 13:42:02 +00:00
|
|
|
async fn create_group(&self, request: CreateGroupRequest) -> DomainResult<i32>;
|
2021-05-26 13:49:59 +00:00
|
|
|
async fn add_user_to_group(&self, request: AddUserToGroupRequest) -> 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
|
|
|
}
|
|
|
|
}
|