Annotation For tests/mail.rs
Logged in as anonymous

Lines of tests/mail.rs from check-in 158c9cffc6 that are changed by the sequence of edits moving toward check-in 98c5a42df0:

                         1: use smtp2tg::mail::MailServer;
                         2: 
                         3: use stacked_errors::{
                         4: 	Result,
                         5: 	StackableErr,
                         6: };
                         7: 
                         8: use tgbot::types::ChatPeerId;
158c9cffc6 2026-08-01    9: /// Builds a `MailServer` purely from an in-memory TOML source, no
158c9cffc6 2026-08-01   10: /// network access is performed while constructing it.
158c9cffc6 2026-08-01   11: fn build_server () -> Result<MailServer> {
158c9cffc6 2026-08-01   12: 	let settings = config::Config::builder()
                        13: 		.add_source(config::File::from_str(r#"
                        14: 			api_key = "test-api-key"
                        15: 			api_gateway = "https://api.telegram.org"
                        16: 			default = 0
                        17: 			fields = ["date", "from", "subject"]
                        18: 			domains = ["example.com"]
                        19: 
                        20: 			[recipients]
                        21: 			"someone@example.com" = 1
                        22: 			"root" = -1
158c9cffc6 2026-08-01   23: 		"#, config::FileFormat::Toml))
                        24: 		.build()
158c9cffc6 2026-08-01   25: 		.stack()?;
158c9cffc6 2026-08-01   26: 	MailServer::new(settings)
158c9cffc6 2026-08-01   27: }
158c9cffc6 2026-08-01   28: 
158c9cffc6 2026-08-01   29: #[test]
158c9cffc6 2026-08-01   30: fn get_id_properly_resolves_addresses () -> Result<()> {
158c9cffc6 2026-08-01   31: 	let server = build_server()?;
                        32: 	let cases = [
                        33: 		("someone@example.com", 1),
                        34: 		("someone", 0),
                        35: 		("root", -1),
                        36: 		("unknown@example.com", 0),
                        37: 		("SOMEONE@example.com", 1),	// uppercase local part
                        38: 		("someone@EXAMPLE.COM", 1),	// uppercase domain
                        39: 		("some.one@example.com", 1),	// functionally equivalent to skipping '.'
                        40: 		("some-one-2", 0),	// Hyphens
                        41: 	];
                        42: 	for (email, id) in cases {
158c9cffc6 2026-08-01   43: 		assert_eq!(*server.get_id(email)?, ChatPeerId::from(id), "email [{email}] expected to return id [{id}]");
                        44: 	}
                        45: 	let cases = [
                        46: 		"someone@otherdomain.net",
                        47: 		"@example.com",             // empty local part
                        48: 		"some@one@example.com",     // more than one '@'
                        49: 		"someone@example.com.evil",
                        50: 		"someone@example.org",
                        51: 	];
                        52: 	for email in cases {
158c9cffc6 2026-08-01   53: 		let err = server.get_id(email).err()
158c9cffc6 2026-08-01   54: 			.ok_or_else(|| format!("email [{email}] expected to fail")).stack()?;
158c9cffc6 2026-08-01   55: 		assert!(err.to_string().contains("Doesn't look like address from one of our domains."));
158c9cffc6 2026-08-01   56: 	}
                        57: 	Ok(())
                        58: }