reinhardt-middleware 0.1.2

Middleware system for request/response processing pipeline
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
//! Broken link detection middleware
//!
//! Detects and logs 404 errors that originate from internal links (same domain).
//! Useful for identifying broken links on your site before users encounter them.
//!
//! ## Email Notifications
//!
//! This middleware can send email notifications to managers when broken links are
//! detected. The canonical entry point is
//! [`BrokenLinkEmailsMiddleware::from_settings`], which copies
//! `Settings::managers` into [`BrokenLinkConfig::managers`] once at middleware
//! construction time. When no `Settings` instance is available, callers may
//! configure recipients directly via [`BrokenLinkConfig::with_emails`]; the
//! middleware then synthesizes anonymous `Contact` entries from those addresses.

use async_trait::async_trait;
use hyper::StatusCode;
use hyper::header::{REFERER, USER_AGENT};
use regex::Regex;
use reinhardt_conf::settings;
use reinhardt_http::{Handler, Middleware, Request, Response, Result};
use reinhardt_mail;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::sync::Arc;

/// Configuration for broken link detection
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BrokenLinkConfig {
	/// Enable or disable broken link detection
	pub enabled: bool,
	/// Email addresses to notify (if configured)
	pub email_addresses: Vec<String>,
	/// Path patterns to ignore (regex)
	pub ignored_paths: Vec<String>,
	/// User-Agent patterns to ignore (e.g., bots)
	pub ignored_user_agents: Vec<String>,
	/// Managers to notify when a broken link is detected
	///
	/// Resolved from `Settings::managers` at middleware construction time via
	/// [`BrokenLinkConfig::from_settings`]. When empty, the middleware falls
	/// back to converting [`BrokenLinkConfig::email_addresses`] into anonymous
	/// `Contact` entries.
	pub managers: Vec<settings::Contact>,
}

impl BrokenLinkConfig {
	/// Create a new default configuration
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_middleware::BrokenLinkConfig;
	///
	/// let config = BrokenLinkConfig::new();
	/// assert!(config.enabled);
	/// ```
	pub fn new() -> Self {
		Self {
			enabled: true,
			email_addresses: Vec::new(),
			ignored_paths: vec![
				// Common paths to ignore
				"/favicon.ico".to_string(),
				"/robots.txt".to_string(),
				"/.well-known/.*".to_string(),
			],
			ignored_user_agents: vec![
				// Common bots/crawlers to ignore
				"bot".to_string(),
				"crawler".to_string(),
				"spider".to_string(),
				"slurp".to_string(),
			],
			managers: Vec::new(),
		}
	}

	/// Create a `BrokenLinkConfig` from application `Settings`
	///
	/// Resolves `Settings::managers` once at construction time, so the
	/// middleware does not need to re-parse settings on every request.
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_conf::Settings;
	/// use reinhardt_middleware::BrokenLinkConfig;
	///
	/// #[allow(deprecated)]
	/// let settings = Settings::default();
	/// #[allow(deprecated)]
	/// let config = BrokenLinkConfig::from_settings(&settings);
	/// assert!(config.enabled);
	/// ```
	#[allow(deprecated)] // Settings is deprecated in favor of composable fragments
	pub fn from_settings(settings: &settings::Settings) -> Self {
		let mut config = Self::new();
		config.managers = settings.managers.clone();
		config
	}

	/// Disable broken link detection
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_middleware::BrokenLinkConfig;
	///
	/// let config = BrokenLinkConfig::new().disabled();
	/// assert!(!config.enabled);
	/// ```
	pub fn disabled(mut self) -> Self {
		self.enabled = false;
		self
	}

	/// Add email addresses for notifications
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_middleware::BrokenLinkConfig;
	///
	/// let config = BrokenLinkConfig::new()
	///     .with_emails(vec!["admin@example.com".to_string()]);
	/// ```
	pub fn with_emails(mut self, emails: Vec<String>) -> Self {
		self.email_addresses = emails;
		self
	}

	/// Add additional paths to ignore
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_middleware::BrokenLinkConfig;
	///
	/// let config = BrokenLinkConfig::new()
	///     .with_ignored_paths(vec!["/admin/.*".to_string()]);
	/// ```
	pub fn with_ignored_paths(mut self, paths: Vec<String>) -> Self {
		self.ignored_paths.extend(paths);
		self
	}

	/// Add additional user agents to ignore
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_middleware::BrokenLinkConfig;
	///
	/// let config = BrokenLinkConfig::new()
	///     .with_ignored_user_agents(vec!["CustomBot".to_string()]);
	/// ```
	pub fn with_ignored_user_agents(mut self, user_agents: Vec<String>) -> Self {
		self.ignored_user_agents.extend(user_agents);
		self
	}
}

impl Default for BrokenLinkConfig {
	fn default() -> Self {
		Self::new()
	}
}

/// Middleware for detecting broken internal links
///
/// Logs 404 errors that originate from internal referrers (same domain).
///
/// # Examples
///
/// ```
/// use std::sync::Arc;
/// use reinhardt_middleware::{BrokenLinkEmailsMiddleware, BrokenLinkConfig};
/// use reinhardt_http::{Handler, Middleware, Request, Response};
/// use hyper::{StatusCode, Method, Version, HeaderMap};
/// use bytes::Bytes;
///
/// struct NotFoundHandler;
///
/// #[async_trait::async_trait]
/// impl Handler for NotFoundHandler {
///     async fn handle(&self, _request: Request) -> reinhardt_core::exception::Result<Response> {
///         Ok(Response::new(StatusCode::NOT_FOUND))
///     }
/// }
///
/// # tokio_test::block_on(async {
/// let config = BrokenLinkConfig::new();
/// let middleware = BrokenLinkEmailsMiddleware::new(config);
/// let handler = Arc::new(NotFoundHandler);
///
/// let mut headers = HeaderMap::new();
/// headers.insert(hyper::header::REFERER, "http://example.com/page".parse().unwrap());
/// headers.insert(hyper::header::HOST, "example.com".parse().unwrap());
///
/// let request = Request::builder()
///     .method(Method::GET)
///     .uri("/missing")
///     .version(Version::HTTP_11)
///     .headers(headers)
///     .body(Bytes::new())
///     .build()
///     .unwrap();
///
/// let response = middleware.process(request, handler).await.unwrap();
/// assert_eq!(response.status, StatusCode::NOT_FOUND);
/// # });
/// ```
pub struct BrokenLinkEmailsMiddleware {
	config: BrokenLinkConfig,
	ignored_path_regexes: Vec<Regex>,
	ignored_ua_regexes: Vec<Regex>,
}

impl BrokenLinkEmailsMiddleware {
	/// Create a new BrokenLinkEmailsMiddleware with the given configuration
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_middleware::{BrokenLinkEmailsMiddleware, BrokenLinkConfig};
	///
	/// let config = BrokenLinkConfig::new();
	/// let middleware = BrokenLinkEmailsMiddleware::new(config);
	/// ```
	pub fn new(config: BrokenLinkConfig) -> Self {
		let ignored_path_regexes = config
			.ignored_paths
			.iter()
			.filter_map(|p| Regex::new(p).ok())
			.collect();

		let ignored_ua_regexes = config
			.ignored_user_agents
			.iter()
			.filter_map(|ua| Regex::new(&format!("(?i){}", ua)).ok())
			.collect();

		Self {
			config,
			ignored_path_regexes,
			ignored_ua_regexes,
		}
	}

	/// Create a `BrokenLinkEmailsMiddleware` from application `Settings`
	///
	/// This is the canonical entry point. Manager contacts from
	/// `Settings::managers` are resolved exactly once and stored on the
	/// middleware, eliminating per-request environment lookups.
	///
	/// # Examples
	///
	/// ```
	/// use reinhardt_conf::Settings;
	/// use reinhardt_middleware::BrokenLinkEmailsMiddleware;
	///
	/// #[allow(deprecated)]
	/// let settings = Settings::default();
	/// #[allow(deprecated)]
	/// let middleware = BrokenLinkEmailsMiddleware::from_settings(&settings);
	/// ```
	#[allow(deprecated)] // Settings is deprecated in favor of composable fragments
	pub fn from_settings(settings: &settings::Settings) -> Self {
		Self::new(BrokenLinkConfig::from_settings(settings))
	}

	/// Check if the path should be ignored
	fn is_ignored_path(&self, path: &str) -> bool {
		self.ignored_path_regexes.iter().any(|re| re.is_match(path))
	}

	/// Check if the user agent should be ignored
	fn is_ignored_user_agent(&self, user_agent: &str) -> bool {
		self.ignored_ua_regexes
			.iter()
			.any(|re| re.is_match(user_agent))
	}

	/// Extract domain from URL
	fn extract_domain(url: &str) -> Option<String> {
		if let Ok(parsed) = url::Url::parse(url) {
			parsed.host_str().map(|h| h.to_string())
		} else {
			None
		}
	}

	/// Check if the referrer is from the same domain (internal link)
	fn is_internal_referrer(&self, referer: &str, host: &str) -> bool {
		if let Some(referer_domain) = Self::extract_domain(referer) {
			// Normalize domains (remove www. prefix for comparison)
			let normalized_referer = referer_domain.trim_start_matches("www.");
			let normalized_host = host.trim_start_matches("www.");
			normalized_referer == normalized_host
		} else {
			false
		}
	}

	/// Log a broken link and send email notifications
	async fn log_broken_link(&self, path: &str, referer: &str) {
		// Log to standard logging system
		log::warn!("Broken link detected: {} (from: {})", path, referer);

		// Managers are resolved once at construction time via
		// `BrokenLinkConfig::from_settings`. When no settings were provided,
		// fall back to converting legacy `email_addresses` into anonymous
		// `Contact` entries so existing direct-construction callers continue
		// to receive notifications.
		let managers: Cow<'_, [settings::Contact]> = if !self.config.managers.is_empty() {
			Cow::Borrowed(&self.config.managers)
		} else {
			Cow::Owned(
				self.config
					.email_addresses
					.iter()
					.map(|email| settings::Contact::new("", email.clone()))
					.collect(),
			)
		};

		// Send email notifications to managers
		if !managers.is_empty() {
			let subject = format!("Broken link detected: {}", path);
			let body = format!(
				"A broken link was detected on your site:\n\n\
				 Broken URL: {}\n\
				 Referrer: {}\n\n\
				 Please check and fix this link.",
				path, referer
			);

			// Send to all managers asynchronously (non-blocking)
			for manager in managers.iter() {
				let email = manager.email.clone();
				let subject_clone = subject.clone();
				let body_clone = body.clone();

				// Schedule email sending in a separate task to avoid blocking
				// Note: Uses default SMTP config (localhost:25). Configure via SmtpConfig for production.
				tokio::spawn(async move {
					let config = reinhardt_mail::SmtpConfig::default();
					let backend = match reinhardt_mail::SmtpBackend::new(config) {
						Ok(backend) => backend,
						Err(e) => {
							log::error!(
								"Failed to create SMTP backend for broken link email: {}",
								e
							);
							return;
						}
					};
					match reinhardt_mail::send_mail_with_backend(
						subject_clone,
						body_clone,
						"noreply@example.com", // Default sender
						vec![email.clone()],
						None,
						&backend,
					)
					.await
					{
						Ok(_) => {
							log::info!("Broken link email notification sent to: {}", email);
						}
						Err(e) => {
							log::error!("Failed to send broken link email to {}: {}", email, e);
						}
					}
				});
			}
		}
	}
}

impl Default for BrokenLinkEmailsMiddleware {
	fn default() -> Self {
		Self::new(BrokenLinkConfig::default())
	}
}

#[async_trait]
impl Middleware for BrokenLinkEmailsMiddleware {
	async fn process(&self, request: Request, handler: Arc<dyn Handler>) -> Result<Response> {
		// Extract necessary information before moving request
		let path = request.uri.path().to_string();
		let referer = request
			.headers
			.get(REFERER)
			.and_then(|r| r.to_str().ok())
			.map(|s| s.to_string());
		let host = request
			.headers
			.get(hyper::header::HOST)
			.and_then(|h| h.to_str().ok())
			.map(|s| s.to_string());
		let user_agent = request
			.headers
			.get(USER_AGENT)
			.and_then(|ua| ua.to_str().ok())
			.map(|s| s.to_string());

		// Convert errors to responses so post-processing always runs,
		// even when invoked outside MiddlewareChain. (#3244)
		let response = match handler.handle(request).await {
			Ok(resp) => resp,
			Err(e) => Response::from(e),
		};

		// Check if we should process this request/response
		if !self.config.enabled || response.status != StatusCode::NOT_FOUND {
			return Ok(response);
		}

		// Check if path should be ignored
		if self.is_ignored_path(&path) {
			return Ok(response);
		}

		// Check if user agent should be ignored
		if let Some(ua) = user_agent
			&& self.is_ignored_user_agent(&ua)
		{
			return Ok(response);
		}

		// Check if there's a referrer and host
		if let (Some(referer_str), Some(host_str)) = (referer, host) {
			// Only log if it's an internal referrer
			if self.is_internal_referrer(&referer_str, &host_str) {
				self.log_broken_link(&path, &referer_str).await;
			}
		}

		Ok(response)
	}
}

#[cfg(test)]
mod tests {
	use super::*;
	use bytes::Bytes;
	use hyper::{HeaderMap, Method, StatusCode, Version};

	struct NotFoundHandler;

	#[async_trait]
	impl Handler for NotFoundHandler {
		async fn handle(&self, _request: Request) -> Result<Response> {
			Ok(Response::new(StatusCode::NOT_FOUND))
		}
	}

	struct OkHandler;

	#[async_trait]
	impl Handler for OkHandler {
		async fn handle(&self, _request: Request) -> Result<Response> {
			Ok(Response::new(StatusCode::OK).with_body(Bytes::from("OK")))
		}
	}

	#[tokio::test]
	async fn test_internal_404_detected() {
		let config = BrokenLinkConfig::new();
		let middleware = BrokenLinkEmailsMiddleware::new(config);
		let handler = Arc::new(NotFoundHandler);

		let mut headers = HeaderMap::new();
		headers.insert(REFERER, "http://example.com/page".parse().unwrap());
		headers.insert(hyper::header::HOST, "example.com".parse().unwrap());

		let request = Request::builder()
			.method(Method::GET)
			.uri("/missing")
			.version(Version::HTTP_11)
			.headers(headers)
			.body(Bytes::new())
			.build()
			.unwrap();

		let response = middleware.process(request, handler).await.unwrap();

		assert_eq!(response.status, StatusCode::NOT_FOUND);
		// In a real scenario, we'd check logs or email was sent
	}

	#[tokio::test]
	async fn test_external_404_ignored() {
		let config = BrokenLinkConfig::new();
		let middleware = BrokenLinkEmailsMiddleware::new(config);
		let handler = Arc::new(NotFoundHandler);

		let mut headers = HeaderMap::new();
		headers.insert(REFERER, "http://external.com/page".parse().unwrap());
		headers.insert(hyper::header::HOST, "example.com".parse().unwrap());

		let request = Request::builder()
			.method(Method::GET)
			.uri("/missing")
			.version(Version::HTTP_11)
			.headers(headers)
			.body(Bytes::new())
			.build()
			.unwrap();

		let response = middleware.process(request, handler).await.unwrap();

		assert_eq!(response.status, StatusCode::NOT_FOUND);
		// External referrer should not trigger detection
	}

	#[tokio::test]
	async fn test_no_referrer_ignored() {
		let config = BrokenLinkConfig::new();
		let middleware = BrokenLinkEmailsMiddleware::new(config);
		let handler = Arc::new(NotFoundHandler);

		let mut headers = HeaderMap::new();
		headers.insert(hyper::header::HOST, "example.com".parse().unwrap());

		let request = Request::builder()
			.method(Method::GET)
			.uri("/missing")
			.version(Version::HTTP_11)
			.headers(headers)
			.body(Bytes::new())
			.build()
			.unwrap();

		let response = middleware.process(request, handler).await.unwrap();

		assert_eq!(response.status, StatusCode::NOT_FOUND);
		// No referrer should not trigger detection
	}

	#[tokio::test]
	async fn test_ignored_path() {
		let config = BrokenLinkConfig::new();
		let middleware = BrokenLinkEmailsMiddleware::new(config);
		let handler = Arc::new(NotFoundHandler);

		let mut headers = HeaderMap::new();
		headers.insert(REFERER, "http://example.com/page".parse().unwrap());
		headers.insert(hyper::header::HOST, "example.com".parse().unwrap());

		let request = Request::builder()
			.method(Method::GET)
			.uri("/favicon.ico")
			.version(Version::HTTP_11)
			.headers(headers)
			.body(Bytes::new())
			.build()
			.unwrap();

		let response = middleware.process(request, handler).await.unwrap();

		assert_eq!(response.status, StatusCode::NOT_FOUND);
		// favicon.ico is in ignored paths
	}

	#[tokio::test]
	async fn test_ignored_user_agent() {
		let config = BrokenLinkConfig::new();
		let middleware = BrokenLinkEmailsMiddleware::new(config);
		let handler = Arc::new(NotFoundHandler);

		let mut headers = HeaderMap::new();
		headers.insert(REFERER, "http://example.com/page".parse().unwrap());
		headers.insert(hyper::header::HOST, "example.com".parse().unwrap());
		headers.insert(USER_AGENT, "Googlebot/2.1".parse().unwrap());

		let request = Request::builder()
			.method(Method::GET)
			.uri("/missing")
			.version(Version::HTTP_11)
			.headers(headers)
			.body(Bytes::new())
			.build()
			.unwrap();

		let response = middleware.process(request, handler).await.unwrap();

		assert_eq!(response.status, StatusCode::NOT_FOUND);
		// Bot user agents should be ignored
	}

	#[tokio::test]
	async fn test_200_response_ignored() {
		let config = BrokenLinkConfig::new();
		let middleware = BrokenLinkEmailsMiddleware::new(config);
		let handler = Arc::new(OkHandler);

		let mut headers = HeaderMap::new();
		headers.insert(REFERER, "http://example.com/page".parse().unwrap());
		headers.insert(hyper::header::HOST, "example.com".parse().unwrap());

		let request = Request::builder()
			.method(Method::GET)
			.uri("/existing")
			.version(Version::HTTP_11)
			.headers(headers)
			.body(Bytes::new())
			.build()
			.unwrap();

		let response = middleware.process(request, handler).await.unwrap();

		assert_eq!(response.status, StatusCode::OK);
		// 200 responses should not trigger detection
	}

	#[tokio::test]
	async fn test_www_subdomain_handling() {
		let config = BrokenLinkConfig::new();
		let middleware = BrokenLinkEmailsMiddleware::new(config);
		let handler = Arc::new(NotFoundHandler);

		let mut headers = HeaderMap::new();
		headers.insert(REFERER, "http://www.example.com/page".parse().unwrap());
		headers.insert(hyper::header::HOST, "example.com".parse().unwrap());

		let request = Request::builder()
			.method(Method::GET)
			.uri("/missing")
			.version(Version::HTTP_11)
			.headers(headers)
			.body(Bytes::new())
			.build()
			.unwrap();

		let response = middleware.process(request, handler).await.unwrap();

		assert_eq!(response.status, StatusCode::NOT_FOUND);
		// www.example.com should be treated as same domain as example.com
	}

	#[tokio::test]
	async fn test_disabled_config() {
		let config = BrokenLinkConfig::new().disabled();
		let middleware = BrokenLinkEmailsMiddleware::new(config);
		let handler = Arc::new(NotFoundHandler);

		let mut headers = HeaderMap::new();
		headers.insert(REFERER, "http://example.com/page".parse().unwrap());
		headers.insert(hyper::header::HOST, "example.com".parse().unwrap());

		let request = Request::builder()
			.method(Method::GET)
			.uri("/missing")
			.version(Version::HTTP_11)
			.headers(headers)
			.body(Bytes::new())
			.build()
			.unwrap();

		let response = middleware.process(request, handler).await.unwrap();

		assert_eq!(response.status, StatusCode::NOT_FOUND);
		// Disabled config should not trigger detection
	}

	#[tokio::test]
	async fn test_custom_ignored_paths() {
		let config = BrokenLinkConfig::new().with_ignored_paths(vec!["/admin/.*".to_string()]);
		let middleware = BrokenLinkEmailsMiddleware::new(config);
		let handler = Arc::new(NotFoundHandler);

		let mut headers = HeaderMap::new();
		headers.insert(REFERER, "http://example.com/page".parse().unwrap());
		headers.insert(hyper::header::HOST, "example.com".parse().unwrap());

		let request = Request::builder()
			.method(Method::GET)
			.uri("/admin/missing")
			.version(Version::HTTP_11)
			.headers(headers)
			.body(Bytes::new())
			.build()
			.unwrap();

		let response = middleware.process(request, handler).await.unwrap();

		assert_eq!(response.status, StatusCode::NOT_FOUND);
		// Custom ignored paths should work
	}

	#[tokio::test]
	async fn test_email_configuration() {
		let config = BrokenLinkConfig::new().with_emails(vec!["admin@example.com".to_string()]);
		let middleware = BrokenLinkEmailsMiddleware::new(config);

		assert_eq!(middleware.config.email_addresses.len(), 1);
		assert_eq!(middleware.config.email_addresses[0], "admin@example.com");
	}
}