use crate::core::config::Config;
pub mod audit_log;
pub mod models;
pub mod openapi_log;
pub use audit_log::AuditLogService;
pub use openapi_log::OpenapiLogService;
pub struct SecurityAndComplianceService {
pub openapi_log: OpenapiLogService,
pub audit_log: AuditLogService,
}
impl SecurityAndComplianceService {
pub fn new(config: Config) -> Self {
Self {
openapi_log: OpenapiLogService::new(config.clone()),
audit_log: AuditLogService::new(config),
}
}
pub fn new_from_shared(shared: std::sync::Arc<Config>) -> Self {
Self {
openapi_log: OpenapiLogService::new(shared.as_ref().clone()),
audit_log: AuditLogService::new(shared.as_ref().clone()),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::time::Duration;
#[test]
fn test_security_and_compliance_service_creation() {
let config = Config::default();
let service = SecurityAndComplianceService::new(config.clone());
assert_eq!(service.openapi_log.config.app_id, config.app_id);
assert_eq!(service.openapi_log.config.app_secret, config.app_secret);
assert_eq!(service.audit_log.config.app_id, config.app_id);
assert_eq!(service.audit_log.config.app_secret, config.app_secret);
}
#[test]
fn test_security_and_compliance_service_with_custom_config() {
let config = Config::builder()
.app_id("security_test_app")
.app_secret("security_test_secret")
.req_timeout(Duration::from_secs(180))
.build();
let service = SecurityAndComplianceService::new(config.clone());
assert_eq!(service.openapi_log.config.app_id, "security_test_app");
assert_eq!(
service.openapi_log.config.app_secret,
"security_test_secret"
);
assert_eq!(
service.openapi_log.config.req_timeout,
Some(Duration::from_secs(180))
);
assert_eq!(service.audit_log.config.app_id, "security_test_app");
assert_eq!(
service.audit_log.config.req_timeout,
Some(Duration::from_secs(180))
);
}
#[test]
fn test_security_and_compliance_service_config_independence() {
let config1 = Config::builder().app_id("security_app_1").build();
let config2 = Config::builder().app_id("security_app_2").build();
let service1 = SecurityAndComplianceService::new(config1);
let service2 = SecurityAndComplianceService::new(config2);
assert_eq!(service1.openapi_log.config.app_id, "security_app_1");
assert_eq!(service2.openapi_log.config.app_id, "security_app_2");
assert_ne!(
service1.openapi_log.config.app_id,
service2.openapi_log.config.app_id
);
assert_ne!(
service1.audit_log.config.app_id,
service2.audit_log.config.app_id
);
}
#[test]
fn test_security_and_compliance_service_sub_services_accessible() {
let config = Config::default();
let service = SecurityAndComplianceService::new(config.clone());
assert_eq!(service.openapi_log.config.app_id, config.app_id);
assert_eq!(service.audit_log.config.app_id, config.app_id);
}
#[test]
fn test_security_and_compliance_service_config_cloning() {
let config = Config::builder()
.app_id("clone_test_app")
.app_secret("clone_test_secret")
.build();
let service = SecurityAndComplianceService::new(config.clone());
assert_eq!(service.openapi_log.config.app_id, "clone_test_app");
assert_eq!(service.openapi_log.config.app_secret, "clone_test_secret");
assert_eq!(service.audit_log.config.app_secret, "clone_test_secret");
assert_eq!(service.audit_log.config.app_id, "clone_test_app");
}
#[test]
fn test_security_and_compliance_service_timeout_propagation() {
let config = Config::builder()
.req_timeout(Duration::from_secs(200))
.build();
let service = SecurityAndComplianceService::new(config);
assert_eq!(
service.openapi_log.config.req_timeout,
Some(Duration::from_secs(200))
);
assert_eq!(
service.audit_log.config.req_timeout,
Some(Duration::from_secs(200))
);
}
#[test]
fn test_security_and_compliance_service_multiple_instances() {
let config = Config::default();
let service1 = SecurityAndComplianceService::new(config.clone());
let service2 = SecurityAndComplianceService::new(config.clone());
assert_eq!(
service1.openapi_log.config.app_id,
service2.openapi_log.config.app_id
);
assert_eq!(
service1.openapi_log.config.app_secret,
service2.openapi_log.config.app_secret
);
assert_eq!(
service1.audit_log.config.app_id,
service2.audit_log.config.app_id
);
assert_eq!(
service1.audit_log.config.app_secret,
service2.audit_log.config.app_secret
);
}
#[test]
fn test_security_and_compliance_service_config_consistency() {
let config = Config::builder()
.app_id("consistency_test")
.app_secret("consistency_secret")
.req_timeout(Duration::from_secs(150))
.build();
let service = SecurityAndComplianceService::new(config);
assert_eq!(service.openapi_log.config.app_id, "consistency_test");
assert_eq!(service.openapi_log.config.app_secret, "consistency_secret");
assert_eq!(
service.openapi_log.config.req_timeout,
Some(Duration::from_secs(150))
);
assert_eq!(service.audit_log.config.app_id, "consistency_test");
assert_eq!(service.audit_log.config.app_secret, "consistency_secret");
assert_eq!(
service.audit_log.config.req_timeout,
Some(Duration::from_secs(150))
);
}
}