reinhardt-openapi 0.1.0

OpenAPI router wrapper for Reinhardt framework
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
//! Router wrapper that adds OpenAPI documentation endpoints
//!
//! This module provides a wrapper around any `Handler` implementation that
//! automatically serves OpenAPI documentation endpoints without modifying
//! user code.
//!
//! # Example
//!
//! ```rust,ignore
//! use reinhardt_openapi::OpenApiRouter;
//! use reinhardt_urls::routers::BasicRouter;
//!
//! fn main() {
//!     // Create your existing router
//!     let router = BasicRouter::new();
//!
//!     // Wrap with OpenAPI endpoints
//!     let wrapped = OpenApiRouter::wrap(router)?;
//!
//!     // The wrapped router now serves:
//!     // - /api/openapi.json (OpenAPI spec)
//!     // - /api/docs (Swagger UI)
//!     // - /api/redoc (Redoc UI)
//! }
//! ```

use async_trait::async_trait;
use reinhardt_http::Handler;
use reinhardt_http::{Request, Response, Result};
use reinhardt_rest::openapi::endpoints::generate_openapi_schema;
use reinhardt_rest::openapi::{RedocUI, SwaggerUI};
use reinhardt_urls::prelude::Route;
use reinhardt_urls::routers::Router;
use std::sync::Arc;

/// Type alias for the authentication guard callback.
///
/// The guard receives a reference to the incoming request and returns
/// `true` if the request is authorized to access documentation endpoints,
/// or `false` to deny access with HTTP 403 Forbidden.
// Fixes #828
pub type AuthGuard = Arc<dyn Fn(&Request) -> bool + Send + Sync>;

/// Router wrapper that adds OpenAPI documentation endpoints
///
/// This wrapper intercepts requests to OpenAPI documentation paths and
/// serves them from memory, delegating all other requests to the wrapped
/// handler.
///
/// The OpenAPI schema is generated once at wrap time from the global
/// schema registry, ensuring minimal runtime overhead.
///
/// Access control is supported via the `enabled` flag and an optional
/// authentication guard callback. When `enabled` is `false`, all
/// documentation endpoints return HTTP 404. When an auth guard is set
/// and returns `false`, endpoints return HTTP 403.
pub struct OpenApiRouter<H> {
	/// Base handler to delegate to
	inner: H,
	/// Pre-generated OpenAPI JSON schema
	openapi_json: Arc<String>,
	/// Swagger UI HTML
	swagger_html: Arc<String>,
	/// Redoc UI HTML
	redoc_html: Arc<String>,
	/// Whether documentation endpoints are enabled (default: true)
	// Fixes #828
	enabled: bool,
	/// Optional authentication guard for documentation endpoints
	// Fixes #828
	auth_guard: Option<AuthGuard>,
}

impl<H> OpenApiRouter<H> {
	/// Wrap an existing handler with OpenAPI endpoints
	///
	/// This generates the OpenAPI schema from the global registry and
	/// pre-renders the Swagger and Redoc UIs.
	///
	/// # Example
	///
	/// ```rust,ignore
	/// use reinhardt_openapi::OpenApiRouter;
	/// use reinhardt_urls::routers::BasicRouter;
	///
	/// let router = BasicRouter::new();
	/// let wrapped = OpenApiRouter::wrap(router)?;
	/// # Ok::<(), reinhardt_rest::openapi::SchemaError>(())
	/// ```
	pub fn wrap(handler: H) -> std::result::Result<Self, reinhardt_rest::openapi::SchemaError> {
		// Generate OpenAPI schema from global registry
		let schema = generate_openapi_schema();
		let openapi_json = serde_json::to_string_pretty(&schema)?;

		// Generate Swagger UI HTML
		let swagger_ui = SwaggerUI::new(schema.clone());
		let swagger_html = swagger_ui.render_html()?;

		// Generate Redoc UI HTML
		let redoc_ui = RedocUI::new(schema);
		let redoc_html = redoc_ui.render_html()?;

		Ok(Self {
			inner: handler,
			openapi_json: Arc::new(openapi_json),
			swagger_html: Arc::new(swagger_html),
			redoc_html: Arc::new(redoc_html),
			enabled: true,
			auth_guard: None,
		})
	}

	/// Set whether documentation endpoints are enabled
	///
	/// When set to `false`, all documentation endpoints (`/api/openapi.json`,
	/// `/api/docs`, `/api/redoc`) will return HTTP 404 Not Found.
	///
	/// Default is `true`.
	///
	/// # Example
	///
	/// ```rust,ignore
	/// use reinhardt_openapi::OpenApiRouter;
	/// use reinhardt_urls::routers::BasicRouter;
	///
	/// let router = BasicRouter::new();
	/// let wrapped = OpenApiRouter::wrap(router)?.enabled(false);
	/// ```
	// Fixes #828
	pub fn enabled(mut self, enabled: bool) -> Self {
		self.enabled = enabled;
		self
	}

	/// Set an authentication guard for documentation endpoints
	///
	/// The guard function receives a reference to the incoming request and
	/// should return `true` to allow access or `false` to deny with HTTP 403
	/// Forbidden.
	///
	/// The guard is only checked when `enabled` is `true`. When `enabled` is
	/// `false`, endpoints return 404 regardless of the guard.
	///
	/// # Example
	///
	/// ```rust,ignore
	/// use reinhardt_openapi::OpenApiRouter;
	/// use reinhardt_urls::routers::BasicRouter;
	///
	/// let router = BasicRouter::new();
	/// let wrapped = OpenApiRouter::wrap(router)?.auth_guard(|request| {
	///     // Check for API key in header
	///     request.headers().get("X-Api-Key")
	///         .map(|v| v == "secret")
	///         .unwrap_or(false)
	/// });
	/// ```
	// Fixes #828
	pub fn auth_guard(mut self, guard: impl Fn(&Request) -> bool + Send + Sync + 'static) -> Self {
		self.auth_guard = Some(Arc::new(guard));
		self
	}

	/// Get a reference to the wrapped handler
	pub fn inner(&self) -> &H {
		&self.inner
	}

	/// Check access control for documentation endpoints.
	///
	/// Returns `None` if access is allowed, or `Some(Response)` with the
	/// appropriate error status if access is denied.
	// Fixes #828
	fn check_access(&self, request: &Request) -> Option<Response> {
		if !self.enabled {
			return Some(Response::not_found());
		}
		if let Some(ref guard) = self.auth_guard
			&& !guard(request)
		{
			return Some(Response::forbidden());
		}
		None
	}

	/// Try to serve an OpenAPI documentation endpoint.
	///
	/// Returns `Some(Ok(Response))` if the request path matches an OpenAPI
	/// endpoint and access control checks pass, `Some(Ok(denied))` if access
	/// is denied, or `None` if the path does not match any documentation
	/// endpoint.
	///
	/// Fixes #831: Deduplicate route handling between Handler and Router.
	fn try_serve_openapi(&self, request: &Request) -> Option<Result<Response>> {
		match request.uri.path() {
			"/api/openapi.json" | "/api/docs" | "/api/redoc" => {
				if let Some(denied) = self.check_access(request) {
					return Some(Ok(denied));
				}
				let response = match request.uri.path() {
					"/api/openapi.json" => {
						let json = (*self.openapi_json).clone();
						Response::ok()
							.with_header("Content-Type", "application/json; charset=utf-8")
							.with_body(json)
					}
					"/api/docs" => {
						let html = (*self.swagger_html).clone();
						Response::ok()
							.with_header("Content-Type", "text/html; charset=utf-8")
							.with_body(html)
					}
					"/api/redoc" => {
						let html = (*self.redoc_html).clone();
						Response::ok()
							.with_header("Content-Type", "text/html; charset=utf-8")
							.with_body(html)
					}
					_ => unreachable!(),
				};
				Some(Ok(Self::apply_security_headers(response)))
			}
			_ => None,
		}
	}

	/// Apply security headers to documentation endpoint responses.
	///
	/// Adds Content-Security-Policy, X-Frame-Options, X-Content-Type-Options,
	/// and Cache-Control headers to prevent clickjacking, MIME sniffing,
	/// and stale cache attacks on documentation pages.
	// Fixes #830
	fn apply_security_headers(response: Response) -> Response {
		response
			.with_header(
				"Content-Security-Policy",
				"default-src 'none'; \
				 script-src 'unsafe-inline' https://unpkg.com https://cdn.redoc.ly; \
				 style-src 'unsafe-inline' https://unpkg.com; \
				 img-src 'self' data:; \
				 connect-src 'self'; \
				 font-src https://fonts.gstatic.com; \
				 frame-ancestors 'none'",
			)
			.with_header("X-Frame-Options", "DENY")
			.with_header("X-Content-Type-Options", "nosniff")
			.with_header("Cache-Control", "no-store")
	}
}

#[async_trait]
impl<H: Handler> Handler for OpenApiRouter<H> {
	/// Handle requests, intercepting OpenAPI documentation paths
	///
	/// Requests to `/api/openapi.json`, `/api/docs`, or `/api/redoc`
	/// are served from memory if access control checks pass. All other
	/// requests are delegated to the wrapped handler.
	///
	/// Access control is enforced via the `enabled` flag and optional
	/// auth guard. Disabled endpoints return 404, unauthorized requests
	/// return 403.
	async fn handle(&self, request: Request) -> Result<Response> {
		// Fixes #831: Use shared OpenAPI serving logic
		if let Some(response) = self.try_serve_openapi(&request) {
			return response;
		}
		self.inner.handle(request).await
	}
}

/// Router trait implementation for OpenApiRouter
///
/// This implementation allows OpenApiRouter to be used where Router trait
/// is required. However, routes cannot be modified after wrapping - use
/// `add_route()` and `include()` on the base router before wrapping.
impl<H> Router for OpenApiRouter<H>
where
	H: Handler + Router,
{
	/// Add a route to the router
	///
	/// # Panics
	///
	/// This method always panics. Routes must be added to the base router
	/// before wrapping with `OpenApiRouter::wrap()`.
	fn add_route(&mut self, _route: Route) {
		panic!(
			"Cannot add routes to OpenApiRouter after wrapping. \
             Add routes to the base router before calling OpenApiRouter::wrap()."
		);
	}

	/// Include routes with a prefix
	///
	/// # Panics
	///
	/// This method always panics. Routes must be mounted in the base router
	/// before wrapping with `OpenApiRouter::wrap()`.
	fn mount(&mut self, _prefix: &str, _routes: Vec<Route>, _namespace: Option<String>) {
		panic!(
			"Cannot mount routes in OpenApiRouter after wrapping. \
             Mount routes in the base router before calling OpenApiRouter::wrap()."
		);
	}

	/// Route a request through the OpenAPI wrapper
	///
	/// OpenAPI documentation endpoints (`/api/openapi.json`, `/api/docs`,
	/// `/api/redoc`) are handled directly if access control checks pass.
	/// All other requests are delegated to the wrapped router's `route()`
	/// method.
	///
	/// Access control is enforced via the `enabled` flag and optional
	/// auth guard. Disabled endpoints return 404, unauthorized requests
	/// return 403.
	async fn route(&self, request: Request) -> Result<Response> {
		// Fixes #831: Use shared OpenAPI serving logic
		if let Some(response) = self.try_serve_openapi(&request) {
			return response;
		}
		self.inner.route(request).await
	}
}

#[cfg(test)]
mod tests {
	use super::*;
	use hyper::StatusCode;
	use rstest::rstest;

	struct DummyHandler;

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

	#[rstest]
	#[tokio::test]
	async fn test_openapi_json_endpoint() {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap();

		// Act
		let request = Request::builder().uri("/api/openapi.json").build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert
		assert_eq!(response.status, StatusCode::OK);
		let body_str = String::from_utf8(response.body.to_vec()).unwrap();
		assert!(body_str.contains("openapi"));
		assert!(body_str.contains("3.")); // OpenAPI version (3.0 or 3.1)
	}

	#[rstest]
	#[tokio::test]
	async fn test_swagger_docs_endpoint() {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap();

		// Act
		let request = Request::builder().uri("/api/docs").build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert
		assert_eq!(response.status, StatusCode::OK);
		let body_str = String::from_utf8(response.body.to_vec()).unwrap();
		assert!(body_str.contains("swagger-ui"));
	}

	#[rstest]
	#[tokio::test]
	async fn test_redoc_docs_endpoint() {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap();

		// Act
		let request = Request::builder().uri("/api/redoc").build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert
		assert_eq!(response.status, StatusCode::OK);
		let body_str = String::from_utf8(response.body.to_vec()).unwrap();
		assert!(body_str.contains("redoc"));
	}

	#[rstest]
	#[tokio::test]
	async fn test_delegation_to_inner_handler() {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap();

		// Act
		let request = Request::builder().uri("/some/other/path").build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert
		assert_eq!(response.status, StatusCode::OK);
		let body_str = String::from_utf8(response.body.to_vec()).unwrap();
		assert_eq!(body_str, "Hello from inner handler");
	}

	// Fixes #828: Access control tests

	#[rstest]
	#[case("/api/openapi.json")]
	#[case("/api/docs")]
	#[case("/api/redoc")]
	#[tokio::test]
	async fn test_disabled_endpoints_return_404(#[case] path: &str) {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap().enabled(false);

		// Act
		let request = Request::builder().uri(path).build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert
		assert_eq!(response.status, StatusCode::NOT_FOUND);
	}

	#[rstest]
	#[tokio::test]
	async fn test_disabled_does_not_affect_other_routes() {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap().enabled(false);

		// Act
		let request = Request::builder().uri("/some/other/path").build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert
		assert_eq!(response.status, StatusCode::OK);
		let body_str = String::from_utf8(response.body.to_vec()).unwrap();
		assert_eq!(body_str, "Hello from inner handler");
	}

	#[rstest]
	#[case("/api/openapi.json")]
	#[case("/api/docs")]
	#[case("/api/redoc")]
	#[tokio::test]
	async fn test_auth_guard_rejects_unauthorized(#[case] path: &str) {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler)
			.unwrap()
			.auth_guard(|_request| false);

		// Act
		let request = Request::builder().uri(path).build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert
		assert_eq!(response.status, StatusCode::FORBIDDEN);
	}

	#[rstest]
	#[case("/api/openapi.json")]
	#[case("/api/docs")]
	#[case("/api/redoc")]
	#[tokio::test]
	async fn test_auth_guard_allows_authorized(#[case] path: &str) {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler)
			.unwrap()
			.auth_guard(|_request| true);

		// Act
		let request = Request::builder().uri(path).build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert
		assert_eq!(response.status, StatusCode::OK);
	}

	#[rstest]
	#[tokio::test]
	async fn test_auth_guard_does_not_affect_other_routes() {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler)
			.unwrap()
			.auth_guard(|_request| false);

		// Act
		let request = Request::builder().uri("/some/other/path").build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert
		assert_eq!(response.status, StatusCode::OK);
		let body_str = String::from_utf8(response.body.to_vec()).unwrap();
		assert_eq!(body_str, "Hello from inner handler");
	}

	#[rstest]
	#[case("/api/openapi.json")]
	#[case("/api/docs")]
	#[case("/api/redoc")]
	#[tokio::test]
	async fn test_disabled_takes_precedence_over_auth_guard(#[case] path: &str) {
		// Arrange: enabled=false should return 404 even with a passing auth guard
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler)
			.unwrap()
			.enabled(false)
			.auth_guard(|_request| true);

		// Act
		let request = Request::builder().uri(path).build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert: Should be 404 (disabled), not 200 (auth passed)
		assert_eq!(response.status, StatusCode::NOT_FOUND);
	}

	#[rstest]
	#[tokio::test]
	async fn test_openapi_json_response_body_is_valid_openapi_json() {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap();

		// Act
		let request = Request::builder().uri("/api/openapi.json").build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert: body is valid JSON with an openapi version field starting with "3."
		assert_eq!(response.status, StatusCode::OK);
		let body_bytes = response.body.to_vec();
		let json: serde_json::Value =
			serde_json::from_slice(&body_bytes).expect("Response body should be valid JSON");
		let openapi_version = json["openapi"]
			.as_str()
			.expect("JSON should have an 'openapi' string field");
		assert!(
			openapi_version.starts_with("3."),
			"openapi field should start with '3.', got: {}",
			openapi_version
		);
	}

	#[rstest]
	#[tokio::test]
	async fn test_openapi_json_response_content_type_header() {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap();

		// Act
		let request = Request::builder().uri("/api/openapi.json").build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert: Content-Type header contains application/json
		assert_eq!(response.status, StatusCode::OK);
		let content_type = response
			.headers
			.get("Content-Type")
			.and_then(|v| v.to_str().ok())
			.unwrap_or("");
		assert!(
			content_type.contains("application/json"),
			"Content-Type should contain 'application/json', got: {}",
			content_type
		);
	}

	#[rstest]
	#[tokio::test]
	async fn test_swagger_docs_response_body_contains_swagger_ui_marker() {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap();

		// Act
		let request = Request::builder().uri("/api/docs").build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert: HTML body contains the swagger-ui marker
		assert_eq!(response.status, StatusCode::OK);
		let body_str = String::from_utf8(response.body.to_vec()).unwrap();
		assert!(
			body_str.contains("swagger-ui"),
			"Swagger docs HTML should contain 'swagger-ui'"
		);
	}

	#[rstest]
	#[tokio::test]
	async fn test_redoc_docs_response_body_contains_redoc_marker() {
		// Arrange
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap();

		// Act
		let request = Request::builder().uri("/api/redoc").build().unwrap();
		let response = wrapped.handle(request).await.unwrap();

		// Assert: HTML body contains the redoc marker (case-insensitive)
		assert_eq!(response.status, StatusCode::OK);
		let body_str = String::from_utf8(response.body.to_vec())
			.unwrap()
			.to_lowercase();
		assert!(
			body_str.contains("redoc"),
			"Redoc docs HTML should contain 'redoc' (case-insensitive)"
		);
	}

	#[rstest]
	#[tokio::test]
	async fn test_auth_guard_inspects_request_headers() {
		// Arrange: Guard checks for a specific header value
		let handler = DummyHandler;
		let wrapped = OpenApiRouter::wrap(handler).unwrap().auth_guard(|request| {
			request
				.headers
				.get("X-Docs-Token")
				.and_then(|v| v.to_str().ok())
				.map(|v| v == "valid-token")
				.unwrap_or(false)
		});

		// Act: Request without token
		let request_no_token = Request::builder().uri("/api/docs").build().unwrap();
		let response_no_token = wrapped.handle(request_no_token).await.unwrap();

		// Assert: Should be forbidden
		assert_eq!(response_no_token.status, StatusCode::FORBIDDEN);

		// Act: Request with valid token
		let request_valid = Request::builder()
			.uri("/api/docs")
			.header("X-Docs-Token", "valid-token")
			.build()
			.unwrap();
		let response_valid = wrapped.handle(request_valid).await.unwrap();

		// Assert: Should be OK
		assert_eq!(response_valid.status, StatusCode::OK);

		// Act: Request with invalid token
		let request_invalid = Request::builder()
			.uri("/api/docs")
			.header("X-Docs-Token", "wrong-token")
			.build()
			.unwrap();
		let response_invalid = wrapped.handle(request_invalid).await.unwrap();

		// Assert: Should be forbidden
		assert_eq!(response_invalid.status, StatusCode::FORBIDDEN);
	}
}