pub mod alerts;
#[cfg(feature = "async")]
pub mod async_logger;
pub mod builder;
pub mod logger;
pub mod storage;
pub mod types;
pub mod utils;
pub use alerts::AlertManager;
#[cfg(feature = "async")]
pub use async_logger::AsyncAuditLogger;
pub use builder::AuditEventBuilder;
pub use logger::AuditLogger;
pub use storage::LogFileManager;
pub use types::{
AlertingConfig, AuditConfig, AuditEvent, AuditStatistics, ComplianceMode, ComplianceReport,
DataClassification, EventCategory, EventOutcome, EventSeverity, RetentionPolicy,
StorageBackend, SystemContext,
};
#[cfg(feature = "s3")]
pub use types::S3Credentials;
pub use utils::{get_hostname, get_local_ip, get_stack_trace, get_thread_id};
#[cfg(test)]
mod tests {
use super::*;
#[allow(unused_imports)]
use tempfile::tempdir;
#[test]
fn test_audit_event_builder() {
let event = AuditEventBuilder::new(EventCategory::DataAccess, "read")
.userid("user123")
.resourceid("dataset1")
.severity(EventSeverity::Info)
.description("Read operation")
.metadata("size", "1000")
.outcome(EventOutcome::Success)
.build();
assert_eq!(event.category, EventCategory::DataAccess);
assert_eq!(event.action, "read");
assert_eq!(event.userid, Some("user123".to_string()));
assert_eq!(event.resourceid, Some("dataset1".to_string()));
assert_eq!(event.severity, EventSeverity::Info);
assert_eq!(event.outcome, EventOutcome::Success);
assert_eq!(event.metadata.get("size"), Some(&"1000".to_string()));
}
#[test]
fn test_audit_logger_creation() {
let temp_dir = tempdir().expect("Failed to create temp dir");
let config = AuditConfig {
log_directory: temp_dir.path().to_path_buf(),
..AuditConfig::default()
};
let logger = AuditLogger::new(config).expect("Failed to create audit logger");
let event = AuditEventBuilder::new(EventCategory::Authentication, "login")
.userid("test_user")
.outcome(EventOutcome::Success)
.build();
logger.log_event(event).expect("Failed to log event");
logger.flush().expect("Failed to flush");
}
#[test]
#[ignore] fn test_data_access_logging() {
let temp_dir = tempdir().expect("Failed to create temp dir");
let config = AuditConfig {
log_directory: temp_dir.path().to_path_buf(),
..AuditConfig::default()
};
let logger = AuditLogger::new(config).expect("Failed to create audit logger");
logger
.log_data_access(
"user123",
"sensitive_dataset",
"read",
Some("Compliance audit"),
)
.expect("Failed to log data access");
logger.flush().expect("Failed to flush");
}
#[test]
fn test_event_categories() {
assert_eq!(EventCategory::Authentication.as_str(), "authentication");
assert_eq!(EventCategory::DataAccess.as_str(), "data_access");
assert_eq!(EventCategory::Security.as_str(), "security");
}
#[test]
#[ignore] fn test_system_context() {
let context = SystemContext::current()
.with_sessionid("session123".to_string())
.with_requestid("req456".to_string());
assert_eq!(context.sessionid, Some("session123".to_string()));
assert_eq!(context.requestid, Some("req456".to_string()));
assert!(context.process_id > 0);
}
#[test]
fn test_compliance_modes() {
let config = AuditConfig {
compliance_mode: ComplianceMode::Financial,
..AuditConfig::default()
};
assert_eq!(config.compliance_mode, ComplianceMode::Financial);
}
}