use crate::config::{AppConfig, AuthConfig, CorsConfig, ServerConfig};
use crate::http::{build, build_with_config};
#[test]
fn test_build_with_config_jwt() {
let config = AppConfig {
server: ServerConfig {
host: "0.0.0.0".to_string(),
port: 3000,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::Jwt {
secret: "ThisIsAVeryLongSecretKeyWithUppercase123!@#ForTesting".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok(), "Should build successfully with JWT config");
}
#[test]
fn test_build_with_config_api_key() {
let config = AppConfig {
server: ServerConfig {
host: "0.0.0.0".to_string(),
port: 3000,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::ApiKey {
header_name: "X-API-Key".to_string(),
prefix: "key-".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(
result.is_ok(),
"Should build successfully with ApiKey config"
);
}
#[test]
fn test_build_with_config_oauth2_error() {
let config = AppConfig {
server: ServerConfig {
host: "0.0.0.0".to_string(),
port: 3000,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok(), "Should succeed with None auth config");
}
#[test]
fn test_build_with_config_cors() {
let config = AppConfig {
server: ServerConfig {
host: "0.0.0.0".to_string(),
port: 3000,
request_timeout_secs: 30,
cors: Some(CorsConfig {
allowed_origins: vec!["http://localhost:3000".to_string()],
allowed_methods: vec!["GET".to_string(), "POST".to_string()],
allowed_headers: vec!["Content-Type".to_string()],
}),
},
authentication: AuthConfig::Jwt {
secret: "ThisIsAVeryLongSecretKeyWithUppercase123!@#ForTesting".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok(), "Should build successfully with CORS config");
}
#[test]
fn test_build_with_config_request_id_middleware() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 60,
cors: None,
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_body_limit() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_compression_layer() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_timeout_layer() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 5,
cors: None,
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_zero_timeout() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 0,
cors: None,
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_large_timeout() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 3600,
cors: None,
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_cors_various_origins() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: Some(CorsConfig {
allowed_origins: vec![
"http://localhost:3000".to_string(),
"http://example.com".to_string(),
"https://app.example.com".to_string(),
],
allowed_methods: vec!["GET".to_string()],
allowed_headers: vec!["Content-Type".to_string()],
}),
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_cors_all_methods() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: Some(CorsConfig {
allowed_origins: vec![
"http://localhost:3000".to_string(),
"https://example.com".to_string(),
],
allowed_methods: vec!["GET".to_string(), "POST".to_string()],
allowed_headers: vec!["Content-Type".to_string()],
}),
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_api_key_empty_prefix() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::ApiKey {
header_name: "X-API-Key".to_string(),
prefix: "".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_api_key_long_prefix() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::ApiKey {
header_name: "X-Custom-API-Key".to_string(),
prefix: "Bearer-api-key-".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_api_key_special_chars() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::ApiKey {
header_name: "X-Api-Key".to_string(),
prefix: "key_123-".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_jwt_short_secret() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::Jwt {
secret: "ValidSecretKey123!@#WithUppercase".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_jwt_special_chars() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::Jwt {
secret: "SpecialChars!@#$%^&*()_+Secret123".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[test]
fn test_build_with_config_jwt_empty_secret() {
let config = AppConfig {
server: ServerConfig {
host: "127.0.0.1".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::Jwt {
secret: "ValidSecretForTesting123!@#WithUppercase".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok());
}
#[cfg(feature = "mcp")]
#[test]
fn test_build_preserves_mcp_inventory_with_routes() {
let router = build();
let _ = router;
}
#[cfg(feature = "websocket")]
#[test]
fn test_build_preserves_websocket_inventory_with_routes() {
let router = build();
let _ = router;
}
#[cfg(feature = "grpc")]
#[test]
fn test_build_preserves_grpc_inventory_with_routes() {
let router = build();
let _ = router;
}
#[test]
fn test_build_with_config_full_jwt_cors() {
let config = AppConfig {
server: ServerConfig {
host: "0.0.0.0".to_string(),
port: 443,
request_timeout_secs: 15,
cors: Some(CorsConfig {
allowed_origins: vec!["https://app.example.com".to_string()],
allowed_methods: vec!["GET".to_string(), "POST".to_string()],
allowed_headers: vec!["Content-Type".to_string(), "Authorization".to_string()],
}),
},
authentication: AuthConfig::Jwt {
secret: "AnotherVeryLongSecretKeyForTestingPurposes1234567890!".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok(), "Should build with full config");
}
#[test]
fn test_build_with_config_full_api_key_cors() {
let config = AppConfig {
server: ServerConfig {
host: "0.0.0.0".to_string(),
port: 8443,
request_timeout_secs: 20,
cors: Some(CorsConfig {
allowed_origins: vec!["http://localhost:8080".to_string()],
allowed_methods: vec!["GET".to_string(), "POST".to_string(), "PUT".to_string()],
allowed_headers: vec!["Content-Type".to_string(), "X-API-Key".to_string()],
}),
},
authentication: AuthConfig::ApiKey {
header_name: "X-API-Key".to_string(),
prefix: "sk-".to_string(),
},
timeout: None,
};
let result = build_with_config(&config);
assert!(result.is_ok(), "Should build with full config");
}
#[test]
fn test_build_with_config_no_auth() {
let config = AppConfig {
server: ServerConfig {
host: "0.0.0.0".to_string(),
port: 8080,
request_timeout_secs: 30,
cors: None,
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(
result.is_ok(),
"build_with_config should succeed with AuthConfig::None: {:?}",
result.err()
);
}
#[test]
fn test_build_with_config_minimal_config() {
let config = AppConfig {
server: ServerConfig {
host: String::new(),
port: 1,
request_timeout_secs: 1,
cors: None,
},
authentication: AuthConfig::None,
timeout: None,
};
let result = build_with_config(&config);
assert!(
result.is_ok(),
"Minimal config should build: {:?}",
result.err()
);
}