actix-security-core 0.2.3

Spring Security-like authentication and authorization for Actix Web - Core library
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
704
705
706
//! Security headers middleware for HTTP security.
//!
//! # Spring Security Equivalent
//! `HttpSecurity.headers()` configuration
//!
//! # Overview
//! Adds security-related HTTP headers to responses:
//!
//! - `X-Content-Type-Options: nosniff` - Prevents MIME-sniffing
//! - `X-Frame-Options: DENY` - Prevents clickjacking
//! - `X-XSS-Protection: 0` - Disables XSS Auditor (deprecated but safe)
//! - `Strict-Transport-Security` - Forces HTTPS (HSTS)
//! - `Content-Security-Policy` - Controls resource loading
//! - `Referrer-Policy` - Controls referrer information
//! - `Permissions-Policy` - Controls browser features
//!
//! # Usage
//! ```ignore
//! use actix_web::{App, HttpServer};
//! use actix_security_core::http::security::headers::SecurityHeaders;
//!
//! HttpServer::new(|| {
//!     App::new()
//!         .wrap(SecurityHeaders::default())
//!         // ... routes
//! })
//! ```

use std::future::{ready, Future, Ready};
use std::pin::Pin;
use std::rc::Rc;
use std::task::{Context, Poll};

use actix_service::{Service, Transform};
use actix_web::dev::{ServiceRequest, ServiceResponse};
use actix_web::http::header::{HeaderName, HeaderValue};
use actix_web::Error;

/// Frame options for X-Frame-Options header.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FrameOptions {
    /// Prevents the page from being framed entirely.
    Deny,
    /// Allows framing by the same origin only.
    SameOrigin,
    /// Disables X-Frame-Options header.
    Disabled,
}

impl FrameOptions {
    fn to_header_value(&self) -> Option<&'static str> {
        match self {
            FrameOptions::Deny => Some("DENY"),
            FrameOptions::SameOrigin => Some("SAMEORIGIN"),
            FrameOptions::Disabled => None,
        }
    }
}

/// Referrer policy options.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ReferrerPolicy {
    NoReferrer,
    NoReferrerWhenDowngrade,
    Origin,
    OriginWhenCrossOrigin,
    SameOrigin,
    StrictOrigin,
    StrictOriginWhenCrossOrigin,
    UnsafeUrl,
    Disabled,
}

impl ReferrerPolicy {
    fn to_header_value(&self) -> Option<&'static str> {
        match self {
            ReferrerPolicy::NoReferrer => Some("no-referrer"),
            ReferrerPolicy::NoReferrerWhenDowngrade => Some("no-referrer-when-downgrade"),
            ReferrerPolicy::Origin => Some("origin"),
            ReferrerPolicy::OriginWhenCrossOrigin => Some("origin-when-cross-origin"),
            ReferrerPolicy::SameOrigin => Some("same-origin"),
            ReferrerPolicy::StrictOrigin => Some("strict-origin"),
            ReferrerPolicy::StrictOriginWhenCrossOrigin => Some("strict-origin-when-cross-origin"),
            ReferrerPolicy::UnsafeUrl => Some("unsafe-url"),
            ReferrerPolicy::Disabled => None,
        }
    }
}

/// Security headers configuration.
///
/// # Spring Security Equivalent
/// `HttpSecurity.headers()`
///
/// # Example
/// ```ignore
/// use actix_security_core::http::security::headers::{SecurityHeaders, FrameOptions};
///
/// let headers = SecurityHeaders::new()
///     .frame_options(FrameOptions::SameOrigin)
///     .content_security_policy("default-src 'self'")
///     .hsts(true, 31536000); // 1 year
/// ```
#[derive(Debug, Clone)]
pub struct SecurityHeaders {
    /// X-Content-Type-Options header (default: nosniff)
    pub content_type_options: bool,
    /// X-Frame-Options header (default: DENY)
    pub frame_options: FrameOptions,
    /// X-XSS-Protection header (default: 0)
    pub xss_protection: bool,
    /// Content-Security-Policy header (default: None)
    pub content_security_policy: Option<String>,
    /// Strict-Transport-Security header (default: disabled)
    pub hsts_enabled: bool,
    /// HSTS max-age in seconds (default: 31536000 = 1 year)
    pub hsts_max_age: u64,
    /// HSTS include subdomains (default: false)
    pub hsts_include_subdomains: bool,
    /// HSTS preload (default: false)
    pub hsts_preload: bool,
    /// Referrer-Policy header (default: strict-origin-when-cross-origin)
    pub referrer_policy: ReferrerPolicy,
    /// Permissions-Policy header (default: None)
    pub permissions_policy: Option<String>,
    /// Cache-Control header for sensitive content (default: None)
    pub cache_control: Option<String>,
}

impl Default for SecurityHeaders {
    /// Creates security headers with sensible defaults.
    ///
    /// # Default Values
    /// - `X-Content-Type-Options: nosniff`
    /// - `X-Frame-Options: DENY`
    /// - `X-XSS-Protection: 0` (disabled as recommended)
    /// - `Referrer-Policy: strict-origin-when-cross-origin`
    fn default() -> Self {
        SecurityHeaders {
            content_type_options: true,
            frame_options: FrameOptions::Deny,
            xss_protection: false, // XSS Auditor is deprecated
            content_security_policy: None,
            hsts_enabled: false,
            hsts_max_age: 31536000, // 1 year
            hsts_include_subdomains: false,
            hsts_preload: false,
            referrer_policy: ReferrerPolicy::StrictOriginWhenCrossOrigin,
            permissions_policy: None,
            cache_control: None,
        }
    }
}

impl SecurityHeaders {
    /// Creates a new security headers configuration with defaults.
    pub fn new() -> Self {
        Self::default()
    }

    /// Creates a strict security headers configuration.
    ///
    /// Enables all security headers with strict values.
    pub fn strict() -> Self {
        SecurityHeaders {
            content_type_options: true,
            frame_options: FrameOptions::Deny,
            xss_protection: false,
            content_security_policy: Some("default-src 'self'".to_string()),
            hsts_enabled: true,
            hsts_max_age: 31536000,
            hsts_include_subdomains: true,
            hsts_preload: false,
            referrer_policy: ReferrerPolicy::NoReferrer,
            permissions_policy: Some("geolocation=(), microphone=(), camera=()".to_string()),
            cache_control: Some("no-cache, no-store, must-revalidate".to_string()),
        }
    }

    /// Sets the X-Frame-Options header.
    ///
    /// # Spring Security Equivalent
    /// `headers().frameOptions().deny()` or `.sameOrigin()`
    pub fn frame_options(mut self, options: FrameOptions) -> Self {
        self.frame_options = options;
        self
    }

    /// Sets the Content-Security-Policy header.
    ///
    /// # Spring Security Equivalent
    /// `headers().contentSecurityPolicy("policy")`
    ///
    /// # Example
    /// ```ignore
    /// let headers = SecurityHeaders::new()
    ///     .content_security_policy("default-src 'self'; script-src 'self' 'unsafe-inline'");
    /// ```
    pub fn content_security_policy(mut self, policy: impl Into<String>) -> Self {
        self.content_security_policy = Some(policy.into());
        self
    }

    /// Enables HTTP Strict Transport Security (HSTS).
    ///
    /// # Spring Security Equivalent
    /// `headers().httpStrictTransportSecurity()`
    ///
    /// # Arguments
    /// * `enabled` - Whether to enable HSTS
    /// * `max_age` - Max-age value in seconds
    pub fn hsts(mut self, enabled: bool, max_age: u64) -> Self {
        self.hsts_enabled = enabled;
        self.hsts_max_age = max_age;
        self
    }

    /// Sets HSTS to include subdomains.
    pub fn hsts_include_subdomains(mut self, include: bool) -> Self {
        self.hsts_include_subdomains = include;
        self
    }

    /// Sets HSTS preload flag.
    ///
    /// # Warning
    /// Only enable this if you've submitted your domain to the HSTS preload list.
    pub fn hsts_preload(mut self, preload: bool) -> Self {
        self.hsts_preload = preload;
        self
    }

    /// Sets the Referrer-Policy header.
    ///
    /// # Spring Security Equivalent
    /// `headers().referrerPolicy(ReferrerPolicy.STRICT_ORIGIN)`
    pub fn referrer_policy(mut self, policy: ReferrerPolicy) -> Self {
        self.referrer_policy = policy;
        self
    }

    /// Sets the Permissions-Policy header.
    ///
    /// # Example
    /// ```ignore
    /// let headers = SecurityHeaders::new()
    ///     .permissions_policy("geolocation=(), microphone=(), camera=()");
    /// ```
    pub fn permissions_policy(mut self, policy: impl Into<String>) -> Self {
        self.permissions_policy = Some(policy.into());
        self
    }

    /// Sets the Cache-Control header for sensitive content.
    pub fn cache_control(mut self, value: impl Into<String>) -> Self {
        self.cache_control = Some(value.into());
        self
    }

    /// Disables X-Content-Type-Options header.
    pub fn disable_content_type_options(mut self) -> Self {
        self.content_type_options = false;
        self
    }

    fn build_hsts_value(&self) -> String {
        let mut value = format!("max-age={}", self.hsts_max_age);
        if self.hsts_include_subdomains {
            value.push_str("; includeSubDomains");
        }
        if self.hsts_preload {
            value.push_str("; preload");
        }
        value
    }
}

impl<S, B> Transform<S, ServiceRequest> for SecurityHeaders
where
    S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
    B: 'static,
{
    type Response = ServiceResponse<B>;
    type Error = Error;
    type Transform = SecurityHeadersMiddleware<S>;
    type InitError = ();
    type Future = Ready<Result<Self::Transform, Self::InitError>>;

    fn new_transform(&self, service: S) -> Self::Future {
        ready(Ok(SecurityHeadersMiddleware {
            service: Rc::new(service),
            config: self.clone(),
        }))
    }
}

/// Security headers middleware service.
pub struct SecurityHeadersMiddleware<S> {
    service: Rc<S>,
    config: SecurityHeaders,
}

impl<S, B> Service<ServiceRequest> for SecurityHeadersMiddleware<S>
where
    S: Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> + 'static,
    B: 'static,
{
    type Response = ServiceResponse<B>;
    type Error = Error;
    type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;

    fn poll_ready(&self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
        self.service.poll_ready(ctx)
    }

    fn call(&self, req: ServiceRequest) -> Self::Future {
        let service = Rc::clone(&self.service);
        let config = self.config.clone();

        Box::pin(async move {
            let mut response = service.call(req).await?;

            let headers = response.headers_mut();

            // X-Content-Type-Options
            if config.content_type_options {
                headers.insert(
                    HeaderName::from_static("x-content-type-options"),
                    HeaderValue::from_static("nosniff"),
                );
            }

            // X-Frame-Options
            if let Some(value) = config.frame_options.to_header_value() {
                headers.insert(
                    HeaderName::from_static("x-frame-options"),
                    HeaderValue::from_static(value),
                );
            }

            // X-XSS-Protection (disabled by default, set to 0)
            headers.insert(
                HeaderName::from_static("x-xss-protection"),
                HeaderValue::from_static(if config.xss_protection {
                    "1; mode=block"
                } else {
                    "0"
                }),
            );

            // Content-Security-Policy
            if let Some(ref csp) = config.content_security_policy {
                if let Ok(value) = HeaderValue::from_str(csp) {
                    headers.insert(HeaderName::from_static("content-security-policy"), value);
                }
            }

            // Strict-Transport-Security (HSTS)
            if config.hsts_enabled {
                let hsts_value = config.build_hsts_value();
                if let Ok(value) = HeaderValue::from_str(&hsts_value) {
                    headers.insert(HeaderName::from_static("strict-transport-security"), value);
                }
            }

            // Referrer-Policy
            if let Some(value) = config.referrer_policy.to_header_value() {
                headers.insert(
                    HeaderName::from_static("referrer-policy"),
                    HeaderValue::from_static(value),
                );
            }

            // Permissions-Policy
            if let Some(ref policy) = config.permissions_policy {
                if let Ok(value) = HeaderValue::from_str(policy) {
                    headers.insert(HeaderName::from_static("permissions-policy"), value);
                }
            }

            // Cache-Control
            if let Some(ref cache) = config.cache_control {
                if let Ok(value) = HeaderValue::from_str(cache) {
                    headers.insert(HeaderName::from_static("cache-control"), value);
                }
            }

            Ok(response)
        })
    }
}

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

    // =============================================================================
    // FrameOptions Tests
    // =============================================================================

    #[test]
    fn test_frame_options_deny() {
        assert_eq!(FrameOptions::Deny.to_header_value(), Some("DENY"));
    }

    #[test]
    fn test_frame_options_same_origin() {
        assert_eq!(
            FrameOptions::SameOrigin.to_header_value(),
            Some("SAMEORIGIN")
        );
    }

    #[test]
    fn test_frame_options_disabled() {
        assert_eq!(FrameOptions::Disabled.to_header_value(), None);
    }

    #[test]
    fn test_frame_options_equality() {
        assert_eq!(FrameOptions::Deny, FrameOptions::Deny);
        assert_ne!(FrameOptions::Deny, FrameOptions::SameOrigin);
    }

    // =============================================================================
    // ReferrerPolicy Tests
    // =============================================================================

    #[test]
    fn test_referrer_policy_values() {
        assert_eq!(
            ReferrerPolicy::NoReferrer.to_header_value(),
            Some("no-referrer")
        );
        assert_eq!(
            ReferrerPolicy::NoReferrerWhenDowngrade.to_header_value(),
            Some("no-referrer-when-downgrade")
        );
        assert_eq!(ReferrerPolicy::Origin.to_header_value(), Some("origin"));
        assert_eq!(
            ReferrerPolicy::OriginWhenCrossOrigin.to_header_value(),
            Some("origin-when-cross-origin")
        );
        assert_eq!(
            ReferrerPolicy::SameOrigin.to_header_value(),
            Some("same-origin")
        );
        assert_eq!(
            ReferrerPolicy::StrictOrigin.to_header_value(),
            Some("strict-origin")
        );
        assert_eq!(
            ReferrerPolicy::StrictOriginWhenCrossOrigin.to_header_value(),
            Some("strict-origin-when-cross-origin")
        );
        assert_eq!(
            ReferrerPolicy::UnsafeUrl.to_header_value(),
            Some("unsafe-url")
        );
        assert_eq!(ReferrerPolicy::Disabled.to_header_value(), None);
    }

    // =============================================================================
    // SecurityHeaders Default Tests
    // =============================================================================

    #[test]
    fn test_default_security_headers() {
        let headers = SecurityHeaders::default();

        assert!(headers.content_type_options);
        assert_eq!(headers.frame_options, FrameOptions::Deny);
        assert!(!headers.xss_protection);
        assert!(headers.content_security_policy.is_none());
        assert!(!headers.hsts_enabled);
        assert_eq!(headers.hsts_max_age, 31536000);
        assert!(!headers.hsts_include_subdomains);
        assert!(!headers.hsts_preload);
        assert_eq!(
            headers.referrer_policy,
            ReferrerPolicy::StrictOriginWhenCrossOrigin
        );
        assert!(headers.permissions_policy.is_none());
        assert!(headers.cache_control.is_none());
    }

    #[test]
    fn test_new_equals_default() {
        let new = SecurityHeaders::new();
        let default = SecurityHeaders::default();

        assert_eq!(new.content_type_options, default.content_type_options);
        assert_eq!(new.frame_options, default.frame_options);
        assert_eq!(new.hsts_enabled, default.hsts_enabled);
    }

    // =============================================================================
    // SecurityHeaders Strict Tests
    // =============================================================================

    #[test]
    fn test_strict_security_headers() {
        let headers = SecurityHeaders::strict();

        assert!(headers.content_type_options);
        assert_eq!(headers.frame_options, FrameOptions::Deny);
        assert!(headers.content_security_policy.is_some());
        assert_eq!(
            headers.content_security_policy.as_deref(),
            Some("default-src 'self'")
        );
        assert!(headers.hsts_enabled);
        assert!(headers.hsts_include_subdomains);
        assert!(!headers.hsts_preload);
        assert_eq!(headers.referrer_policy, ReferrerPolicy::NoReferrer);
        assert!(headers.permissions_policy.is_some());
        assert!(headers.cache_control.is_some());
    }

    // =============================================================================
    // Builder Pattern Tests
    // =============================================================================

    #[test]
    fn test_frame_options_builder() {
        let headers = SecurityHeaders::new().frame_options(FrameOptions::SameOrigin);

        assert_eq!(headers.frame_options, FrameOptions::SameOrigin);
    }

    #[test]
    fn test_content_security_policy_builder() {
        let headers =
            SecurityHeaders::new().content_security_policy("default-src 'self'; script-src 'self'");

        assert_eq!(
            headers.content_security_policy.as_deref(),
            Some("default-src 'self'; script-src 'self'")
        );
    }

    #[test]
    fn test_hsts_builder() {
        let headers = SecurityHeaders::new().hsts(true, 86400);

        assert!(headers.hsts_enabled);
        assert_eq!(headers.hsts_max_age, 86400);
    }

    #[test]
    fn test_hsts_include_subdomains_builder() {
        let headers = SecurityHeaders::new().hsts_include_subdomains(true);

        assert!(headers.hsts_include_subdomains);
    }

    #[test]
    fn test_hsts_preload_builder() {
        let headers = SecurityHeaders::new().hsts_preload(true);

        assert!(headers.hsts_preload);
    }

    #[test]
    fn test_referrer_policy_builder() {
        let headers = SecurityHeaders::new().referrer_policy(ReferrerPolicy::NoReferrer);

        assert_eq!(headers.referrer_policy, ReferrerPolicy::NoReferrer);
    }

    #[test]
    fn test_permissions_policy_builder() {
        let headers = SecurityHeaders::new().permissions_policy("geolocation=(), camera=()");

        assert_eq!(
            headers.permissions_policy.as_deref(),
            Some("geolocation=(), camera=()")
        );
    }

    #[test]
    fn test_cache_control_builder() {
        let headers = SecurityHeaders::new().cache_control("no-cache, no-store");

        assert_eq!(headers.cache_control.as_deref(), Some("no-cache, no-store"));
    }

    #[test]
    fn test_disable_content_type_options() {
        let headers = SecurityHeaders::new().disable_content_type_options();

        assert!(!headers.content_type_options);
    }

    #[test]
    fn test_chained_builders() {
        let headers = SecurityHeaders::new()
            .frame_options(FrameOptions::SameOrigin)
            .content_security_policy("default-src 'self'")
            .hsts(true, 86400)
            .hsts_include_subdomains(true)
            .referrer_policy(ReferrerPolicy::StrictOrigin)
            .permissions_policy("geolocation=()")
            .cache_control("private");

        assert_eq!(headers.frame_options, FrameOptions::SameOrigin);
        assert!(headers.content_security_policy.is_some());
        assert!(headers.hsts_enabled);
        assert!(headers.hsts_include_subdomains);
        assert_eq!(headers.referrer_policy, ReferrerPolicy::StrictOrigin);
        assert!(headers.permissions_policy.is_some());
        assert!(headers.cache_control.is_some());
    }

    // =============================================================================
    // HSTS Value Building Tests
    // =============================================================================

    #[test]
    fn test_build_hsts_value_basic() {
        let headers = SecurityHeaders::new().hsts(true, 31536000);

        assert_eq!(headers.build_hsts_value(), "max-age=31536000");
    }

    #[test]
    fn test_build_hsts_value_with_subdomains() {
        let headers = SecurityHeaders::new()
            .hsts(true, 31536000)
            .hsts_include_subdomains(true);

        assert_eq!(
            headers.build_hsts_value(),
            "max-age=31536000; includeSubDomains"
        );
    }

    #[test]
    fn test_build_hsts_value_with_preload() {
        let headers = SecurityHeaders::new()
            .hsts(true, 31536000)
            .hsts_preload(true);

        assert_eq!(headers.build_hsts_value(), "max-age=31536000; preload");
    }

    #[test]
    fn test_build_hsts_value_full() {
        let headers = SecurityHeaders::new()
            .hsts(true, 31536000)
            .hsts_include_subdomains(true)
            .hsts_preload(true);

        assert_eq!(
            headers.build_hsts_value(),
            "max-age=31536000; includeSubDomains; preload"
        );
    }

    // =============================================================================
    // Clone Tests
    // =============================================================================

    #[test]
    fn test_security_headers_clone() {
        let original = SecurityHeaders::new()
            .frame_options(FrameOptions::SameOrigin)
            .content_security_policy("default-src 'self'");

        let cloned = original.clone();

        assert_eq!(cloned.frame_options, original.frame_options);
        assert_eq!(
            cloned.content_security_policy,
            original.content_security_policy
        );
    }

    // =============================================================================
    // Debug Tests
    // =============================================================================

    #[test]
    fn test_security_headers_debug() {
        let headers = SecurityHeaders::new();
        let debug_str = format!("{:?}", headers);

        assert!(debug_str.contains("SecurityHeaders"));
    }

    #[test]
    fn test_frame_options_debug() {
        let deny = FrameOptions::Deny;
        let debug_str = format!("{:?}", deny);

        assert!(debug_str.contains("Deny"));
    }

    #[test]
    fn test_referrer_policy_debug() {
        let policy = ReferrerPolicy::StrictOriginWhenCrossOrigin;
        let debug_str = format!("{:?}", policy);

        assert!(debug_str.contains("StrictOriginWhenCrossOrigin"));
    }
}