feat: identity: delete_user service

This commit is contained in:
Aravinth Manivannan 2024-05-18 00:09:47 +05:30
parent b4e56cc9a1
commit 5d49ecee5c
Signed by: realaravinth
GPG key ID: F8F50389936984FF
5 changed files with 102 additions and 4 deletions

View file

@ -1 +1,45 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use super::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd)]
pub struct DeleteUserCommand;
impl DeleteUserCommand {
pub fn new(
_username: String,
supplied_password: String,
actual_password_hash: &str,
) -> IdentityCommandResult<Self> {
if !argon2_creds::Config::verify(actual_password_hash, &supplied_password).unwrap() {
return Err(IdentityCommandError::WrongPassword);
}
Ok(Self)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cmd() {
let config = argon2_creds::Config::default();
let password = "adsfasdfasd";
let hashed_password = config.password(password).unwrap();
DeleteUserCommand::new("realaravinth".into(), password.into(), &hashed_password);
assert_eq!(
DeleteUserCommand::new(
"realaravinth".into(),
"wrongpassword".into(),
&hashed_password,
)
.err(),
Some(IdentityCommandError::WrongPassword)
);
}
}

View file

@ -0,0 +1,3 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later

View file

@ -1,3 +1,18 @@
mod command;
mod error;
mod service;
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
pub mod command;
pub mod events;
pub mod service;
use super::errors::*;
#[async_trait::async_trait]
pub trait DeleteUserUseCase {
async fn delete_user(
&self,
cmd: command::DeleteUserCommand,
//) -> errors::ProcessAuthorizationServiceResult<String>;
);
}

View file

@ -1 +1,38 @@
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use super::*;
struct DeleteUserService;
#[async_trait::async_trait]
impl DeleteUserUseCase for DeleteUserService {
async fn delete_user(
&self,
_cmd: command::DeleteUserCommand,
//) -> errors::ProcessAuthorizationServiceResult<String>;
) {
}
}
#[cfg(test)]
mod tests {
use super::*;
#[actix_rt::test]
async fn test_service() {
let config = argon2_creds::Config::default();
let username = "realaravinth";
let password = "password";
let hashed_password = config.password(password).unwrap();
let s = DeleteUserService;
let cmd =
command::DeleteUserCommand::new(username.into(), password.into(), &hashed_password)
.unwrap();
s.delete_user(cmd).await;
}
}