mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2024-11-23 09:55:57 +03:00
duplicate email check and address clippy warnings
This commit is contained in:
parent
1d1b9e650f
commit
b7ec1bca22
24 changed files with 118 additions and 120 deletions
|
@ -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<T>][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<T>][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)]
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Data>, 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<Data>, 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<T: Serialize>(
|
|||
) {
|
||||
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<data::Data>, 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(),
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue