Skip to content

Commit

Permalink
fix(core): Improve invalid parser (#1166)
Browse files Browse the repository at this point in the history
* fix(core): Improve invalid parser

* add more parsing ones

* fix tests
  • Loading branch information
amaury1093 authored Aug 30, 2022
1 parent 84fcc0d commit bb46004
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
14 changes: 8 additions & 6 deletions backend/tests/check_email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,28 @@ const FOO_BAR_BAZ_RESPONSE: &str = r#"{"input":"foo@bar.baz","is_reachable":"inv

#[tokio::test]
async fn test_input_foo_bar() {
env::remove_var("RCH_HEADER_SECRET");
env::set_var("RCH_HEADER_SECRET", "foobar");

let resp = request()
.path("/v0/check_email")
.method("POST")
.header(REACHER_SECRET_HEADER, "foobar")
.json(&serde_json::from_str::<EndpointRequest>(r#"{"to_email": "foo@bar"}"#).unwrap())
.reply(&create_routes(None))
.await;

assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(resp.status(), StatusCode::OK, "{:?}", resp.body());
assert_eq!(resp.body(), FOO_BAR_RESPONSE);
}

#[tokio::test]
async fn test_input_foo_bar_baz() {
env::remove_var("RCH_HEADER_SECRET");
env::set_var("RCH_HEADER_SECRET", "foobar");

let resp = request()
.path("/v0/check_email")
.method("POST")
.header(REACHER_SECRET_HEADER, "foobar")
.json(&serde_json::from_str::<EndpointRequest>(r#"{"to_email": "foo@bar.baz"}"#).unwrap())
.reply(&create_routes(None))
.await;
Expand All @@ -66,7 +68,7 @@ async fn test_reacher_secret_missing_header() {
.reply(&create_routes(None))
.await;

assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST, "{:?}", resp.body());
assert_eq!(resp.body(), r#"Missing request header "x-reacher-secret""#);
}

Expand All @@ -82,7 +84,7 @@ async fn test_reacher_secret_wrong_secret() {
.reply(&create_routes(None))
.await;

assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
assert_eq!(resp.status(), StatusCode::BAD_REQUEST, "{:?}", resp.body());
assert_eq!(resp.body(), r#"Invalid request header "x-reacher-secret""#);
}

Expand All @@ -98,6 +100,6 @@ async fn test_reacher_secret_correct_secret() {
.reply(&create_routes(None))
.await;

assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(resp.status(), StatusCode::OK, "{:?}", resp.body());
assert_eq!(resp.body(), FOO_BAR_RESPONSE);
}
12 changes: 9 additions & 3 deletions core/src/smtp/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ pub fn is_invalid(e: &str, email: &EmailAddress) -> bool {
|| e.contains("no longer available")
// permanent: RCPT (<EMAIL>) dosn't exist (on @hgy.ooo)
|| e.contains("dosn't exist") // sic! typo is intentional
// 5.1.1 <EMAIL>: Email address could not be found, or was misspelled (G8) (on biotech-calendar.com, invoicefactoring.com)
|| e.contains("could not be found")
// No such person at this address (on aconsa.com.mx)
|| e.contains("no such person")
// Callout verification failed: 550 No Such User Here (on medipro.co.uk)
|| e.contains("callout verification failed")
}

/// Check that the mailbox has a full inbox.
Expand All @@ -94,9 +100,9 @@ pub fn is_full_inbox(e: &str) -> bool {
|| e.contains("mailbox full")
// https://answers.microsoft.com/en-us/outlook_com/forum/all/how-do-i-interpret-the-delivery-failure-message/2f1bf9c0-8b03-4f8f-aacc-5f6ba60a73f3
|| e.contains("quote exceeded")
|| e.contains("over quota")
// 550 user has too many messages on the server
|| e.contains("too many messages")
|| e.contains("over quota")
// 550 user has too many messages on the server
|| e.contains("too many messages")
}

/// Check if the email account has been disabled or blocked by the email
Expand Down

0 comments on commit bb46004

Please sign in to comment.