fix(tests): resolve issues with s3 tests

This commit is contained in:
perf3ct 2025-08-11 00:54:09 +00:00
parent 6fd3dec749
commit 080263a9ac
No known key found for this signature in database
GPG Key ID: 569C4EEC436F5232
2 changed files with 15 additions and 7 deletions

View File

@ -181,10 +181,18 @@ pub fn validate_path_within_base(path: &str, base_dir: &str) -> Result<()> {
normalize_path(&base_buf) normalize_path(&base_buf)
}); });
// Add debug logging to diagnose path validation issues
eprintln!("DEBUG: Path validation:");
eprintln!(" Input path: '{}'", path);
eprintln!(" Input base: '{}'", base_dir);
eprintln!(" Canonical path: '{}'", canonical_path.display());
eprintln!(" Canonical base: '{}'", canonical_base.display());
eprintln!(" Starts with check: {}", canonical_path.starts_with(&canonical_base));
if !canonical_path.starts_with(&canonical_base) { if !canonical_path.starts_with(&canonical_base) {
return Err(anyhow::anyhow!( return Err(anyhow::anyhow!(
"Path '{}' is not within allowed base directory '{}'", "Path '{}' is not within allowed base directory '{}' (failed after {:?})",
path, base_dir path, base_dir, std::time::Instant::now().elapsed()
)); ));
} }

View File

@ -4,7 +4,7 @@ use std::sync::Arc;
use readur::services::file_service::FileService; use readur::services::file_service::FileService;
use readur::storage::factory::create_storage_backend; use readur::storage::factory::create_storage_backend;
use readur::config::StorageConfig; use readur::storage::StorageConfig;
#[cfg(feature = "s3")] #[cfg(feature = "s3")]
use readur::services::s3_service::S3Service; use readur::services::s3_service::S3Service;
@ -37,9 +37,9 @@ async fn test_s3_service_new_validation() {
async fn test_file_service_local_creation() { async fn test_file_service_local_creation() {
// Test local-only FileService creation and functionality // Test local-only FileService creation and functionality
let upload_path = "./test_uploads".to_string(); let upload_path = "./test_uploads".to_string();
let storage_config = StorageConfig::Local { upload_path }; let storage_config = StorageConfig::Local { upload_path: upload_path.clone() };
let storage_backend = create_storage_backend(storage_config).await.unwrap(); let storage_backend = create_storage_backend(storage_config).await.unwrap();
let _local_service = FileService::with_storage(storage_backend); let _local_service = FileService::with_storage(upload_path, storage_backend);
// Note: is_s3_enabled() method is no longer available in the new architecture // Note: is_s3_enabled() method is no longer available in the new architecture
// as we use trait-based abstraction instead of conditional logic // as we use trait-based abstraction instead of conditional logic
} }
@ -73,8 +73,8 @@ async fn test_s3_service_configuration() {
// Test FileService integration with S3 storage backend // Test FileService integration with S3 storage backend
#[cfg(feature = "s3")] #[cfg(feature = "s3")]
{ {
let storage_backend = Arc::new(service) as Arc<dyn crate::storage::StorageBackend>; let storage_backend = Arc::new(service) as Arc<dyn readur::storage::StorageBackend>;
let _s3_file_service = FileService::with_storage(storage_backend); let _s3_file_service = FileService::with_storage("./test_uploads".to_string(), storage_backend);
// Note: is_s3_enabled() method is no longer available in the new architecture // Note: is_s3_enabled() method is no longer available in the new architecture
// as we use trait-based abstraction instead of conditional logic // as we use trait-based abstraction instead of conditional logic
} }