duplicate email check and address clippy warnings

This commit is contained in:
realaravinth
2021-07-11 21:46:50 +05:30
parent 1d1b9e650f
commit b7ec1bca22
24 changed files with 118 additions and 120 deletions

View File

@@ -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(),

View File

@@ -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 {

View File

@@ -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(),

View File

@@ -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(),

View File

@@ -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(),

View File

@@ -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(),

View File

@@ -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(),

View File

@@ -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())

View File

@@ -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())

View File

@@ -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(),

View File

@@ -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;

View File

@@ -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;

View File

@@ -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!(&register_msg, ROUTES.auth.register).to_request(),
)
.await;

View File

@@ -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())