Skip to content

Commit

Permalink
fix: Put Smtp debug details in Debug struct
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 committed Dec 5, 2023
1 parent ee741f4 commit 5b71ca5
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 85 deletions.
100 changes: 62 additions & 38 deletions backend/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,14 @@
"is_disabled": {
"type": "boolean",
"description": "Has this email address been disabled by the email provider?"
},
"verif_method": {
"$ref": "#/components/schemas/VerifMethod"
}
},
"required": [
"can_connect_smtp",
"has_full_inbox",
"is_catch_all",
"is_deliverable",
"is_disabled",
"verif_method"
"is_disabled"
]
},
"SyntaxDetails": {
Expand Down Expand Up @@ -326,7 +322,7 @@
"HotmailVerifMethod": {
"type": "string",
"x-stoplight": {
"id": "tiy37w0jp5x13"
"id": "ntdugsleyotut"
},
"title": "HotmailVerifMethod",
"enum": ["Api", "Headless", "Smtp"],
Expand All @@ -335,7 +331,7 @@
"GmailVerifMethod": {
"type": "string",
"x-stoplight": {
"id": "2p7yqzxi6n3bj"
"id": "xo5r48yhtxiwr"
},
"title": "GmailVerifMethod",
"enum": ["Api", "Smtp"],
Expand Down Expand Up @@ -430,12 +426,56 @@
"description": "Password to pass to proxy authentication."
}
},
"required": ["host", "port"]
"required": ["host", "port"],
"description": "Proxy information for email verification."
},
"DebugDetails": {
"title": "DebugDetails",
"x-stoplight": {
"id": "4wxlk39h8v9kz"
},
"type": "object",
"properties": {
"start_time": {
"type": "string",
"x-stoplight": {
"id": "60i65k60m8e8d"
},
"description": "The time when the email verification started."
},
"end_time": {
"type": "string",
"x-stoplight": {
"id": "zw4ccbvwsoh6q"
},
"description": "The time when the email verification ended."
},
"duration": {
"$ref": "#/components/schemas/Duration"
},
"server_name": {
"type": "string",
"x-stoplight": {
"id": "2jrbdecvqh4t5"
},
"description": "The name of the server that performed the email verification."
},
"smtp": {
"$ref": "#/components/schemas/DebugDetailsSmtp"
}
},
"required": [
"start_time",
"end_time",
"duration",
"server_name",
"smtp"
]
},
"Duration": {
"title": "Duration",
"x-stoplight": {
"id": "kwbhwi9fkpg6q"
"id": "bg9y0iez4zati"
},
"type": "object",
"description": "An object representing a duration (seconds + nanoseconds).",
Expand All @@ -451,66 +491,50 @@
},
"required": ["secs", "nanos"]
},
"DebugDetails": {
"title": "DebugDetails",
"DebugDetailsSmtp": {
"title": "DebugDetailsSmtp",
"x-stoplight": {
"id": "jhror15zeepgx"
"id": "2a90bzapppo0j"
},
"type": "object",
"properties": {
"start_time": {
"type": "string",
"x-stoplight": {
"id": "ms8ftx9vwth1a"
}
},
"end_time": {
"type": "string",
"x-stoplight": {
"id": "g2kydtwtmr7po"
}
},
"duration": {
"$ref": "#/components/schemas/Duration"
},
"server_ip": {
"type": "string",
"x-stoplight": {
"id": "ktn104e8oyu6d"
}
"verif_method": {
"$ref": "#/components/schemas/VerifMethod"
}
}
},
"description": "Smtp details used for debugging, such as which method is used."
},
"VerifMethod": {
"title": "VerifMethod",
"x-stoplight": {
"id": "yfa2hjmyy321x"
"id": "9xw9e1jwti230"
},
"type": "object",
"properties": {
"type": {
"x-stoplight": {
"id": "dzmw4acub9xp6"
"id": "4ogsz639tcdb6"
},
"enum": ["Smtp", "Headless", "Api", "Skipped"],
"description": "The method used to perform the email verification"
},
"host": {
"type": "string",
"x-stoplight": {
"id": "nvnjrm1137x96"
"id": "lxbxckircn0sk"
},
"description": "If `type` is `SmtpConnection`, the hostname that Reacher connected to."
},
"port": {
"type": "number",
"x-stoplight": {
"id": "xpxzvllzxxyyn"
"id": "xqfdjyoiodq23"
},
"description": "If `type` is `SmtpConnection`, the port that Reacher connected to."
}
},
"required": ["type"]
"required": ["type"],
"description": "The verification method used for the email."
}
},
"securitySchemes": {
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/check_email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use reacher_backend::routes::create_routes;
use warp::http::StatusCode;
use warp::test::request;

const FOO_BAR_RESPONSE: &str = r#"{"input":"foo@bar","is_reachable":"invalid","misc":{"is_disposable":false,"is_role_account":false,"gravatar_url":null,"haveibeenpwned":null},"mx":{"accepts_mail":false,"records":[]},"smtp":{"can_connect_smtp":false,"has_full_inbox":false,"is_catch_all":false,"is_deliverable":false,"is_disabled":false,"verif_method":{"type":"Skipped"}},"syntax":{"address":null,"domain":"","is_valid_syntax":false,"username":"","normalized_email":null,"suggestion":null}"#;
const FOO_BAR_BAZ_RESPONSE: &str = r#"{"input":"foo@bar.baz","is_reachable":"invalid","misc":{"is_disposable":false,"is_role_account":false,"gravatar_url":null,"haveibeenpwned":null},"mx":{"accepts_mail":false,"records":[]},"smtp":{"can_connect_smtp":false,"has_full_inbox":false,"is_catch_all":false,"is_deliverable":false,"is_disabled":false,"verif_method":{"type":"Skipped"}},"syntax":{"address":"foo@bar.baz","domain":"bar.baz","is_valid_syntax":true,"username":"foo","normalized_email":"foo@bar.baz","suggestion":null}"#;
const FOO_BAR_RESPONSE: &str = r#"{"input":"foo@bar","is_reachable":"invalid","misc":{"is_disposable":false,"is_role_account":false,"gravatar_url":null,"haveibeenpwned":null},"mx":{"accepts_mail":false,"records":[]},"smtp":{"can_connect_smtp":false,"has_full_inbox":false,"is_catch_all":false,"is_deliverable":false,"is_disabled":false},"syntax":{"address":null,"domain":"","is_valid_syntax":false,"username":"","normalized_email":null,"suggestion":null}"#;
const FOO_BAR_BAZ_RESPONSE: &str = r#"{"input":"foo@bar.baz","is_reachable":"invalid","misc":{"is_disposable":false,"is_role_account":false,"gravatar_url":null,"haveibeenpwned":null},"mx":{"accepts_mail":false,"records":[]},"smtp":{"can_connect_smtp":false,"has_full_inbox":false,"is_catch_all":false,"is_deliverable":false,"is_disabled":false},"syntax":{"address":"foo@bar.baz","domain":"bar.baz","is_valid_syntax":true,"username":"foo","normalized_email":"foo@bar.baz","suggestion":null}"#;

#[tokio::test]
async fn test_input_foo_bar() {
Expand Down
3 changes: 2 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ pub async fn check_email(input: &CheckEmailInput) -> CheckEmailOutput {
mx_records[mx_records.len() - 1]
};

let my_smtp = check_smtp(
let (my_smtp, smtp_debug) = check_smtp(
my_syntax
.address
.as_ref()
Expand Down Expand Up @@ -249,6 +249,7 @@ pub async fn check_email(input: &CheckEmailInput) -> CheckEmailOutput {
duration: end_time
.duration_since(start_time)
.unwrap_or(Duration::from_secs(0)),
smtp: smtp_debug,
..Default::default()
},
}
Expand Down
6 changes: 1 addition & 5 deletions core/src/smtp/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::iter;
use std::str::FromStr;
use std::time::Duration;

use super::{parser, SmtpConnection, VerifMethod};
use super::parser;
use super::{SmtpDetails, SmtpError};
use crate::{
rules::{has_rule, Rule},
Expand Down Expand Up @@ -334,10 +334,6 @@ async fn check_smtp_without_retry(
is_catch_all,
is_deliverable: deliverability.is_deliverable,
is_disabled: deliverability.is_disabled,
verif_method: VerifMethod::Smtp(SmtpConnection {
host: host.to_string(),
port,
}),
})
}

Expand Down
Loading

0 comments on commit 5b71ca5

Please sign in to comment.