use crate::helpers::{TestInfoBuilder, DEFAULT_SENDER, EMPTY_MESSAGE};
use fake::{faker::internet::en::Password, Fake};
use lettre::{
transport::smtp::{authentication::Mechanism, client::Tls},
Transport,
};
#[test]
fn plain_incorrect_user() {
let password: String = Password(8..16).fake();
let test_info = TestInfoBuilder::new()
.add_mailbox(DEFAULT_SENDER, &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 test_info = TestInfoBuilder::new()
.add_mailbox(DEFAULT_SENDER, "P@ssw0rd")
.auth_as(DEFAULT_SENDER, "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 password: String = Password(8..16).fake();
let test_info = TestInfoBuilder::new()
.add_mailbox(DEFAULT_SENDER, &password)
.add_mailbox("user2@domain1.com", "another_password")
.auth_as(DEFAULT_SENDER, &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 password: String = Password(8..16).fake();
let test_info = TestInfoBuilder::new()
.add_mailbox("user2domain1.com", "another_password")
.add_mailbox(DEFAULT_SENDER, &password)
.auth_as(DEFAULT_SENDER, &password)
.build();
let mailer = test_info
.mailer_builder
.tls(Tls::None)
.authentication(vec![Mechanism::Plain])
.build();
assert!(mailer.send(&EMPTY_MESSAGE).is_ok());
}