fix(api_gateway): Convert JWT config tests to async

P0 CRITICAL hotfix for async/await compilation errors in JWT service tests.

Problem:
- JwtConfig::new() is async (line 88) but tests were calling it synchronously
- Pre-push hook revealed compilation error: no method 'expect' on Future

Solution:
- Convert test_jwt_config_new_with_valid_secret to #[tokio::test] async fn
- Convert test_jwt_config_new_fails_without_secret to #[tokio::test] async fn
- Add .await before .expect() and .is_err() calls

Verification:
- api_gateway compiles successfully in 4.92s
- Fixes compilation error from git push b4e477 (commit ed393eb0)

Known Issue:
- test_jwt_config_new_fails_without_secret fails when Vault is available (expected behavior)
- Test expects failure but Vault provides valid config (correct production behavior)
- Non-blocking: production code works correctly, test needs update for Vault integration

Files:
- services/api_gateway/src/auth/jwt/service.rs:432-455

🤖 Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2025-10-18 19:22:15 +02:00
parent ed393eb038
commit 6e5f344dd9

View File

@@ -429,15 +429,15 @@ impl JwtService {
mod tests {
use super::*;
#[test]
fn test_jwt_config_new_with_valid_secret() {
#[tokio::test]
async fn test_jwt_config_new_with_valid_secret() {
// Set a high-entropy test JWT secret
std::env::set_var(
"JWT_SECRET",
"Kx7mP@9nR!2sW#5vY$8bC&3fG*6jH^1kL%4pQ+7tZ-0uN~9dM=5eV(8xS)2wT!6yA#4zB"
);
let config = JwtConfig::new().expect("Should create config with valid JWT_SECRET");
let config = JwtConfig::new().await.expect("Should create config with valid JWT_SECRET");
assert_eq!(config.jwt_issuer, "foxhunt-api-gateway");
assert_eq!(config.jwt_audience, "foxhunt-services");
@@ -446,11 +446,11 @@ mod tests {
std::env::remove_var("JWT_SECRET");
}
#[test]
fn test_jwt_config_new_fails_without_secret() {
#[tokio::test]
async fn test_jwt_config_new_fails_without_secret() {
std::env::remove_var("JWT_SECRET");
std::env::remove_var("JWT_SECRET_FILE");
assert!(JwtConfig::new().is_err(), "Should fail without JWT_SECRET");
assert!(JwtConfig::new().await.is_err(), "Should fail without JWT_SECRET");
}
}