auth-framework 0.5.0-rc19

A comprehensive, production-ready authentication and authorization framework for Rust applications
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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
//! Comprehensive API and Integration Tests for AuthFramewo        let mut framework = AuthFramework::new(config);
// Framework not yet initialized
//!
//! This test suite validates all public APIs, edge cases, and integration scenarios
//! for the current AuthFramework implementation.

use auth_framework::{
    auth::AuthFramework,
    authentication::credentials::{Credential, CredentialMetadata},
    config::{
        AuthConfig, CookieSameSite, JwtAlgorithm, PasswordHashAlgorithm, RateLimitConfig,
        SecurityConfig, StorageConfig,
    },
    errors::AuthError,
    methods::{ApiKeyMethod, AuthMethodEnum, JwtMethod, OAuth2Method, PasswordMethod},
    tokens::AuthToken,
};
use std::time::Duration;

/// Test suite for AuthFramework initialization and configuration
#[cfg(test)]
mod framework_lifecycle_tests {
    use super::*;

    #[tokio::test]
    async fn test_new_framework_with_minimal_config() {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());

        let framework = AuthFramework::new(config);
        // Framework created successfully (can't test initialization state)
        let credential = Credential::password("test", "pass");
        assert!(
            framework
                .authenticate("password", credential)
                .await
                .is_err()
        );
    }

    #[tokio::test]
    async fn test_new_framework_with_full_config() {
        let config = AuthConfig::new()
            .secret("test_secret_key_32_bytes_long!!!!".to_string())
            .issuer("test-issuer".to_string())
            .audience("test-audience".to_string())
            .storage(StorageConfig::Memory)
            .security(SecurityConfig {
                min_password_length: 12,
                require_password_complexity: true,
                password_hash_algorithm: PasswordHashAlgorithm::Argon2,
                jwt_algorithm: JwtAlgorithm::HS256,
                secret_key: Some("test_secret_key_32_bytes_long!!!!".to_string()),
                secure_cookies: true,
                cookie_same_site: CookieSameSite::Strict,
                csrf_protection: true,
                session_timeout: Duration::from_secs(1800),
                previous_secret_key: None,
            })
            .rate_limiting(RateLimitConfig {
                enabled: true,
                max_requests: 100,
                window: Duration::from_secs(60),
                burst: 150,
            });

        let mut framework = AuthFramework::new(config);
        assert!(framework.initialize().await.is_ok());
        // Framework successfully initialized
    }

    #[tokio::test]
    async fn test_framework_initialization_success() {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);

        let result = framework.initialize().await;
        assert!(result.is_ok());
        // Framework successfully initialized
    }

    #[tokio::test]
    async fn test_framework_double_initialization() {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);

        // First initialization
        assert!(framework.initialize().await.is_ok());
        // Framework successfully initialized

        // Second initialization should succeed (idempotent)
        assert!(framework.initialize().await.is_ok());
        // Framework still initialized
    }

    #[test]
    fn test_framework_new_with_invalid_secret() {
        // Secret too short
        let config = AuthConfig::new().secret("short".to_string());

        // This should not panic but should show a warning
        let _framework = AuthFramework::new(config);
    }

    #[test]
    fn test_framework_new_with_env_var_fallback() {
        // Test JWT_SECRET environment variable fallback
        let _env = auth_framework::testing::test_infrastructure::TestEnvironmentGuard::new()
            .with_jwt_secret("env_secret_key_32_bytes_long!!!!!");

        let config = AuthConfig::new(); // No explicit secret
        let _framework = AuthFramework::new(config);
    }
}

/// Test suite for authentication method registration and management
#[cfg(test)]
mod method_registration_tests {
    use super::*;

    #[tokio::test]
    async fn test_register_password_method() {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);

        framework.register_method("password", AuthMethodEnum::Password(PasswordMethod::new()));

        assert!(framework.initialize().await.is_ok());
    }

    #[tokio::test]
    async fn test_register_multiple_methods() {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);

        framework.register_method("password", AuthMethodEnum::Password(PasswordMethod::new()));
        framework.register_method("jwt", AuthMethodEnum::Jwt(JwtMethod::new()));
        framework.register_method("api_key", AuthMethodEnum::ApiKey(ApiKeyMethod::new()));
        framework.register_method("oauth2", AuthMethodEnum::OAuth2(OAuth2Method::new()));

        assert!(framework.initialize().await.is_ok());
    }

    #[tokio::test]
    async fn test_register_method_overwrite() {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);

        // Register method twice - should overwrite
        framework.register_method("password", AuthMethodEnum::Password(PasswordMethod::new()));
        framework.register_method("password", AuthMethodEnum::Password(PasswordMethod::new()));

        assert!(framework.initialize().await.is_ok());
    }
}

/// Test suite for authentication flows and edge cases
#[cfg(test)]
mod authentication_tests {
    use super::*;

    async fn setup_framework_with_methods() -> AuthFramework {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);

        framework.register_method("password", AuthMethodEnum::Password(PasswordMethod::new()));
        framework.register_method("jwt", AuthMethodEnum::Jwt(JwtMethod::new()));
        framework.register_method("api_key", AuthMethodEnum::ApiKey(ApiKeyMethod::new()));

        framework.initialize().await.unwrap();
        framework
    }

    #[tokio::test]
    async fn test_authenticate_with_uninitialized_framework() {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let framework = AuthFramework::new(config); // Not initialized

        let credential = Credential::password("user", "password");
        let result = framework.authenticate("password", credential).await;

        assert!(result.is_err());
        assert!(
            matches!(
                result.unwrap_err(),
                AuthError::Configuration { .. }
            ),
            "Uninitialized framework should return Configuration error"
        );
    }

    #[tokio::test]
    async fn test_authenticate_with_unknown_method() {
        let framework = setup_framework_with_methods().await;

        let credential = Credential::password("user", "password");
        let result = framework.authenticate("unknown_method", credential).await;

        assert!(result.is_err());
        assert!(matches!(
            result.unwrap_err(),
            AuthError::AuthMethod {
                method: _,
                message: _,
                ..
            }
        ));
    }

    #[tokio::test]
    async fn test_authenticate_password_empty_credentials() {
        let framework = setup_framework_with_methods().await;

        let credential = Credential::password("", "");
        let result = framework.authenticate("password", credential).await;

        // Should succeed but return failure result from method
        assert!(result.is_ok());
        match result.unwrap() {
            auth_framework::AuthResult::Failure(reason) => {
                assert!(reason.contains("empty"));
            }
            _ => panic!("Expected failure result"),
        }
    }

    #[tokio::test]
    async fn test_authenticate_jwt_empty_token() {
        let framework = setup_framework_with_methods().await;

        let credential = Credential::jwt("");
        let result = framework.authenticate("jwt", credential).await;

        assert!(result.is_ok());
        match result.unwrap() {
            auth_framework::AuthResult::Failure(reason) => {
                assert!(reason.contains("empty"));
            }
            _ => panic!("Expected failure result"),
        }
    }

    #[tokio::test]
    async fn test_authenticate_api_key_empty_key() {
        let framework = setup_framework_with_methods().await;

        let credential = Credential::api_key("");
        let result = framework.authenticate("api_key", credential).await;

        assert!(result.is_ok());
        match result.unwrap() {
            auth_framework::AuthResult::Failure(reason) => {
                assert!(reason.contains("empty"));
            }
            _ => panic!("Expected failure result"),
        }
    }

    #[tokio::test]
    async fn test_authenticate_with_metadata() {
        let framework = setup_framework_with_methods().await;

        let credential = Credential::password("user", "password");
        let _metadata = CredentialMetadata::new();
        let metadata = CredentialMetadata::new()
            .client_ip("192.168.1.1".to_string())
            .user_agent("TestAgent/1.0".to_string());

        let result = framework
            .authenticate_with_metadata("password", credential, metadata)
            .await;
        assert!(result.is_ok());
        // With no registered users, password auth yields a Failure variant
        match result.unwrap() {
            auth_framework::AuthResult::Failure(_) => {}
            other => panic!("Expected Failure for unknown user, got {:?}", other),
        }
    }

    #[tokio::test]
    async fn test_authenticate_with_localhost_ip_warning() {
        let framework = setup_framework_with_methods().await;

        let credential = Credential::password("user", "password");
        let metadata = CredentialMetadata::new().client_ip("127.0.0.1");

        let result = framework
            .authenticate_with_metadata("password", credential, metadata)
            .await;
        assert!(result.is_ok());
        // Localhost IP should still be processed; no registered user → Failure
        match result.unwrap() {
            auth_framework::AuthResult::Failure(_) => {}
            other => panic!("Expected Failure for localhost auth, got {:?}", other),
        }
    }
}

/// Test suite for token management and validation
#[cfg(test)]
mod token_management_tests {
    use super::*;

    async fn setup_framework() -> AuthFramework {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);
        framework.initialize().await.unwrap();
        framework
    }

    #[tokio::test]
    async fn test_create_auth_token_success() {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);
        framework.register_method("password", AuthMethodEnum::Password(PasswordMethod::new()));
        framework.initialize().await.unwrap();

        let result = framework
            .create_auth_token(
                "user123",
                vec!["read".to_string(), "write".to_string()],
                "password",
                Some(Duration::from_secs(3600)),
            )
            .await;

        assert!(result.is_ok());
        let token = result.unwrap();
        assert_eq!(token.user_id, "user123");
        assert_eq!(token.scopes, auth_framework::types::Scopes::new(vec!["read".to_string(), "write".to_string()]));
        assert_eq!(token.auth_method, "password");
    }

    #[tokio::test]
    async fn test_create_auth_token_with_unknown_method() {
        let framework = setup_framework().await;

        let result = framework
            .create_auth_token("user123", vec!["read".to_string()], "unknown_method", None)
            .await;

        assert!(result.is_err());
        assert!(matches!(
            result.unwrap_err(),
            AuthError::AuthMethod {
                method: _,
                message: _,
                ..
            }
        ));
    }

    #[tokio::test]
    async fn test_validate_token_uninitialized_framework() {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let framework = AuthFramework::new(config); // Not initialized

        let token = AuthToken::new("user", "token", Duration::from_secs(3600), "test");
        let result = framework.validate_token(&token).await;

        assert!(result.is_err());
        assert!(
            matches!(
                result.unwrap_err(),
                AuthError::Configuration { .. }
            ),
            "Uninitialized framework should return Configuration error"
        );
    }

    #[tokio::test]
    async fn test_token_manager_access() {
        let framework = setup_framework().await;
        let token_manager = framework.token_manager();

        // Just verify we can access the token manager
        // Token manager initialized successfully
        assert!(token_manager.validate_jwt_token("invalid_token").is_err());
    }
}

/// Test suite for user management and validation
#[cfg(test)]
mod user_management_tests {
    use super::*;

    async fn setup_framework() -> AuthFramework {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);
        framework.initialize().await.unwrap();
        framework
    }

    #[tokio::test]
    async fn test_validate_username_valid() {
        let framework = setup_framework().await;

        let result = framework.validate_username("valid_user123").await;
        assert!(result.is_ok());
        assert!(result.unwrap());
    }

    #[tokio::test]
    async fn test_validate_username_empty() {
        let framework = setup_framework().await;

        let result = framework.validate_username("").await;
        assert!(result.is_ok());
        assert!(!result.unwrap()); // Empty username should be invalid
    }

    #[tokio::test]
    async fn test_validate_username_too_long() {
        let framework = setup_framework().await;

        let long_username = "a".repeat(256); // Very long username
        let result = framework.validate_username(&long_username).await;
        assert!(result.is_ok());
        assert!(!result.unwrap()); // Too long username should be invalid
    }

    #[tokio::test]
    async fn test_validate_display_name_valid() {
        let framework = setup_framework().await;

        let result = framework.validate_display_name("John Doe").await;
        assert!(result.is_ok());
        assert!(result.unwrap());
    }

    #[tokio::test]
    async fn test_validate_display_name_empty() {
        let framework = setup_framework().await;

        let result = framework.validate_display_name("").await;
        assert!(result.is_ok());
        assert!(!result.unwrap()); // Empty display name should be invalid
    }

    #[tokio::test]
    async fn test_validate_user_input_safe() {
        let framework = setup_framework().await;

        let result = framework.validate_user_input("safe_input_123").await;
        assert!(result.is_ok());
        assert!(result.unwrap());
    }

    #[tokio::test]
    async fn test_validate_user_input_potentially_malicious() {
        let framework = setup_framework().await;

        let result = framework
            .validate_user_input("<script>alert('xss')</script>")
            .await;
        assert!(result.is_ok());
        assert!(!result.unwrap()); // Potentially malicious input should be invalid
    }
}

/// Test suite for MFA (Multi-Factor Authentication) functionality
#[cfg(test)]
mod mfa_tests {
    use super::*;

    async fn setup_framework() -> AuthFramework {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);
        framework.initialize().await.unwrap();
        framework
    }

    #[tokio::test]
    async fn test_initiate_sms_challenge_success() {
        let framework = setup_framework().await;

        let result = framework.initiate_sms_challenge("user123").await;
        assert!(result.is_ok());
        let challenge_id = result.unwrap();
        assert!(!challenge_id.is_empty());
    }

    #[tokio::test]
    async fn test_initiate_sms_challenge_empty_user() {
        let framework = setup_framework().await;

        let result = framework.initiate_sms_challenge("").await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_verify_sms_code_invalid_challenge() {
        let framework = setup_framework().await;

        let result = framework
            .verify_sms_code("invalid_challenge_id", "123456")
            .await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_initiate_email_challenge_success() {
        let framework = setup_framework().await;

        let result = framework.initiate_email_challenge("user123").await;
        assert!(result.is_ok());
        let challenge_id = result.unwrap();
        assert!(!challenge_id.is_empty());
    }

    #[tokio::test]
    async fn test_register_email_valid() {
        let framework = setup_framework().await;

        let result = framework
            .register_email("user123", "user@example.com")
            .await;
        assert!(result.is_ok());
    }

    #[tokio::test]
    async fn test_register_email_invalid_format() {
        let framework = setup_framework().await;

        let result = framework.register_email("user123", "invalid-email").await;
        assert!(result.is_err());
        assert!(matches!(
            result.unwrap_err(),
            AuthError::Validation { message: _ }
        ));
    }

    #[tokio::test]
    async fn test_register_email_empty() {
        let framework = setup_framework().await;

        let result = framework.register_email("user123", "").await;
        assert!(result.is_err());
        assert!(matches!(
            result.unwrap_err(),
            AuthError::Validation { message: _ }
        ));
    }

    #[tokio::test]
    async fn test_register_email_no_at_symbol() {
        let framework = setup_framework().await;

        let result = framework.register_email("user123", "userexample.com").await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_register_email_no_domain() {
        let framework = setup_framework().await;

        let result = framework.register_email("user123", "user@").await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_register_email_invalid_domain() {
        let framework = setup_framework().await;

        let result = framework.register_email("user123", "user@.com").await;
        assert!(result.is_err());
    }
}

/// Test suite for API key management
#[cfg(test)]
mod api_key_tests {
    use super::*;

    async fn setup_framework() -> AuthFramework {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);
        framework.initialize().await.unwrap();
        framework
    }

    #[tokio::test]
    async fn test_validate_api_key_nonexistent() {
        let framework = setup_framework().await;

        let result = framework.validate_api_key("nonexistent_key").await;
        assert!(result.is_err());
        assert!(matches!(result.unwrap_err(), AuthError::Token(_)));
    }

    #[tokio::test]
    async fn test_validate_api_key_empty() {
        let framework = setup_framework().await;

        let result = framework.validate_api_key("").await;
        assert!(result.is_err());
    }
}

/// Test suite for session management
#[cfg(test)]
mod session_tests {
    use super::*;

    async fn setup_framework() -> AuthFramework {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);
        framework.initialize().await.unwrap();
        framework
    }

    #[tokio::test]
    async fn test_get_nonexistent_session() {
        let framework = setup_framework().await;

        let result = framework.get_session("nonexistent_session").await;
        assert!(result.is_ok());
        assert!(result.unwrap().is_none());
    }

    #[tokio::test]
    async fn test_delete_nonexistent_session() {
        let framework = setup_framework().await;

        let result = framework.delete_session("nonexistent_session").await;
        assert!(result.is_ok()); // Should succeed even if session doesn't exist
    }

    #[tokio::test]
    async fn test_list_user_tokens_empty() {
        let framework = setup_framework().await;

        let result = framework.list_user_tokens("nonexistent_user").await;
        assert!(result.is_ok());
        assert!(result.unwrap().is_empty());
    }
}

/// Test suite for rate limiting functionality
#[cfg(test)]
mod rate_limiting_tests {
    use super::*;

    #[tokio::test]
    async fn test_rate_limiting_disabled() {
        let config = AuthConfig::new()
            .secret("test_secret_key_32_bytes_long!!!!".to_string())
            .rate_limiting(RateLimitConfig {
                enabled: false,
                max_requests: 10,
                window: Duration::from_secs(60),
                burst: 15,
            });
        let mut framework = AuthFramework::new(config);
        framework.initialize().await.unwrap();

        let result = framework.check_ip_rate_limit("192.168.1.1").await;
        assert!(result.is_ok());
        assert!(result.unwrap()); // Should always pass when disabled
    }

    #[tokio::test]
    async fn test_rate_limiting_enabled() {
        let config = AuthConfig::new()
            .secret("test_secret_key_32_bytes_long!!!!".to_string())
            .rate_limiting(RateLimitConfig {
                enabled: true,
                max_requests: 5,
                window: Duration::from_secs(60),
                burst: 10,
            });
        let mut framework = AuthFramework::new(config);
        framework.initialize().await.unwrap();

        let result = framework.check_ip_rate_limit("192.168.1.1").await;
        assert!(result.is_ok());
        assert!(result.unwrap(), "First request should be within rate limit");
    }
}

/// Test suite for statistics and monitoring
#[cfg(test)]
mod monitoring_tests {
    use super::*;

    async fn setup_framework() -> AuthFramework {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);
        framework.initialize().await.unwrap();
        framework
    }

    #[tokio::test]
    async fn test_get_stats() {
        let framework = setup_framework().await;

        let result = framework.get_stats().await;
        assert!(result.is_ok());
        let stats = result.unwrap();

        // Verify stats structure
        assert_eq!(stats.registered_methods.len(), 0); // No methods registered
        assert_eq!(stats.tokens_issued, 0);
    }

    #[tokio::test]
    async fn test_get_security_metrics() {
        let framework = setup_framework().await;

        let result = framework.get_security_metrics().await;
        assert!(result.is_ok());
        let metrics = result.unwrap();

        // Should return a HashMap with security metrics
        assert!(metrics.contains_key("failed_attempts"));
        assert!(metrics.contains_key("successful_attempts"));
    }

    #[tokio::test]
    async fn test_cleanup_expired_data() {
        let framework = setup_framework().await;

        let result = framework.cleanup_expired_data().await;
        assert!(result.is_ok());
    }
}

/// Test suite for edge cases and error conditions
#[cfg(test)]
mod edge_case_tests {
    use super::*;

    #[test]
    fn test_config_validation_edge_cases() {
        // Test with minimal valid config
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        assert!(config.validate().is_ok());

        // Test with empty issuer (should still be valid)
        let config = AuthConfig::new()
            .secret("test_secret_key_32_bytes_long!!!!".to_string())
            .issuer("".to_string());
        assert!(config.validate().is_ok());
    }

    #[tokio::test]
    async fn test_concurrent_initialization() {
        let config = AuthConfig::new().secret("test_secret_key_32_bytes_long!!!!".to_string());
        let mut framework = AuthFramework::new(config);

        // Try to initialize from multiple tasks simultaneously
        let handles: Vec<_> = (0..5)
            .map(|_| {
                tokio::spawn(async move {
                    // This won't work because we need mutable access
                    // framework.initialize().await
                })
            })
            .collect();

        // Wait for all tasks to complete
        for handle in handles {
            let _ = handle.await;
        }

        // Manual initialization should still work
        assert!(framework.initialize().await.is_ok());
    }

    #[test]
    fn test_memory_safety_with_large_configs() {
        // Test with very large configuration values
        let large_string = "a".repeat(10000);
        let config = AuthConfig::new()
            .secret("test_secret_key_32_bytes_long!!!!".to_string())
            .issuer(large_string.clone())
            .audience(large_string);

        let _framework = AuthFramework::new(config);
    }
}