mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 18:15:39 +00:00
demo user task
This commit is contained in:
@@ -47,9 +47,7 @@ async fn delete_account(
|
||||
match rec {
|
||||
Ok(s) => {
|
||||
if Config::verify(&s.password, &payload.password)? {
|
||||
sqlx::query!("DELETE FROM mcaptcha_users WHERE name = ($1)", &username)
|
||||
.execute(&data.db)
|
||||
.await?;
|
||||
runners::delete_user(&username, &data).await?;
|
||||
id.forget();
|
||||
Ok(HttpResponse::Ok())
|
||||
} else {
|
||||
@@ -61,6 +59,18 @@ async fn delete_account(
|
||||
}
|
||||
}
|
||||
|
||||
pub mod runners {
|
||||
|
||||
use super::*;
|
||||
|
||||
pub async fn delete_user(name: &str, data: &AppData) -> ServiceResult<()> {
|
||||
sqlx::query!("DELETE FROM mcaptcha_users WHERE name = ($1)", name,)
|
||||
.execute(&data.db)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
cfg.service(delete_account);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
|
||||
use crate::api::v1::ROUTES;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
|
||||
use super::email::*;
|
||||
|
||||
@@ -24,11 +24,6 @@ use super::mcaptcha::get_random;
|
||||
use crate::errors::*;
|
||||
use crate::AppData;
|
||||
|
||||
/// Demo username
|
||||
pub const DEMO_USER: &str = "aaronsw";
|
||||
/// Demo password
|
||||
pub const DEMO_PASSWORD: &str = "password";
|
||||
|
||||
pub mod routes {
|
||||
pub struct Auth {
|
||||
pub logout: &'static str,
|
||||
@@ -199,21 +194,6 @@ pub mod runners {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// register demo user runner
|
||||
pub async fn register_demo_user(data: &AppData) -> ServiceResult<()> {
|
||||
let payload = runners::Register {
|
||||
username: DEMO_USER.into(),
|
||||
password: DEMO_PASSWORD.into(),
|
||||
confirm_password: DEMO_PASSWORD.into(),
|
||||
email: None,
|
||||
};
|
||||
|
||||
match register_runner(&payload, data).await {
|
||||
Err(ServiceError::UsernameTaken) | Ok(_) => Ok(()),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
|
||||
@@ -276,7 +276,7 @@ async fn get_stats(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -130,7 +130,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -241,7 +241,7 @@ async fn get_levels_util(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
pub mod captcha;
|
||||
pub mod duration;
|
||||
|
||||
@@ -61,7 +61,7 @@ pub async fn add_notification(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -98,7 +98,7 @@ pub mod runner {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -63,7 +63,7 @@ pub async fn mark_read(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -152,7 +152,7 @@ async fn init_mcaptcha(data: &AppData, key: &str) -> ServiceResult<()> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
use libmcaptcha::pow::PoWConfig;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ pub async fn verify_pow(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
use libmcaptcha::pow::PoWConfig;
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ pub async fn validate_captcha_token(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::test;
|
||||
use libmcaptcha::pow::PoWConfig;
|
||||
use libmcaptcha::pow::Work;
|
||||
|
||||
@@ -18,11 +18,7 @@
|
||||
use actix_web::http::{header, StatusCode};
|
||||
use actix_web::test;
|
||||
|
||||
use crate::api::v1::account::{username::runners::username_exists, AccountCheckPayload};
|
||||
use crate::api::v1::auth::{
|
||||
runners::{register_demo_user, Login, Register},
|
||||
DEMO_PASSWORD, DEMO_USER,
|
||||
};
|
||||
use crate::api::v1::auth::runners::{Login, Register};
|
||||
use crate::api::v1::ROUTES;
|
||||
use crate::data::Data;
|
||||
use crate::errors::*;
|
||||
@@ -167,17 +163,3 @@ async fn serverside_password_validation_works() {
|
||||
let txt: ErrorToResponse = test::read_body_json(resp).await;
|
||||
assert_eq!(txt.error, format!("{}", ServiceError::PasswordsDontMatch));
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn demo_account() {
|
||||
let data = AppData::new(Data::new().await);
|
||||
let _ = register_demo_user(&data).await.unwrap();
|
||||
|
||||
let payload = AccountCheckPayload {
|
||||
val: DEMO_USER.into(),
|
||||
};
|
||||
|
||||
assert!(username_exists(&payload, &data).await.unwrap().exists);
|
||||
|
||||
signin(DEMO_USER, DEMO_PASSWORD).await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user