From b7ec1bca221af2c62072fcd8dd5b63e7b6fcac07 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Sun, 11 Jul 2021 21:46:50 +0530 Subject: [PATCH] duplicate email check and address clippy warnings --- browser/src/lib.rs | 45 +++++++++++++-------------- src/api/v1/account/test.rs | 20 ++++++------ src/api/v1/auth.rs | 2 ++ src/api/v1/mcaptcha/captcha.rs | 12 +++---- src/api/v1/mcaptcha/duration.rs | 8 ++--- src/api/v1/mcaptcha/levels.rs | 12 +++---- src/api/v1/meta.rs | 8 ++--- src/api/v1/notifications/add.rs | 4 +-- src/api/v1/notifications/get.rs | 6 ++-- src/api/v1/notifications/mark_read.rs | 10 +++--- src/api/v1/pow/get_config.rs | 4 +-- src/api/v1/pow/verify_pow.rs | 10 +++--- src/api/v1/pow/verify_token.rs | 12 +++---- src/api/v1/tests/auth.rs | 10 +++--- src/api/v1/tests/protected.rs | 6 ++-- src/docs.rs | 8 ++--- src/email/verification.rs | 1 - src/pages/errors.rs | 6 ++-- src/pages/mod.rs | 10 +++--- src/pages/panel/sitekey/list.rs | 4 +-- src/pages/panel/sitekey/view.rs | 4 +-- src/static_assets/static_files.rs | 16 +++++----- src/tests/mod.rs | 18 +++++------ src/widget/mod.rs | 2 +- 24 files changed, 118 insertions(+), 120 deletions(-) diff --git a/browser/src/lib.rs b/browser/src/lib.rs index ed974858..9d10907a 100644 --- a/browser/src/lib.rs +++ b/browser/src/lib.rs @@ -28,35 +28,33 @@ //! //! generate proof-of-work //! ```rust -//! fn main() { -//! use mcaptcha_browser::*; -//! use pow_sha256::*; +//! use mcaptcha_browser::*; +//! use pow_sha256::*; //! //! -//! // salt using which PoW should be computed -//! const SALT: &str = "yrandomsaltisnotlongenoug"; -//! // one-time phrase over which PoW should be computed -//! const PHRASE: &str = "ironmansucks"; -//! // and the difficulty factor -//! const DIFFICULTY: u32 = 1000; +//! // salt using which PoW should be computed +//! const SALT: &str = "yrandomsaltisnotlongenoug"; +//! // one-time phrase over which PoW should be computed +//! const PHRASE: &str = "ironmansucks"; +//! // and the difficulty factor +//! const DIFFICULTY: u32 = 1000; //! -//! // currently gen_pow() returns a JSON formated string to better communicate -//! // with JavaScript. See [PoW][pow_sha256::PoW] for schema -//! let serialised_work = gen_pow(SALT.into(), PHRASE.into(), DIFFICULTY); +//! // currently gen_pow() returns a JSON formated string to better communicate +//! // with JavaScript. See [PoW][pow_sha256::PoW] for schema +//! let serialised_work = gen_pow(SALT.into(), PHRASE.into(), DIFFICULTY); //! //! -//! let work: Work = serde_json::from_str(&serialised_work).unwrap(); +//! let work: Work = serde_json::from_str(&serialised_work).unwrap(); //! -//! let work = PoWBuilder::default() -//! .result(work.result) -//! .nonce(work.nonce) -//! .build() -//! .unwrap(); +//! let work = PoWBuilder::default() +//! .result(work.result) +//! .nonce(work.nonce) +//! .build() +//! .unwrap(); //! -//! let config = ConfigBuilder::default().salt(SALT.into()).build().unwrap(); -//! assert!(config.is_valid_proof(&work, &PHRASE.to_string())); -//! assert!(config.is_sufficient_difficulty(&work, DIFFICULTY)); -//! } +//! let config = ConfigBuilder::default().salt(SALT.into()).build().unwrap(); +//! assert!(config.is_valid_proof(&work, &PHRASE.to_string())); +//! assert!(config.is_sufficient_difficulty(&work, DIFFICULTY)); //! ``` use serde::{Deserialize, Serialize}; @@ -124,8 +122,7 @@ pub fn gen_pow(salt: String, phrase: String, difficulty_factor: u32) -> String { let work = config.prove_work(&phrase, difficulty_factor).unwrap(); let work: Work = work.into(); - let payload = serde_json::to_string(&work).unwrap(); - payload + serde_json::to_string(&work).unwrap() } #[cfg(test)] diff --git a/src/api/v1/account/test.rs b/src/api/v1/account/test.rs index adffa590..0e89b764 100644 --- a/src/api/v1/account/test.rs +++ b/src/api/v1/account/test.rs @@ -40,11 +40,11 @@ async fn uname_email_exists_works() { let (data, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; // chech if get user secret works let resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .cookie(cookies.clone()) .uri(ROUTES.account.get_secret) @@ -55,7 +55,7 @@ async fn uname_email_exists_works() { // chech if get user secret works let resp = test::call_service( - &mut app, + &app, test::TestRequest::post() .cookie(cookies.clone()) .uri(ROUTES.account.update_secret) @@ -67,7 +67,7 @@ async fn uname_email_exists_works() { let mut payload = AccountCheckPayload { val: NAME.into() }; let user_exists_resp = test::call_service( - &mut app, + &app, post_request!(&payload, ROUTES.account.username_exists) .cookie(cookies.clone()) .to_request(), @@ -80,7 +80,7 @@ async fn uname_email_exists_works() { payload.val = PASSWORD.into(); let user_doesnt_exist = test::call_service( - &mut app, + &app, post_request!(&payload, ROUTES.account.username_exists) .cookie(cookies.clone()) .to_request(), @@ -91,7 +91,7 @@ async fn uname_email_exists_works() { assert!(!resp.exists); let email_doesnt_exist = test::call_service( - &mut app, + &app, post_request!(&payload, ROUTES.account.email_exists) .cookie(cookies.clone()) .to_request(), @@ -104,7 +104,7 @@ async fn uname_email_exists_works() { payload.val = EMAIL.into(); let email_exist = test::call_service( - &mut app, + &app, post_request!(&payload, ROUTES.account.email_exists) .cookie(cookies.clone()) .to_request(), @@ -128,13 +128,13 @@ async fn email_udpate_password_validation_del_userworks() { let (data, creds, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let email_payload = Email { email: EMAIL.into(), }; let email_update_resp = test::call_service( - &mut app, + &app, post_request!(&email_payload, ROUTES.account.update_email) //post_request!(&email_payload, EMAIL_UPDATE) .cookie(cookies.clone()) @@ -149,7 +149,7 @@ async fn email_udpate_password_validation_del_userworks() { }; let delete_user_resp = test::call_service( - &mut app, + &app, post_request!(&payload, ROUTES.account.delete) .cookie(cookies) .to_request(), diff --git a/src/api/v1/auth.rs b/src/api/v1/auth.rs index 64d0dc81..eae1a951 100644 --- a/src/api/v1/auth.rs +++ b/src/api/v1/auth.rs @@ -181,6 +181,8 @@ pub mod runners { let msg = err.message(); if msg.contains("mcaptcha_users_name_key") { return Err(ServiceError::UsernameTaken); + } else if msg.contains("mcaptcha_users_email_key") { + return Err(ServiceError::EmailTaken); } else if msg.contains("mcaptcha_users_secret_key") { continue; } else { diff --git a/src/api/v1/mcaptcha/captcha.rs b/src/api/v1/mcaptcha/captcha.rs index b64c552d..d56bf83c 100644 --- a/src/api/v1/mcaptcha/captcha.rs +++ b/src/api/v1/mcaptcha/captcha.rs @@ -250,11 +250,11 @@ mod tests { register_and_signin(NAME, EMAIL, PASSWORD).await; let (data, _, signin_resp, token_key) = add_levels_util(NAME, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; // 4. delete token let del_token = test::call_service( - &mut app, + &app, post_request!(&token_key, ROUTES.mcaptcha.delete) .cookie(cookies.clone()) .to_request(), @@ -278,11 +278,11 @@ mod tests { register_and_signin(NAME, EMAIL, PASSWORD).await; let (data, _, signin_resp, token_key) = add_levels_util(NAME, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; // 2. update token key let update_token_resp = test::call_service( - &mut app, + &app, post_request!(&token_key, ROUTES.mcaptcha.update_key) .cookie(cookies.clone()) .to_request(), @@ -294,7 +294,7 @@ mod tests { // get token key with updated key let get_token_resp = test::call_service( - &mut app, + &app, post_request!(&updated_token, ROUTES.mcaptcha.get_token) .cookie(cookies.clone()) .to_request(), @@ -310,7 +310,7 @@ mod tests { get_token_key.key = "nonexistent".into(); let get_nonexistent_token_resp = test::call_service( - &mut app, + &app, post_request!(&get_token_key, ROUTES.mcaptcha.get_token) .cookie(cookies.clone()) .to_request(), diff --git a/src/api/v1/mcaptcha/duration.rs b/src/api/v1/mcaptcha/duration.rs index 507562fb..d0fabcd3 100644 --- a/src/api/v1/mcaptcha/duration.rs +++ b/src/api/v1/mcaptcha/duration.rs @@ -152,7 +152,7 @@ mod tests { register_and_signin(NAME, EMAIL, PASSWORD).await; let (data, _, signin_resp, token_key) = add_levels_util(NAME, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let update = UpdateDuration { key: token_key.key.clone(), @@ -162,7 +162,7 @@ mod tests { // check default let get_level_resp = test::call_service( - &mut app, + &app, post_request!(&token_key, ROUTES.duration.get) .cookie(cookies.clone()) .to_request(), @@ -175,7 +175,7 @@ mod tests { // update and check changes let update_duration = test::call_service( - &mut app, + &app, post_request!(&update, ROUTES.duration.update) .cookie(cookies.clone()) .to_request(), @@ -183,7 +183,7 @@ mod tests { .await; assert_eq!(update_duration.status(), StatusCode::OK); let get_level_resp = test::call_service( - &mut app, + &app, post_request!(&token_key, ROUTES.duration.get) .cookie(cookies.clone()) .to_request(), diff --git a/src/api/v1/mcaptcha/levels.rs b/src/api/v1/mcaptcha/levels.rs index cdef16bc..4b59b774 100644 --- a/src/api/v1/mcaptcha/levels.rs +++ b/src/api/v1/mcaptcha/levels.rs @@ -280,14 +280,14 @@ mod tests { register_and_signin(NAME, EMAIL, PASSWORD).await; let (data, _, signin_resp, key) = add_levels_util(NAME, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; // 2. get level let levels = vec![L1, L2]; let get_level_resp = test::call_service( - &mut app, + &app, post_request!(&key, ROUTES.levels.get) .cookie(cookies.clone()) .to_request(), @@ -313,7 +313,7 @@ mod tests { key: key.key.clone(), }; let add_token_resp = test::call_service( - &mut app, + &app, post_request!(&add_level, ROUTES.levels.update) .cookie(cookies.clone()) .to_request(), @@ -321,7 +321,7 @@ mod tests { .await; assert_eq!(add_token_resp.status(), StatusCode::OK); let get_level_resp = test::call_service( - &mut app, + &app, post_request!(&key, ROUTES.levels.get) .cookie(cookies.clone()) .to_request(), @@ -346,7 +346,7 @@ mod tests { key: key.key.clone(), }; let add_token_resp = test::call_service( - &mut app, + &app, post_request!(&add_level, ROUTES.levels.delete) .cookie(cookies.clone()) .to_request(), @@ -354,7 +354,7 @@ mod tests { .await; assert_eq!(add_token_resp.status(), StatusCode::OK); let get_level_resp = test::call_service( - &mut app, + &app, post_request!(&key, ROUTES.levels.get) .cookie(cookies.clone()) .to_request(), diff --git a/src/api/v1/meta.rs b/src/api/v1/meta.rs index b60d3756..31ba2339 100644 --- a/src/api/v1/meta.rs +++ b/src/api/v1/meta.rs @@ -116,10 +116,10 @@ mod tests { #[actix_rt::test] async fn build_details_works() { - let mut app = test::init_service(App::new().configure(services)).await; + let app = test::init_service(App::new().configure(services)).await; let resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(V1_API_ROUTES.meta.build_details) .to_request(), @@ -132,10 +132,10 @@ mod tests { async fn health_works() { println!("{}", V1_API_ROUTES.meta.health); let data = Data::new().await; - let mut app = get_app!(data).await; + let app = get_app!(data).await; let resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(V1_API_ROUTES.meta.health) .to_request(), diff --git a/src/api/v1/notifications/add.rs b/src/api/v1/notifications/add.rs index a75429f4..b5d8c754 100644 --- a/src/api/v1/notifications/add.rs +++ b/src/api/v1/notifications/add.rs @@ -86,7 +86,7 @@ mod tests { register_and_signin(NAME2, EMAIL2, PASSWORD).await; let (data, _creds, signin_resp) = signin(NAME1, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let msg = AddNotification { to: NAME2.into(), @@ -95,7 +95,7 @@ mod tests { }; let send_notification_resp = test::call_service( - &mut app, + &app, post_request!(&msg, V1_API_ROUTES.notifications.add) .cookie(cookies.clone()) .to_request(), diff --git a/src/api/v1/notifications/get.rs b/src/api/v1/notifications/get.rs index 0ef9f830..69c46a8c 100644 --- a/src/api/v1/notifications/get.rs +++ b/src/api/v1/notifications/get.rs @@ -114,7 +114,7 @@ mod tests { let (_data, _creds2, signin_resp2) = signin(NAME2, PASSWORD).await; let cookies = get_cookie!(signin_resp); let cookies2 = get_cookie!(signin_resp2); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let msg = AddNotification { to: NAME2.into(), @@ -123,7 +123,7 @@ mod tests { }; let send_notification_resp = test::call_service( - &mut app, + &app, post_request!(&msg, V1_API_ROUTES.notifications.add) .cookie(cookies.clone()) .to_request(), @@ -132,7 +132,7 @@ mod tests { assert_eq!(send_notification_resp.status(), StatusCode::OK); let get_notifications_resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(V1_API_ROUTES.notifications.get) .cookie(cookies2.clone()) diff --git a/src/api/v1/notifications/mark_read.rs b/src/api/v1/notifications/mark_read.rs index 3495abf3..169b0cfb 100644 --- a/src/api/v1/notifications/mark_read.rs +++ b/src/api/v1/notifications/mark_read.rs @@ -93,7 +93,7 @@ mod tests { let (_data, _creds2, signin_resp2) = signin(NAME2, PASSWORD).await; let cookies = get_cookie!(signin_resp); let cookies2 = get_cookie!(signin_resp2); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let msg = AddNotification { to: NAME2.into(), @@ -102,7 +102,7 @@ mod tests { }; let send_notification_resp = test::call_service( - &mut app, + &app, post_request!(&msg, V1_API_ROUTES.notifications.add) .cookie(cookies.clone()) .to_request(), @@ -111,7 +111,7 @@ mod tests { assert_eq!(send_notification_resp.status(), StatusCode::OK); let get_notifications_resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(V1_API_ROUTES.notifications.get) .cookie(cookies2.clone()) @@ -131,7 +131,7 @@ mod tests { id: notification.id, }; let mark_read_resp = test::call_service( - &mut app, + &app, post_request!(&mark_read_payload, V1_API_ROUTES.notifications.mark_read) .cookie(cookies2.clone()) .to_request(), @@ -140,7 +140,7 @@ mod tests { assert_eq!(mark_read_resp.status(), StatusCode::OK); let get_notifications_resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(V1_API_ROUTES.notifications.get) .cookie(cookies2.clone()) diff --git a/src/api/v1/pow/get_config.rs b/src/api/v1/pow/get_config.rs index 9c657e95..99f82ead 100644 --- a/src/api/v1/pow/get_config.rs +++ b/src/api/v1/pow/get_config.rs @@ -177,7 +177,7 @@ mod tests { register_and_signin(NAME, EMAIL, PASSWORD).await; let (data, _, signin_resp, token_key) = add_levels_util(NAME, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let get_config_payload = GetConfigPayload { key: token_key.key.clone(), @@ -186,7 +186,7 @@ mod tests { // update and check changes let get_config_resp = test::call_service( - &mut app, + &app, post_request!(&get_config_payload, V1_API_ROUTES.pow.get_config) .cookie(cookies.clone()) .to_request(), diff --git a/src/api/v1/pow/verify_pow.rs b/src/api/v1/pow/verify_pow.rs index 2d326a9d..5f373114 100644 --- a/src/api/v1/pow/verify_pow.rs +++ b/src/api/v1/pow/verify_pow.rs @@ -74,7 +74,7 @@ mod tests { register_and_signin(NAME, EMAIL, PASSWORD).await; let (data, _, _signin_resp, token_key) = add_levels_util(NAME, PASSWORD).await; - let mut app = get_app!(data).await; + let app = get_app!(data).await; let get_config_payload = GetConfigPayload { key: token_key.key.clone(), @@ -83,7 +83,7 @@ mod tests { // update and check changes let get_config_resp = test::call_service( - &mut app, + &app, post_request!(&get_config_payload, V1_API_ROUTES.pow.get_config) .to_request(), ) @@ -107,14 +107,14 @@ mod tests { }; let pow_verify_resp = test::call_service( - &mut app, + &app, post_request!(&work, V1_API_ROUTES.pow.verify_pow).to_request(), ) .await; assert_eq!(pow_verify_resp.status(), StatusCode::OK); let string_not_found = test::call_service( - &mut app, + &app, post_request!(&work, V1_API_ROUTES.pow.verify_pow).to_request(), ) .await; @@ -123,7 +123,7 @@ mod tests { assert_eq!(err.error, "Challenge: not found"); // let pow_config_resp = test::call_service( - // &mut app, + // &app, // post_request!(&get_config_payload, V1_API_ROUTES.pow.get_config).to_request(), // ) // .await; diff --git a/src/api/v1/pow/verify_token.rs b/src/api/v1/pow/verify_token.rs index 2c75b287..57a6c5c7 100644 --- a/src/api/v1/pow/verify_token.rs +++ b/src/api/v1/pow/verify_token.rs @@ -81,7 +81,7 @@ mod tests { register_and_signin(NAME, EMAIL, PASSWORD).await; let (data, _, _signin_resp, token_key) = add_levels_util(NAME, PASSWORD).await; - let mut app = get_app!(data).await; + let app = get_app!(data).await; let get_config_payload = GetConfigPayload { key: token_key.key.clone(), @@ -90,7 +90,7 @@ mod tests { // update and check changes let get_config_resp = test::call_service( - &mut app, + &app, post_request!(&get_config_payload, GET_URL).to_request(), ) .await; @@ -113,7 +113,7 @@ mod tests { }; let pow_verify_resp = test::call_service( - &mut app, + &app, post_request!(&work, VERIFY_CAPTCHA_URL).to_request(), ) .await; @@ -126,7 +126,7 @@ mod tests { }; let validate_client_token = test::call_service( - &mut app, + &app, post_request!(&validate_payload, VERIFY_TOKEN_URL).to_request(), ) .await; @@ -137,7 +137,7 @@ mod tests { // string not found let string_not_found = test::call_service( - &mut app, + &app, post_request!(&validate_payload, VERIFY_TOKEN_URL).to_request(), ) .await; @@ -151,7 +151,7 @@ mod tests { // key not found let key_not_found = test::call_service( - &mut app, + &app, post_request!(&validate_payload, VERIFY_TOKEN_URL).to_request(), ) .await; diff --git a/src/api/v1/tests/auth.rs b/src/api/v1/tests/auth.rs index d641113e..021a53f5 100644 --- a/src/api/v1/tests/auth.rs +++ b/src/api/v1/tests/auth.rs @@ -33,7 +33,7 @@ async fn auth_works() { const PASSWORD: &str = "longpassword"; const EMAIL: &str = "testuser1@a.com"; - let mut app = get_app!(data).await; + let app = get_app!(data).await; delete_user(NAME, &data).await; @@ -45,7 +45,7 @@ async fn auth_works() { email: None, }; let resp = test::call_service( - &mut app, + &app, post_request!(&msg, ROUTES.auth.register).to_request(), ) .await; @@ -108,7 +108,7 @@ async fn auth_works() { // 5. signout let signout_resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(ROUTES.auth.logout) .cookie(cookies) @@ -128,7 +128,7 @@ async fn serverside_password_validation_works() { let data = Data::new().await; delete_user(NAME, &data).await; - let mut app = get_app!(data).await; + let app = get_app!(data).await; // checking to see if server-side password validation (password == password_config) // works @@ -139,7 +139,7 @@ async fn serverside_password_validation_works() { email: None, }; let resp = test::call_service( - &mut app, + &app, post_request!(®ister_msg, ROUTES.auth.register).to_request(), ) .await; diff --git a/src/api/v1/tests/protected.rs b/src/api/v1/tests/protected.rs index c2755468..e9614155 100644 --- a/src/api/v1/tests/protected.rs +++ b/src/api/v1/tests/protected.rs @@ -54,16 +54,16 @@ async fn protected_routes_work() { let (data, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; for url in get_protected_urls.iter() { let resp = - test::call_service(&mut app, test::TestRequest::get().uri(url).to_request()) + test::call_service(&app, test::TestRequest::get().uri(url).to_request()) .await; assert_eq!(resp.status(), StatusCode::FOUND); let authenticated_resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(url) .cookie(cookies.clone()) diff --git a/src/docs.rs b/src/docs.rs index c9e1afa1..1a621a37 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -98,7 +98,7 @@ mod tests { async fn docs_works() { const FILE: &str = "favicon-32x32.png"; - let mut app = test::init_service( + let app = test::init_service( App::new() .wrap(actix_middleware::NormalizePath::new( actix_middleware::TrailingSlash::Trim, @@ -108,14 +108,14 @@ mod tests { .await; let resp = test::call_service( - &mut app, + &app, test::TestRequest::get().uri(DOCS.home).to_request(), ) .await; assert_eq!(resp.status(), StatusCode::OK); let resp = test::call_service( - &mut app, + &app, test::TestRequest::get().uri(DOCS.spec).to_request(), ) .await; @@ -124,7 +124,7 @@ mod tests { let uri = format!("{}{}", DOCS.home, FILE); let resp = test::call_service( - &mut app, + &app, test::TestRequest::get().uri(&uri).to_request(), ) .await; diff --git a/src/email/verification.rs b/src/email/verification.rs index c12aebba..50ce72ea 100644 --- a/src/email/verification.rs +++ b/src/email/verification.rs @@ -121,7 +121,6 @@ mod tests { let smtp = SETTINGS.smtp.as_ref().unwrap(); let from_addr = &data["headers"]["from"]; - ["address"]; assert!(from_addr.to_string().contains(&smtp.from)); diff --git a/src/pages/errors.rs b/src/pages/errors.rs index 54784034..82763c54 100644 --- a/src/pages/errors.rs +++ b/src/pages/errors.rs @@ -94,10 +94,10 @@ mod tests { #[actix_rt::test] async fn error_pages_work() { - let mut app = test::init_service(App::new().configure(services)).await; + let app = test::init_service(App::new().configure(services)).await; let resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(PAGES.errors.internal_server_error) .to_request(), @@ -106,7 +106,7 @@ mod tests { assert_eq!(resp.status(), StatusCode::INTERNAL_SERVER_ERROR); let resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(PAGES.errors.unknown_error) .to_request(), diff --git a/src/pages/mod.rs b/src/pages/mod.rs index 2e57b2a5..149bd8b1 100644 --- a/src/pages/mod.rs +++ b/src/pages/mod.rs @@ -54,7 +54,7 @@ mod tests { let (data, _, signin_resp) = register_and_signin(NAME, EMAIL, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let urls = vec![ PAGES.home, @@ -64,14 +64,14 @@ mod tests { for url in urls.iter() { let resp = test::call_service( - &mut app, + &app, test::TestRequest::get().uri(url).to_request(), ) .await; assert_eq!(resp.status(), StatusCode::FOUND); let authenticated_resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(url) .cookie(cookies.clone()) @@ -87,12 +87,12 @@ mod tests { #[actix_rt::test] async fn public_pages_tempaltes_work() { - let mut app = test::init_service(App::new().configure(services)).await; + let app = test::init_service(App::new().configure(services)).await; let urls = vec![PAGES.auth.login, PAGES.auth.join]; for url in urls.iter() { let resp = test::call_service( - &mut app, + &app, test::TestRequest::get().uri(url).to_request(), ) .await; diff --git a/src/pages/panel/sitekey/list.rs b/src/pages/panel/sitekey/list.rs index 0a619abc..85971ce6 100644 --- a/src/pages/panel/sitekey/list.rs +++ b/src/pages/panel/sitekey/list.rs @@ -87,10 +87,10 @@ mod test { let (data, _, signin_resp, key) = add_levels_util(NAME, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let list_sitekey_resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(PAGES.panel.sitekey.list) .cookie(cookies.clone()) diff --git a/src/pages/panel/sitekey/view.rs b/src/pages/panel/sitekey/view.rs index e8244af1..d5ba868c 100644 --- a/src/pages/panel/sitekey/view.rs +++ b/src/pages/panel/sitekey/view.rs @@ -123,12 +123,12 @@ mod test { let (data, _, signin_resp, key) = add_levels_util(NAME, PASSWORD).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let url = format!("/sitekey/{}/view", &key.key); let list_sitekey_resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(&url) .cookie(cookies.clone()) diff --git a/src/static_assets/static_files.rs b/src/static_assets/static_files.rs index ebaba401..c818a3ee 100644 --- a/src/static_assets/static_files.rs +++ b/src/static_assets/static_files.rs @@ -95,17 +95,17 @@ mod tests { #[actix_rt::test] async fn static_assets_work() { - let mut app = get_app!().await; + let app = get_app!().await; let resp = test::call_service( - &mut app, + &app, test::TestRequest::get().uri(*crate::JS).to_request(), ) .await; assert_eq!(resp.status(), StatusCode::OK); let resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(*crate::VERIFICATIN_WIDGET_JS) .to_request(), @@ -114,7 +114,7 @@ mod tests { assert_eq!(resp.status(), StatusCode::OK); let resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri(*crate::VERIFICATIN_WIDGET_CSS) .to_request(), @@ -123,7 +123,7 @@ mod tests { assert_eq!(resp.status(), StatusCode::OK); let resp = test::call_service( - &mut app, + &app, test::TestRequest::get() .uri( crate::FILES @@ -140,11 +140,11 @@ mod tests { async fn favicons_work() { assert!(Favicons::get("favicon.ico").is_some()); - //let mut app = test::init_service(App::new().configure(services)).await; - let mut app = get_app!().await; + //let app = test::init_service(App::new().configure(services)).await; + let app = get_app!().await; let resp = test::call_service( - &mut app, + &app, test::TestRequest::get().uri("/favicon.ico").to_request(), ) .await; diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 8012ba37..b217b46e 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -52,7 +52,7 @@ macro_rules! post_request { macro_rules! get_works { ($app:expr,$route:expr ) => { let list_sitekey_resp = test::call_service( - &mut $app, + &$app, test::TestRequest::get().uri($route).to_request(), ) .await; @@ -107,7 +107,7 @@ pub async fn register_and_signin( /// register utility pub async fn register(name: &str, email: &str, password: &str) { let data = Data::new().await; - let mut app = get_app!(data).await; + let app = get_app!(data).await; // 1. Register let msg = Register { @@ -117,7 +117,7 @@ pub async fn register(name: &str, email: &str, password: &str) { email: Some(email.into()), }; let resp = test::call_service( - &mut app, + &app, post_request!(&msg, ROUTES.auth.register).to_request(), ) .await; @@ -127,7 +127,7 @@ pub async fn register(name: &str, email: &str, password: &str) { /// signin util pub async fn signin(name: &str, password: &str) -> (Arc, Login, ServiceResponse) { let data = Data::new().await; - let mut app = get_app!(data.clone()).await; + let app = get_app!(data.clone()).await; // 2. signin let creds = Login { @@ -135,7 +135,7 @@ pub async fn signin(name: &str, password: &str) -> (Arc, Login, ServiceRes password: password.into(), }; let signin_resp = test::call_service( - &mut app, + &app, post_request!(&creds, ROUTES.auth.login).to_request(), ) .await; @@ -154,10 +154,10 @@ pub async fn bad_post_req_test( ) { let (data, _, signin_resp) = signin(name, password).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let dup_token_resp = test::call_service( - &mut app, + &app, post_request!(&payload, url) .cookie(cookies.clone()) .to_request(), @@ -183,7 +183,7 @@ pub async fn add_levels_util( ) -> (Arc, Login, ServiceResponse, MCaptchaDetails) { let (data, creds, signin_resp) = signin(name, password).await; let cookies = get_cookie!(signin_resp); - let mut app = get_app!(data).await; + let app = get_app!(data).await; let levels = vec![L1, L2]; @@ -195,7 +195,7 @@ pub async fn add_levels_util( // 1. add level let add_token_resp = test::call_service( - &mut app, + &app, post_request!(&add_level, ROUTES.levels.add) .cookie(cookies.clone()) .to_request(), diff --git a/src/widget/mod.rs b/src/widget/mod.rs index e766d466..6c068b48 100644 --- a/src/widget/mod.rs +++ b/src/widget/mod.rs @@ -75,7 +75,7 @@ mod test { #[actix_rt::test] async fn captcha_widget_route_works() { - let mut app = get_app!().await; + let app = get_app!().await; get_works!(app, crate::WIDGET_ROUTES.verification_widget); } }