From 8e901e2b8ff6a2b9d81574877b75aa271e7751e5 Mon Sep 17 00:00:00 2001 From: Yudhya P W Date: Fri, 25 Mar 2022 16:24:32 +0700 Subject: [PATCH] removed commented code --- src/domain/subscriber_email.rs | 5 - src/email_client.rs | 1 - src/routes/admin/newsletters/post.rs | 107 +-------------------- src/routes/admin/password/post.rs | 13 --- src/routes/login/login.html | 22 ----- src/telemetry.rs | 5 - tests/api/login.rs | 3 - tests/api/newsletters.rs | 134 --------------------------- 8 files changed, 3 insertions(+), 287 deletions(-) delete mode 100644 src/routes/login/login.html diff --git a/src/domain/subscriber_email.rs b/src/domain/subscriber_email.rs index 3360854..a1567b8 100644 --- a/src/domain/subscriber_email.rs +++ b/src/domain/subscriber_email.rs @@ -55,11 +55,6 @@ mod tests { } // // We have removed the `assert_ok` import. - // #[test] - // fn valid_emails_are_parsed_successfully() { - // let email = SafeEmail().fake(); - // claim::assert_ok!(SubscriberEmail::parse(email)); - // } // Both `Clone` and `Debug` are required by `quickcheck` #[derive(Debug, Clone)] diff --git a/src/email_client.rs b/src/email_client.rs index 41b8064..91c6630 100644 --- a/src/email_client.rs +++ b/src/email_client.rs @@ -119,7 +119,6 @@ mod tests { let result: Result = serde_json::from_slice(&request.body); if let Ok(body) = result { - // dbg!(&body); // Check that all the mandatory fields are populated // without inspecting the field values body.get("From").is_some() diff --git a/src/routes/admin/newsletters/post.rs b/src/routes/admin/newsletters/post.rs index e617aa6..2c5e9b8 100644 --- a/src/routes/admin/newsletters/post.rs +++ b/src/routes/admin/newsletters/post.rs @@ -101,38 +101,7 @@ pub async fn publish_newsletter( .context("Failed to enqueue delivery tasks") .map_err(e500)?; - // let subscribers = get_confirmed_subscribers(&pool).await.map_err(e500)?; - // for subscriber in subscribers { - // match subscriber { - // Ok(subscriber) => { - // email_client - // .send_email( - // &subscriber.email, - // &title, - // &html_content, - // &text_content, - // ) - // .await - // .with_context(|| { - // format!( - // "failed to send newsletter issue to {}", - // subscriber.email - // ) - // }) - // .map_err(e500)?; - // } - // Err(err) => { - // tracing::warn!( - // // We record the error chain as a structured field - // // on the log record - // err.cause_chain = ?err, // what is this!? - // err.message = %err, - // "Skipping a confirmed subscriber. \ - // Their stored contact is invalid", - // ); - // } - // } - // } + // move send email logic to worker // save the saved response let response = see_other("/admin/newsletters"); @@ -151,49 +120,7 @@ fn success_message() -> FlashMessage { ) } -// fn basic_authentication( -// headers: &HeaderMap, -// ) -> Result { -// // Header value, if present, must be valid UTF8 string -// let header_value = headers -// .get("Authorization") -// .context("The 'Authorization' header was missing")? -// .to_str() -// .context("The 'Authorization' header was not a valid UTF8 string.")?; - -// let base64encoded_segment = header_value -// .strip_prefix("Basic ") -// .context("The authorization scheme was not 'Basic'.")?; - -// let decoded_bytes = -// base64::decode_config(base64encoded_segment, base64::STANDARD) -// .context("Failed to base64-decode 'Basic' credentials")?; - -// let decoded_credentials = String::from_utf8(decoded_bytes) -// .context("The decoded credential string is not valid UTF8")?; - -// // split into two segments, using ':' as delimitator -// let mut credentials = decoded_credentials.splitn(2, ':'); - -// let username = credentials -// .next() -// .ok_or_else(|| { -// anyhow::anyhow!("A username must be provided in 'Basic' auth.") -// })? -// .to_string(); - -// let password = credentials -// .next() -// .ok_or_else(|| { -// anyhow::anyhow!("A password must be provided in 'Basic' auth.") -// })? -// .to_string(); - -// Ok(Credentials { -// username, -// password: Secret::new(password), -// }) -// } +// removed basic authentication #[derive(serde::Deserialize, serde::Serialize)] pub struct FormData { @@ -204,35 +131,7 @@ pub struct FormData { pub idempotency_key: String, } -// pub struct ConfirmedSubscriber { -// email: SubscriberEmail, -// } - -// #[tracing::instrument(name = "Get confirmed subscriber", skip(pool))] -// pub async fn get_confirmed_subscribers( -// pool: &PgPool, -// // We are returning a `Vec` of `Result`s in the happy case. -// // This allows the caller to bubble up errors due to network issues or other -// // transient failures using the `?` operator, while the compiler -// // forces them to handle the subtler mapping error. -// // See http://sled.rs/errors.html for a deep-dive about this technique. -// ) -> Result>, anyhow::Error> { -// let confirmed_subscribers = sqlx::query!( -// r#" -// SELECT email FROM subscriptions -// WHERE status = 'confirmed' -// "#, -// ) -// .fetch_all(pool) -// .await? -// .into_iter() -// .map(|r| match SubscriberEmail::parse(r.email) { -// Ok(email) => Ok(ConfirmedSubscriber { email }), -// Err(e) => Err(anyhow::anyhow!(e)), -// }) -// .collect(); -// Ok(confirmed_subscribers) -// } +// confirmed subscriber to worker #[tracing::instrument(skip_all)] async fn insert_newsletter_issue( diff --git a/src/routes/admin/password/post.rs b/src/routes/admin/password/post.rs index e6e6a70..01097ac 100644 --- a/src/routes/admin/password/post.rs +++ b/src/routes/admin/password/post.rs @@ -64,16 +64,3 @@ pub async fn change_password( FlashMessage::error("The current password has been changed.").send(); Ok(see_other("/admin/password")) } - -// async fn reject_anonymous_users( -// session: TypedSession -// ) -> Result { -// match session.get_user_id().map_err(e500)? { -// Some(user_id) => Ok(user_id), -// None => { -// let response = see_other("/login"); -// let e = anyhow::anyhow!("The user has not logged in"); -// Err(InternalError::from_response(e, response).into()) -// }, -// } -// } diff --git a/src/routes/login/login.html b/src/routes/login/login.html deleted file mode 100644 index 020e753..0000000 --- a/src/routes/login/login.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - Login - - - -
- - - -
- - - \ No newline at end of file diff --git a/src/telemetry.rs b/src/telemetry.rs index 8a7a1d9..b9eb5e1 100644 --- a/src/telemetry.rs +++ b/src/telemetry.rs @@ -59,10 +59,6 @@ where /// /// It should only be called once! pub fn init_subscriber(subscriber: impl Subscriber + Send + Sync) { - // env_logger::Builder::from_env( - // env_logger::Env::default().default_filter_or("info"), - // ) - // .init(); LogTracer::init().expect("Failed to set logger"); set_global_default(subscriber).expect("Failed to set subscriber"); } @@ -75,5 +71,4 @@ where { let current_span = tracing::Span::current(); tokio::task::spawn_blocking(move || current_span.in_scope(f)) - // tokio::task::spawn_blocking(f) } diff --git a/tests/api/login.rs b/tests/api/login.rs index 48c095b..aa54e90 100644 --- a/tests/api/login.rs +++ b/tests/api/login.rs @@ -17,9 +17,6 @@ async fn an_error_flash_message_is_set_on_failure() { assert_eq!(response.headers().get("Location").unwrap(), "/login"); // No longer asserting fats related to cookies - // let flash_cookie = - // response.cookies().find(|c| c.name() == "_flash").unwrap(); - // assert_eq!(flash_cookie.value(), "Authentication failed."); // Act - Part 2 - Follow the redirect let response = app.get_login().await; diff --git a/tests/api/newsletters.rs b/tests/api/newsletters.rs index 8d93d74..45c7fb5 100644 --- a/tests/api/newsletters.rs +++ b/tests/api/newsletters.rs @@ -300,137 +300,3 @@ async fn concurrent_form_submisison_is_handled_gracefully() { app.dispatch_all_pending_emails().await; // Mock verifies on Drop that we have sent the newsletter email once } - -// // Short-hand for a common mocking setup -// fn when_sending_an_email() -> MockBuilder { -// Mock::given(path("/email")).and(method("POST")) -// } - -// #[tokio::test] -// async fn transient_error_do_not_cause_duplicate_deliveries_on_retries() { -// let app = spawn_app().await; -// let newsletter_request_body = &serde_json::json!({ -// "title": "Newsletter title", -// "text_content": "Newsletter body as plain text", -// "html_content": "

Newsletter body as HTML

", -// "idempotency_key": Uuid::new_v4().to_string(), -// }); - -// // Two subscribers insted of one -// create_confirmed_subscriber(&app).await; -// create_confirmed_subscriber(&app).await; -// app.test_user.login(&app).await; - -// // Part 1 - Submit newsletter form -// // Email delivery failes for the second subscriber -// when_sending_an_email() -// .respond_with(ResponseTemplate::new(200)) -// .up_to_n_times(1) -// .expect(1) -// .mount(&app.email_server) -// .await; -// when_sending_an_email() -// .respond_with(ResponseTemplate::new(500)) -// .up_to_n_times(1) -// .expect(1) -// .mount(&app.email_server) -// .await; - -// let response = app.post_newsletters(&newsletter_request_body).await; -// assert_eq!(response.status().as_u16(), 500); - -// // Part2 - Retry submitting the form -// // Email delivery will succeed for both subscriber now -// when_sending_an_email() -// .respond_with(ResponseTemplate::new(200)) -// .expect(1) -// .named("Delivery retry") -// .mount(&app.email_server) -// .await; - -// let response = app.post_newsletters(&newsletter_request_body).await; -// assert_eq!(response.status().as_u16(), 303); - -// // Mock verifies on Drop that we did not send out duplicates -// } - -// #[tokio::test] -// async fn requests_missing_authorization_are_rejected() { -// // Arrange -// let app = spawn_app().await; - -// let response = reqwest::Client::new() -// .post(&format!("{}/admin/newsletters", &app.address)) -// .form(&FormData { -// title: "Newsletter title".to_string(), -// text_content: "Newsletter body as plain text".to_string(), -// html_content: "

Newsletter body as HTML

".to_string(), -// }) -// .send() -// .await -// .expect("Failed execute request."); - -// // Assert -// assert_eq!(401, response.status().as_u16()); -// assert_eq!( -// r#"Basic realm="publish""#, -// response.headers()["WWW-Authenticate"] -// ); -// } - -// #[tokio::test] -// async fn non_existing_user_is_rejected() { -// // Arrange -// let app = spawn_app().await; -// // Random credentials -// let username = Uuid::new_v4().to_string(); -// let password = Uuid::new_v4().to_string(); - -// let respone = reqwest::Client::new() -// .post(&format!("{}/admin/newsletters", &app.address)) -// .basic_auth(username, Some(password)) -// .form(&FormData { -// title: "Newsletter title".to_string(), -// text_content: "Newsletter body as plain text".to_string(), -// html_content: "

Newsletter body as HTML

".to_string(), -// }) -// .send() -// .await -// .expect("Failed execute request."); - -// // Assert -// assert_eq!(401, respone.status().as_u16()); -// assert_eq!( -// r#"Basic realm="publish""#, -// respone.headers()["WWW-Authenticate"] -// ); -// } - -// #[tokio::test] -// async fn invalid_password_is_rejected() { -// // Arrange -// let app = spawn_app().await; -// // Random credentials -// let username = &app.test_user.username; -// let password = Uuid::new_v4().to_string(); -// assert_ne!(app.test_user.password, password); - -// let respone = reqwest::Client::new() -// .post(&format!("{}/admin/newsletters", &app.address)) -// .basic_auth(username, Some(password)) -// .form(&FormData { -// title: "Newsletter title".to_string(), -// text_content: "Newsletter body as plain text".to_string(), -// html_content: "

Newsletter body as HTML

".to_string(), -// }) -// .send() -// .await -// .expect("Failed execute request."); - -// // Assert -// assert_eq!(401, respone.status().as_u16()); -// assert_eq!( -// r#"Basic realm="publish""#, -// respone.headers()["WWW-Authenticate"] -// ); -// }