use crate::helpers::{TestInfoBuilder, EMPTY_MESSAGE}; use lettre::{ transport::smtp::{authentication::Mechanism, client::Tls}, Transport, }; #[test] fn plain_incorrect_user() { let password = "abcd1234"; let test_info = TestInfoBuilder::new() .add_mailbox("sender@domain1.com", password) .auth_as("whodis@domain1.com", password) .build(); let mailer = test_info .mailer_builder .tls(Tls::None) .authentication(vec![Mechanism::Plain]) .build(); assert!(mailer.send(&EMPTY_MESSAGE).is_err()); } #[test] fn plain_incorrect_password() { let smtp_user = "sender@domain1.com"; let test_info = TestInfoBuilder::new() .add_mailbox(smtp_user, "abcd1234") .auth_as(smtp_user, "incorrect_password") .build(); let mailer = test_info .mailer_builder .tls(Tls::None) .authentication(vec![Mechanism::Plain]) .build(); assert!(mailer.send(&EMPTY_MESSAGE).is_err()); } #[test] fn multiple_users_auth_with_first_one() { let smtp_user = "sender@domain1.com"; let password = "abcd1234"; let test_info = TestInfoBuilder::new() .add_mailbox(smtp_user, password) .add_mailbox("user2@domain1.com", "anotherpassword") .auth_as(smtp_user, password) .build(); let mailer = test_info .mailer_builder .tls(Tls::None) .authentication(vec![Mechanism::Plain]) .build(); assert!(mailer.send(&EMPTY_MESSAGE).is_ok()); } #[test] fn multiple_users_auth_with_second_one() { let smtp_user = "sender@domain1.com"; let password = "abcd1234"; let test_info = TestInfoBuilder::new() .add_mailbox("user2domain1.com", "another_password") .add_mailbox(smtp_user, password) .auth_as(smtp_user, password) .build(); let mailer = test_info .mailer_builder .tls(Tls::None) .authentication(vec![Mechanism::Plain]) .build(); assert!(mailer.send(&EMPTY_MESSAGE).is_ok()); }