From 4cd4605266fd463b7a82fb862bad06e6d45941b5 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Fri, 27 May 2022 15:25:10 +0530 Subject: [PATCH] chore: use local app ctx --- src/api/mod.rs | 30 +++++++++--------- src/api/v1/account/delete.rs | 30 +++++++++--------- src/api/v1/account/password.rs | 2 +- src/api/v1/account/secret.rs | 30 +++++++++--------- src/api/v1/account/test.rs | 6 ++-- src/api/v1/auth.rs | 2 +- src/api/v1/mcaptcha/easy.rs | 25 +++++++-------- src/api/v1/mcaptcha/stats.rs | 30 +++++++++--------- src/api/v1/mcaptcha/test.rs | 2 +- src/api/v1/mcaptcha/update.rs | 2 +- src/api/v1/meta.rs | 34 ++++++++++----------- src/api/v1/mod.rs | 30 +++++++++--------- src/api/v1/notifications/add.rs | 32 +++++++++---------- src/api/v1/notifications/get.rs | 32 +++++++++---------- src/api/v1/notifications/mark_read.rs | 32 +++++++++---------- src/api/v1/notifications/mod.rs | 30 +++++++++--------- src/api/v1/pow/get_config.rs | 32 +++++++++---------- src/api/v1/pow/mod.rs | 30 +++++++++--------- src/api/v1/pow/verify_pow.rs | 32 +++++++++---------- src/api/v1/pow/verify_token.rs | 32 +++++++++---------- src/api/v1/routes.rs | 30 +++++++++--------- src/api/v1/tests/auth.rs | 4 +-- src/api/v1/tests/mod.rs | 30 +++++++++--------- src/api/v1/tests/protected.rs | 32 +++++++++---------- src/data.rs | 44 ++++++++++++++++----------- src/demo.rs | 2 +- src/email/mod.rs | 30 +++++++++--------- src/email/verification.rs | 39 ++++++++++++------------ src/errors.rs | 30 +++++++++--------- src/main.rs | 20 +++++++----- src/pages/auth/login.rs | 30 +++++++++--------- src/pages/auth/mod.rs | 30 +++++++++--------- src/pages/auth/register.rs | 30 +++++++++--------- src/pages/errors.rs | 28 +++++++++-------- src/pages/mod.rs | 5 +-- src/pages/panel/sitekey/add.rs | 30 +++++++++--------- src/pages/panel/sitekey/delete.rs | 30 +++++++++--------- src/pages/panel/sitekey/edit.rs | 2 +- src/pages/panel/sitekey/list.rs | 2 +- src/pages/panel/sitekey/login.rs | 30 +++++++++--------- src/pages/panel/sitekey/mod.rs | 30 +++++++++--------- src/pages/panel/sitekey/view.rs | 2 +- src/pages/routes.rs | 30 +++++++++--------- src/tests/mod.rs | 30 ++++++++++++++++-- 44 files changed, 542 insertions(+), 503 deletions(-) diff --git a/src/api/mod.rs b/src/api/mod.rs index 56277d30..dcedb932 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,18 +1,18 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ pub mod v1; diff --git a/src/api/v1/account/delete.rs b/src/api/v1/account/delete.rs index 629383a3..abe825dd 100644 --- a/src/api/v1/account/delete.rs +++ b/src/api/v1/account/delete.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_identity::Identity; use actix_web::{web, HttpResponse, Responder}; diff --git a/src/api/v1/account/password.rs b/src/api/v1/account/password.rs index 69b60810..99d3346b 100644 --- a/src/api/v1/account/password.rs +++ b/src/api/v1/account/password.rs @@ -111,7 +111,7 @@ pub mod tests { const PASSWORD: &str = "longpassword2"; const EMAIL: &str = "updatepassuser@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/api/v1/account/secret.rs b/src/api/v1/account/secret.rs index 3a432f82..64f5ee22 100644 --- a/src/api/v1/account/secret.rs +++ b/src/api/v1/account/secret.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_identity::Identity; use actix_web::{HttpResponse, Responder}; use db_core::prelude::*; diff --git a/src/api/v1/account/test.rs b/src/api/v1/account/test.rs index 24185c73..8b00c1ec 100644 --- a/src/api/v1/account/test.rs +++ b/src/api/v1/account/test.rs @@ -33,7 +33,7 @@ pub async fn uname_email_exists_works() { const NAME: &str = "testuserexists"; const PASSWORD: &str = "longpassword2"; const EMAIL: &str = "testuserexists@a.com2"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; @@ -122,7 +122,7 @@ pub async fn email_udpate_password_validation_del_userworks() { const NAME2: &str = "eupdauser"; const EMAIL2: &str = "eupdauser@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; delete_user(data, NAME2).await; @@ -206,7 +206,7 @@ pub async fn username_update_works() { const NAME2: &str = "terstusrtds"; const NAME_CHANGE: &str = "terstusrtdsxx"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; futures::join!( diff --git a/src/api/v1/auth.rs b/src/api/v1/auth.rs index 9234d56d..d89a5c5f 100644 --- a/src/api/v1/auth.rs +++ b/src/api/v1/auth.rs @@ -115,7 +115,7 @@ pub mod runners { payload: &Register, data: &AppData, ) -> ServiceResult<()> { - if !crate::SETTINGS.allow_registration { + if !data.settings.allow_registration { return Err(ServiceError::ClosedForRegistration); } diff --git a/src/api/v1/mcaptcha/easy.rs b/src/api/v1/mcaptcha/easy.rs index 0cd9081d..e90ed052 100644 --- a/src/api/v1/mcaptcha/easy.rs +++ b/src/api/v1/mcaptcha/easy.rs @@ -121,13 +121,11 @@ async fn create( let username = id.identity().unwrap(); let payload = payload.into_inner(); let pattern = (&payload).into(); - let levels = calculate( - &pattern, - &crate::SETTINGS.captcha.default_difficulty_strategy, - )?; + let levels = + calculate(&pattern, &data.settings.captcha.default_difficulty_strategy)?; let msg = CreateCaptcha { levels, - duration: crate::SETTINGS.captcha.default_difficulty_strategy.duration, + duration: data.settings.captcha.default_difficulty_strategy.duration, description: payload.description, }; @@ -156,14 +154,12 @@ async fn update( let username = id.identity().unwrap(); let payload = payload.into_inner(); let pattern = (&payload.pattern).into(); - let levels = calculate( - &pattern, - &crate::SETTINGS.captcha.default_difficulty_strategy, - )?; + let levels = + calculate(&pattern, &data.settings.captcha.default_difficulty_strategy)?; let msg = UpdateCaptcha { levels, - duration: crate::SETTINGS.captcha.default_difficulty_strategy.duration, + duration: data.settings.captcha.default_difficulty_strategy.duration, description: payload.pattern.description, key: payload.key, }; @@ -201,6 +197,7 @@ pub mod tests { #[test] fn easy_configuration_works() { const NAME: &str = "defaultuserconfgworks"; + let settings = crate::tests::get_settings(); let mut payload = TrafficPattern { avg_traffic: 100_000, @@ -208,7 +205,7 @@ pub mod tests { broke_my_site_traffic: Some(10_000_000), }; - let strategy = &crate::SETTINGS.captcha.default_difficulty_strategy; + let strategy = &settings.captcha.default_difficulty_strategy; let l1 = LevelBuilder::default() .difficulty_factor(strategy.avg_traffic_difficulty) .unwrap() @@ -273,7 +270,7 @@ pub mod tests { const NAME: &str = "defaultuserconfgworks"; const PASSWORD: &str = "longpassworddomain"; const EMAIL: &str = "defaultuserconfgworks@a.com"; - let data = crate::data::Data::new().await; + let data = crate::tests::get_data().await; let data = &data; delete_user(data, NAME).await; @@ -292,7 +289,7 @@ pub mod tests { let default_levels = calculate( &(&payload).into(), - &crate::SETTINGS.captcha.default_difficulty_strategy, + &data.settings.captcha.default_difficulty_strategy, ) .unwrap(); @@ -331,7 +328,7 @@ pub mod tests { let updated_default_values = calculate( &(&update_pattern).into(), - &crate::SETTINGS.captcha.default_difficulty_strategy, + &data.settings.captcha.default_difficulty_strategy, ) .unwrap(); diff --git a/src/api/v1/mcaptcha/stats.rs b/src/api/v1/mcaptcha/stats.rs index e84fbe7f..b3a911d8 100644 --- a/src/api/v1/mcaptcha/stats.rs +++ b/src/api/v1/mcaptcha/stats.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_identity::Identity; use actix_web::{web, HttpResponse, Responder}; use serde::{Deserialize, Serialize}; diff --git a/src/api/v1/mcaptcha/test.rs b/src/api/v1/mcaptcha/test.rs index 7e0e3733..a5fdc2e4 100644 --- a/src/api/v1/mcaptcha/test.rs +++ b/src/api/v1/mcaptcha/test.rs @@ -41,7 +41,7 @@ pub async fn level_routes_work() { const NAME: &str = "testuserlevelroutes"; const PASSWORD: &str = "longpassworddomain"; const EMAIL: &str = "testuserlevelrouts@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/api/v1/mcaptcha/update.rs b/src/api/v1/mcaptcha/update.rs index 543fea5f..d0d249b9 100644 --- a/src/api/v1/mcaptcha/update.rs +++ b/src/api/v1/mcaptcha/update.rs @@ -159,7 +159,7 @@ mod tests { const NAME: &str = "updateusermcaptcha"; const PASSWORD: &str = "longpassworddomain"; const EMAIL: &str = "testupdateusermcaptcha@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/api/v1/meta.rs b/src/api/v1/meta.rs index f2fdaa8d..79f5cfae 100644 --- a/src/api/v1/meta.rs +++ b/src/api/v1/meta.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_web::{web, HttpResponse, Responder}; use derive_builder::Builder; @@ -79,7 +79,7 @@ async fn health(data: AppData) -> impl Responder { if let SystemGroup::Redis(_) = data.captcha { if let Ok(r) = Redis::new(RedisConfig::Single( - crate::SETTINGS.redis.as_ref().unwrap().url.clone(), + data.settings.redis.as_ref().unwrap().url.clone(), )) .await { @@ -123,7 +123,7 @@ pub mod tests { #[actix_rt::test] pub async fn health_works() { println!("{}", V1_API_ROUTES.meta.health); - let data = crate::data::Data::new().await; + let data = crate::tests::get_data().await; let data = &data; let app = get_app!(data).await; diff --git a/src/api/v1/mod.rs b/src/api/v1/mod.rs index db6f9ccf..c570cffe 100644 --- a/src/api/v1/mod.rs +++ b/src/api/v1/mod.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_auth_middleware::Authentication; use actix_web::web::ServiceConfig; diff --git a/src/api/v1/notifications/add.rs b/src/api/v1/notifications/add.rs index acfd57f5..8c7afcfd 100644 --- a/src/api/v1/notifications/add.rs +++ b/src/api/v1/notifications/add.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_identity::Identity; use actix_web::{web, HttpResponse, Responder}; @@ -73,7 +73,7 @@ pub mod tests { const EMAIL1: &str = "testnotification1@a.com"; const EMAIL2: &str = "testnotification2@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME1).await; diff --git a/src/api/v1/notifications/get.rs b/src/api/v1/notifications/get.rs index 146b758f..c4d89a97 100644 --- a/src/api/v1/notifications/get.rs +++ b/src/api/v1/notifications/get.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_identity::Identity; use actix_web::{HttpResponse, Responder}; @@ -95,7 +95,7 @@ pub mod tests { const HEADING: &str = "testing notifications get"; const MESSAGE: &str = "testing notifications get message"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME1).await; diff --git a/src/api/v1/notifications/mark_read.rs b/src/api/v1/notifications/mark_read.rs index b2b6809a..770f7cfb 100644 --- a/src/api/v1/notifications/mark_read.rs +++ b/src/api/v1/notifications/mark_read.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_identity::Identity; use actix_web::{web, HttpResponse, Responder}; @@ -68,7 +68,7 @@ pub mod tests { const EMAIL2: &str = "testnotification222@a.com"; const HEADING: &str = "testing notifications get"; const MESSAGE: &str = "testing notifications get message"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME1).await; diff --git a/src/api/v1/notifications/mod.rs b/src/api/v1/notifications/mod.rs index 0038c150..1f7c4894 100644 --- a/src/api/v1/notifications/mod.rs +++ b/src/api/v1/notifications/mod.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ pub mod add; pub mod get; diff --git a/src/api/v1/pow/get_config.rs b/src/api/v1/pow/get_config.rs index 9c4a1060..9110e3a7 100644 --- a/src/api/v1/pow/get_config.rs +++ b/src/api/v1/pow/get_config.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ //use actix::prelude::*; use actix_web::{web, HttpResponse, Responder}; @@ -155,7 +155,7 @@ pub mod tests { const PASSWORD: &str = "testingpas"; const EMAIL: &str = "randomuser@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/api/v1/pow/mod.rs b/src/api/v1/pow/mod.rs index f2b7bcf4..932c4d55 100644 --- a/src/api/v1/pow/mod.rs +++ b/src/api/v1/pow/mod.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_web::web; diff --git a/src/api/v1/pow/verify_pow.rs b/src/api/v1/pow/verify_pow.rs index cb8d7fb3..3202ed4d 100644 --- a/src/api/v1/pow/verify_pow.rs +++ b/src/api/v1/pow/verify_pow.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ //! PoW Verification module use actix_web::{web, HttpResponse, Responder}; @@ -64,7 +64,7 @@ pub mod tests { const NAME: &str = "powverifyusr"; const PASSWORD: &str = "testingpas"; const EMAIL: &str = "verifyuser@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/api/v1/pow/verify_token.rs b/src/api/v1/pow/verify_token.rs index f6fe9b96..bad1c6fc 100644 --- a/src/api/v1/pow/verify_token.rs +++ b/src/api/v1/pow/verify_token.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ //! PoW success token module use actix_web::{web, HttpResponse, Responder}; @@ -72,7 +72,7 @@ pub mod tests { const VERIFY_TOKEN_URL: &str = "/api/v1/pow/siteverify"; // const UPDATE_URL: &str = "/api/v1/mcaptcha/domain/token/duration/update"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/api/v1/routes.rs b/src/api/v1/routes.rs index 0159b91d..3ee5554d 100644 --- a/src/api/v1/routes.rs +++ b/src/api/v1/routes.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_auth_middleware::GetLoginRoute; use super::account::routes::Account; diff --git a/src/api/v1/tests/auth.rs b/src/api/v1/tests/auth.rs index 8b111e23..ed256332 100644 --- a/src/api/v1/tests/auth.rs +++ b/src/api/v1/tests/auth.rs @@ -31,7 +31,7 @@ pub async fn auth_works() { const PASSWORD: &str = "longpassword"; const EMAIL: &str = "testuser1@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; let app = get_app!(data).await; @@ -147,7 +147,7 @@ pub async fn serverside_password_validation_works() { const NAME: &str = "testuser542"; const PASSWORD: &str = "longpassword2"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/api/v1/tests/mod.rs b/src/api/v1/tests/mod.rs index 790e9f21..298a9352 100644 --- a/src/api/v1/tests/mod.rs +++ b/src/api/v1/tests/mod.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ mod auth; mod protected; diff --git a/src/api/v1/tests/protected.rs b/src/api/v1/tests/protected.rs index 3e8fb5f8..5d11f12f 100644 --- a/src/api/v1/tests/protected.rs +++ b/src/api/v1/tests/protected.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_web::http::StatusCode; use actix_web::test; @@ -27,7 +27,7 @@ async fn protected_routes_work() { const NAME: &str = "testuser619"; const PASSWORD: &str = "longpassword2"; const EMAIL: &str = "testuser119@a.com2"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; let _post_protected_urls = [ diff --git a/src/data.rs b/src/data.rs index 260c775b..7eb58e4b 100644 --- a/src/data.rs +++ b/src/data.rs @@ -46,7 +46,8 @@ use sqlx::PgPool; use db_core::MCDatabase; use crate::errors::ServiceResult; -use crate::SETTINGS; +//use crate::SETTINGS; +use crate::settings::Settings; macro_rules! enum_system_actor { ($name:ident, $type:ident) => { @@ -105,9 +106,13 @@ impl SystemGroup { // utility function to remove captcha enum_system_actor!(remove, RemoveCaptcha); - fn new_system(m: Addr, c: Addr) -> System { + fn new_system( + s: &Settings, + m: Addr, + c: Addr, + ) -> System { let pow = PoWConfigBuilder::default() - .salt(SETTINGS.captcha.salt.clone()) + .salt(s.captcha.salt.clone()) .build() .unwrap(); @@ -116,8 +121,8 @@ impl SystemGroup { // read settings, if Redis is configured then produce a Redis mCaptcha cache // based SystemGroup - async fn new() -> Self { - match &SETTINGS.redis { + async fn new(s: &Settings) -> Self { + match &s.redis { Some(val) => { let master = RedisMaster::new(RedisConfig::Single(val.url.clone())) .await @@ -127,14 +132,14 @@ impl SystemGroup { .await .unwrap() .start(); - let captcha = Self::new_system(master, cache); + let captcha = Self::new_system(s, master, cache); SystemGroup::Redis(captcha) } None => { - let master = EmbeddedMaster::new(SETTINGS.captcha.gc).start(); + let master = EmbeddedMaster::new(s.captcha.gc).start(); let cache = HashCache::default().start(); - let captcha = Self::new_system(master, cache); + let captcha = Self::new_system(s, master, cache); SystemGroup::Embedded(captcha) } @@ -154,6 +159,9 @@ pub struct Data { pub captcha: SystemGroup, /// email client pub mailer: Option, + + /// app settings + pub settings: Settings, } impl Data { @@ -168,7 +176,7 @@ impl Data { } #[cfg(not(tarpaulin_include))] /// create new instance of app data - pub async fn new() -> Arc { + pub async fn new(s: &Settings) -> Arc { let creds = Self::get_creds(); let c = creds.clone(); @@ -180,17 +188,16 @@ impl Data { }); let db = PgPoolOptions::new() - .max_connections(SETTINGS.database.pool) - .connect(&SETTINGS.database.url) + .max_connections(s.database.pool) + .connect(&s.database.url) .await .expect("Unable to form database pool"); - let settings = &SETTINGS; - let pool = settings.database.pool; + let pool = s.database.pool; let pool_options = PgPoolOptions::new().max_connections(pool); let connection_options = ConnectionOptions::Fresh(Fresh { pool_options, - url: settings.database.url.clone(), + url: s.database.url.clone(), }); let dblib = connection_options.connect().await.unwrap(); dblib.migrate().await.unwrap(); @@ -199,8 +206,9 @@ impl Data { creds, db, dblib: Box::new(dblib), - captcha: SystemGroup::new().await, - mailer: Self::get_mailer(), + captcha: SystemGroup::new(s).await, + mailer: Self::get_mailer(s), + settings: s.clone(), }; #[cfg(not(debug_assertions))] @@ -209,8 +217,8 @@ impl Data { Arc::new(data) } - fn get_mailer() -> Option { - if let Some(smtp) = SETTINGS.smtp.as_ref() { + fn get_mailer(s: &Settings) -> Option { + if let Some(smtp) = s.smtp.as_ref() { let creds = Credentials::new(smtp.username.to_string(), smtp.password.to_string()); // "smtp_username".to_string(), "smtp_password".to_string()); diff --git a/src/demo.rs b/src/demo.rs index e6b94da0..592cee1a 100644 --- a/src/demo.rs +++ b/src/demo.rs @@ -115,7 +115,7 @@ mod tests { #[actix_rt::test] async fn demo_account_works() { - let data_inner = crate::data::Data::new().await; + let data_inner = get_data().await; let data_inner = &data_inner; let data = AppData::new(data_inner.clone()); crate::tests::delete_user(data_inner, DEMO_USER).await; diff --git a/src/email/mod.rs b/src/email/mod.rs index 9415980d..c7d48367 100644 --- a/src/email/mod.rs +++ b/src/email/mod.rs @@ -1,18 +1,18 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ pub mod verification; diff --git a/src/email/verification.rs b/src/email/verification.rs index df225a2f..9f7fdb71 100644 --- a/src/email/verification.rs +++ b/src/email/verification.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ //! Email operations: verification, notification, etc use lettre::{ message::{header, MultiPart, SinglePart}, @@ -44,7 +44,7 @@ async fn verification( to: &str, verification_link: &str, ) -> ServiceResult<()> { - if let Some(smtp) = SETTINGS.smtp.as_ref() { + if let Some(smtp) = data.settings.smtp.as_ref() { let from = format!("mCaptcha Admin <{}>", smtp.from); let reply_to = format!("mCaptcha Admin <{}>", smtp.reply); const SUBJECT: &str = "[mCaptcha] Please verify your email"; @@ -64,7 +64,7 @@ Admin instance: {} project website: {}", verification_link, - SETTINGS.server.domain, + &data.settings.server.domain, crate::PKG_HOMEPAGE ); @@ -105,7 +105,8 @@ mod tests { async fn email_verification_works() { const TO_ADDR: &str = "Hello "; const VERIFICATION_LINK: &str = "https://localhost"; - let data = Data::new().await; + let data = crate::tests::get_data().await; + let settings = &data.settings; verification(&data, TO_ADDR, VERIFICATION_LINK) .await .unwrap(); @@ -118,7 +119,7 @@ mod tests { .unwrap(); let data: serde_json::Value = resp.json().await.unwrap(); let data = &data[0]; - let smtp = SETTINGS.smtp.as_ref().unwrap(); + let smtp = settings.smtp.as_ref().unwrap(); let from_addr = &data["headers"]["from"]; diff --git a/src/errors.rs b/src/errors.rs index 3b657f45..990e534a 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use std::convert::From; diff --git a/src/main.rs b/src/main.rs index 390a9069..b1c2cff4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,12 +110,13 @@ async fn main() -> std::io::Result<()> { PKG_NAME, PKG_DESCRIPTION, PKG_HOMEPAGE, VERSION, GIT_COMMIT_HASH ); - let data = Data::new().await; + let settings = Settings::new().unwrap(); + let data = Data::new(&settings).await; let data = actix_web::web::Data::new(data); let mut demo_user: Option = None; - if SETTINGS.allow_demo && SETTINGS.allow_registration { + if settings.allow_demo && settings.allow_registration { demo_user = Some( DemoUser::spawn(data.clone(), Duration::from_secs(60 * 30)) .await @@ -123,7 +124,8 @@ async fn main() -> std::io::Result<()> { ); } - println!("Starting server on: http://{}", SETTINGS.server.get_ip()); + let ip = settings.server.get_ip(); + println!("Starting server on: http://{ip}"); HttpServer::new(move || { App::new() @@ -132,7 +134,7 @@ async fn main() -> std::io::Result<()> { actix_middleware::DefaultHeaders::new() .add(("Permissions-Policy", "interest-cohort=()")), ) - .wrap(get_identity_service()) + .wrap(get_identity_service(&settings)) .wrap(actix_middleware::Compress::default()) .app_data(data.clone()) .wrap(actix_middleware::NormalizePath::new( @@ -141,7 +143,7 @@ async fn main() -> std::io::Result<()> { .configure(routes::services) .app_data(get_json_err()) }) - .bind(SETTINGS.server.get_ip()) + .bind(&ip) .unwrap() .run() .await?; @@ -161,14 +163,16 @@ pub fn get_json_err() -> JsonConfig { } #[cfg(not(tarpaulin_include))] -pub fn get_identity_service() -> IdentityService { - let cookie_secret = &SETTINGS.server.cookie_secret; +pub fn get_identity_service( + settings: &Settings, +) -> IdentityService { + let cookie_secret = &settings.server.cookie_secret; IdentityService::new( CookieIdentityPolicy::new(cookie_secret.as_bytes()) .name("Authorization") //TODO change cookie age .max_age_secs(216000) - .domain(&SETTINGS.server.domain) + .domain(&settings.server.domain) .secure(false), ) } diff --git a/src/pages/auth/login.rs b/src/pages/auth/login.rs index bb2d6b4b..72f77d64 100644 --- a/src/pages/auth/login.rs +++ b/src/pages/auth/login.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_web::{HttpResponse, Responder}; use lazy_static::lazy_static; diff --git a/src/pages/auth/mod.rs b/src/pages/auth/mod.rs index 96f68f0b..801df59f 100644 --- a/src/pages/auth/mod.rs +++ b/src/pages/auth/mod.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ pub mod login; pub mod register; diff --git a/src/pages/auth/register.rs b/src/pages/auth/register.rs index 211de8fd..1077fd8c 100644 --- a/src/pages/auth/register.rs +++ b/src/pages/auth/register.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_web::{HttpResponse, Responder}; use lazy_static::lazy_static; diff --git a/src/pages/errors.rs b/src/pages/errors.rs index 05457036..b241f16d 100644 --- a/src/pages/errors.rs +++ b/src/pages/errors.rs @@ -1,17 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . */ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_web::{web, HttpResponse, Responder}; use lazy_static::lazy_static; diff --git a/src/pages/mod.rs b/src/pages/mod.rs index d15264ef..098a3567 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -11,7 +11,8 @@ * 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 . + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . */ use actix_auth_middleware::Authentication; use actix_web::web::ServiceConfig; @@ -51,7 +52,7 @@ mod tests { const PASSWORD: &str = "longpassword"; const EMAIL: &str = "templateuser@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/pages/panel/sitekey/add.rs b/src/pages/panel/sitekey/add.rs index 432a8b21..2022cdf2 100644 --- a/src/pages/panel/sitekey/add.rs +++ b/src/pages/panel/sitekey/add.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_web::{HttpResponse, Responder}; use lazy_static::lazy_static; diff --git a/src/pages/panel/sitekey/delete.rs b/src/pages/panel/sitekey/delete.rs index 684c585f..b46a8886 100644 --- a/src/pages/panel/sitekey/delete.rs +++ b/src/pages/panel/sitekey/delete.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_web::{web, HttpResponse, Responder}; use my_codegen::get; diff --git a/src/pages/panel/sitekey/edit.rs b/src/pages/panel/sitekey/edit.rs index d486926e..fec5ae02 100644 --- a/src/pages/panel/sitekey/edit.rs +++ b/src/pages/panel/sitekey/edit.rs @@ -192,7 +192,7 @@ mod test { const NAME: &str = "editsitekeyuser"; const PASSWORD: &str = "longpassworddomain"; const EMAIL: &str = "editsitekeyuser@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/pages/panel/sitekey/list.rs b/src/pages/panel/sitekey/list.rs index 22c62387..d99b5879 100644 --- a/src/pages/panel/sitekey/list.rs +++ b/src/pages/panel/sitekey/list.rs @@ -81,7 +81,7 @@ mod test { const PASSWORD: &str = "longpassworddomain"; const EMAIL: &str = "listsitekeyuser@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/pages/panel/sitekey/login.rs b/src/pages/panel/sitekey/login.rs index fe1e399e..522a43ff 100644 --- a/src/pages/panel/sitekey/login.rs +++ b/src/pages/panel/sitekey/login.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_web::{HttpResponse, Responder}; use lazy_static::lazy_static; diff --git a/src/pages/panel/sitekey/mod.rs b/src/pages/panel/sitekey/mod.rs index 5905e653..4be3fee8 100644 --- a/src/pages/panel/sitekey/mod.rs +++ b/src/pages/panel/sitekey/mod.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ mod add; mod delete; diff --git a/src/pages/panel/sitekey/view.rs b/src/pages/panel/sitekey/view.rs index 04e3ed64..9b67158b 100644 --- a/src/pages/panel/sitekey/view.rs +++ b/src/pages/panel/sitekey/view.rs @@ -113,7 +113,7 @@ mod test { const PASSWORD: &str = "longpassworddomain"; const EMAIL: &str = "viewsitekeyuser@a.com"; - let data = crate::data::Data::new().await; + let data = get_data().await; let data = &data; delete_user(data, NAME).await; diff --git a/src/pages/routes.rs b/src/pages/routes.rs index 79cf8270..7b3322ac 100644 --- a/src/pages/routes.rs +++ b/src/pages/routes.rs @@ -1,19 +1,19 @@ /* -* Copyright (C) 2022 Aravinth Manivannan -* -* 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 . -*/ + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ use actix_auth_middleware::GetLoginRoute; use super::auth::routes::Auth; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index af92c578..696fe716 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1,3 +1,20 @@ +/* + * Copyright (C) 2022 Aravinth Manivannan + * + * 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 . + */ + use actix_web::test; use actix_web::{ body::{BoxBody, EitherBody}, @@ -17,6 +34,15 @@ use crate::api::v1::ROUTES; use crate::errors::*; use crate::ArcData; +pub fn get_settings() -> Settings { + Settings::new().unwrap() +} +pub async fn get_data() -> ArcData { + let settings = get_settings(); + let data = Data::new(&settings).await; + data +} + #[macro_export] macro_rules! get_cookie { ($resp:expr) => { @@ -50,7 +76,7 @@ macro_rules! get_app { () => { test::init_service( App::new() - .wrap(get_identity_service()) + // .wrap(get_identity_service(&$data.settings)) .wrap(actix_middleware::NormalizePath::new( actix_middleware::TrailingSlash::Trim, )) @@ -60,7 +86,7 @@ macro_rules! get_app { ($data:expr) => { test::init_service( App::new() - .wrap(get_identity_service()) + .wrap(get_identity_service(&$data.settings)) .wrap(actix_middleware::NormalizePath::new( actix_middleware::TrailingSlash::Trim, ))