use keeper_secrets_manager_core::{
caching,
core::{ClientOptions, SecretsManager},
custom_error::KSMRError,
storage::FileKeyValueStorage,
};
fn main() -> Result<(), KSMRError> {
println!("=== Manual Integration Test 6: Disaster Recovery Caching ===\n");
println!("Clearing existing cache...");
caching::clear_cache().ok();
println!("Cache cleared: {}", !caching::cache_exists());
let config = FileKeyValueStorage::new_config_storage("test_config.json".to_string())?;
let mut client_options = ClientOptions::new_client_options(config);
let client = reqwest::blocking::Client::builder()
.build()
.expect("build reqwest client");
println!("\nEnabling disaster recovery caching...");
client_options.set_custom_post_function(caching::make_caching_post_function(client));
let mut secrets_manager = SecretsManager::new(client_options)?;
println!("First API call (should save to cache)...");
let secrets = secrets_manager.get_secrets(Vec::new())?;
println!("✅ Retrieved {} secrets", secrets.len());
let cache_path = caching::get_cache_file_path();
println!("\nChecking cache...");
println!("Cache path: {:?}", cache_path);
println!("Cache exists: {}", caching::cache_exists());
if caching::cache_exists() {
println!("✅ Cache file created successfully");
if let Ok(metadata) = std::fs::metadata(&cache_path) {
println!("Cache size: {} bytes", metadata.len());
}
} else {
println!("⚠️ Cache file not created");
}
println!("\nTesting cache data retrieval...");
if let Some(cached_data) = caching::get_cached_data() {
println!("✅ Cache loaded: {} bytes", cached_data.len());
println!(" First 32 bytes: transmission key");
println!(" Remaining bytes: encrypted response");
} else {
println!("⚠️ Failed to load cache");
}
println!("\n=== Cache Function Validation ===");
println!("✅ make_caching_post_function() can be set");
println!("✅ Cache saves on successful API call");
println!("✅ Cache file accessible via get_cached_data()");
println!("✅ Cache can be cleared via clear_cache()");
println!("\nCleaning up cache file...");
caching::clear_cache().ok();
println!("✅ Cache cleared");
Ok(())
}