mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-14 03:25:40 +00:00
rename from_user_provided_traffic_pattern to create_easy
isolate non-async test in separate module
This commit is contained in:
@@ -34,7 +34,9 @@ pub mod routes {
|
|||||||
pub delete: &'static str,
|
pub delete: &'static str,
|
||||||
pub update_key: &'static str,
|
pub update_key: &'static str,
|
||||||
pub stats: &'static str,
|
pub stats: &'static str,
|
||||||
pub user_provided_traffic_pattern: &'static str,
|
/// easy is using defaults
|
||||||
|
pub create_easy: &'static str,
|
||||||
|
pub update_easy: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MCaptcha {
|
impl MCaptcha {
|
||||||
@@ -43,8 +45,8 @@ pub mod routes {
|
|||||||
update_key: "/api/v1/mcaptcha/update/key",
|
update_key: "/api/v1/mcaptcha/update/key",
|
||||||
delete: "/api/v1/mcaptcha/delete",
|
delete: "/api/v1/mcaptcha/delete",
|
||||||
stats: "/api/v1/mcaptcha/stats",
|
stats: "/api/v1/mcaptcha/stats",
|
||||||
user_provided_traffic_pattern:
|
create_easy: "/api/v1/mcaptcha/add/easy",
|
||||||
"/api/v1/mcaptcha/add/user-provided-traffic-pattern",
|
update_easy: "/api/v1/mcaptcha/update/easy",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,7 +56,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||||||
cfg.service(update_token);
|
cfg.service(update_token);
|
||||||
cfg.service(delete_mcaptcha);
|
cfg.service(delete_mcaptcha);
|
||||||
cfg.service(get_stats);
|
cfg.service(get_stats);
|
||||||
cfg.service(from_user_provided_traffic_pattern);
|
cfg.service(create_easy);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
@@ -221,14 +223,14 @@ async fn get_stats(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
pub struct UserProvidedTrafficPattern {
|
pub struct TrafficPattern {
|
||||||
pub avg_traffic: u32,
|
pub avg_traffic: u32,
|
||||||
pub peak_sustainable_traffic: u32,
|
pub peak_sustainable_traffic: u32,
|
||||||
pub broke_my_site_traffic: Option<u32>,
|
pub broke_my_site_traffic: Option<u32>,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserProvidedTrafficPattern {
|
impl TrafficPattern {
|
||||||
pub fn calculate(
|
pub fn calculate(
|
||||||
&self,
|
&self,
|
||||||
strategy: &DefaultDifficultyStrategy,
|
strategy: &DefaultDifficultyStrategy,
|
||||||
@@ -268,11 +270,11 @@ impl UserProvidedTrafficPattern {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[my_codegen::post(
|
#[my_codegen::post(
|
||||||
path = "crate::V1_API_ROUTES.mcaptcha.user_provided_traffic_pattern",
|
path = "crate::V1_API_ROUTES.mcaptcha.create_easy",
|
||||||
wrap = "crate::CheckLogin"
|
wrap = "crate::CheckLogin"
|
||||||
)]
|
)]
|
||||||
async fn from_user_provided_traffic_pattern(
|
async fn create_easy(
|
||||||
payload: web::Json<UserProvidedTrafficPattern>,
|
payload: web::Json<TrafficPattern>,
|
||||||
data: AppData,
|
data: AppData,
|
||||||
id: Identity,
|
id: Identity,
|
||||||
) -> ServiceResult<impl Responder> {
|
) -> ServiceResult<impl Responder> {
|
||||||
@@ -380,11 +382,15 @@ mod tests {
|
|||||||
assert_eq!(get_statis_resp.status(), StatusCode::OK);
|
assert_eq!(get_statis_resp.status(), StatusCode::OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[cfg(test)]
|
||||||
async fn user_provided_traffic_pattern_calculate_works() {
|
mod isoloated_test {
|
||||||
|
use super::{LevelBuilder, TrafficPattern};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn easy_configuration_works() {
|
||||||
const NAME: &str = "defaultuserconfgworks";
|
const NAME: &str = "defaultuserconfgworks";
|
||||||
|
|
||||||
let mut payload = UserProvidedTrafficPattern {
|
let mut payload = TrafficPattern {
|
||||||
avg_traffic: 100_000,
|
avg_traffic: 100_000,
|
||||||
peak_sustainable_traffic: 1_000_000,
|
peak_sustainable_traffic: 1_000_000,
|
||||||
broke_my_site_traffic: Some(10_000_000),
|
broke_my_site_traffic: Some(10_000_000),
|
||||||
@@ -449,9 +455,10 @@ mod tests {
|
|||||||
vec![l1, very_large_l2, lmax]
|
vec![l1, very_large_l2, lmax]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn from_user_provided_traffic_pattern_works() {
|
async fn easy_works() {
|
||||||
const NAME: &str = "defaultuserconfgworks";
|
const NAME: &str = "defaultuserconfgworks";
|
||||||
const PASSWORD: &str = "longpassworddomain";
|
const PASSWORD: &str = "longpassworddomain";
|
||||||
const EMAIL: &str = "defaultuserconfgworks@a.com";
|
const EMAIL: &str = "defaultuserconfgworks@a.com";
|
||||||
@@ -466,7 +473,7 @@ mod tests {
|
|||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let app = get_app!(data).await;
|
let app = get_app!(data).await;
|
||||||
|
|
||||||
let payload = UserProvidedTrafficPattern {
|
let payload = TrafficPattern {
|
||||||
avg_traffic: 100_000,
|
avg_traffic: 100_000,
|
||||||
peak_sustainable_traffic: 1_000_000,
|
peak_sustainable_traffic: 1_000_000,
|
||||||
broke_my_site_traffic: Some(10_000_000),
|
broke_my_site_traffic: Some(10_000_000),
|
||||||
@@ -479,7 +486,7 @@ mod tests {
|
|||||||
|
|
||||||
let add_token_resp = test::call_service(
|
let add_token_resp = test::call_service(
|
||||||
&app,
|
&app,
|
||||||
post_request!(&payload, ROUTES.mcaptcha.user_provided_traffic_pattern)
|
post_request!(&payload, ROUTES.mcaptcha.create_easy)
|
||||||
.cookie(cookies.clone())
|
.cookie(cookies.clone())
|
||||||
.to_request(),
|
.to_request(),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user