diff --git a/services/backup/src/http/handlers/backup.rs b/services/backup/src/http/handlers/backup.rs --- a/services/backup/src/http/handlers/backup.rs +++ b/services/backup/src/http/handlers/backup.rs @@ -17,6 +17,7 @@ use tokio_stream::{wrappers::ReceiverStream, StreamExt}; use tracing::{info, instrument, trace, warn}; +use crate::identity::find_user_id; use crate::{ database::{backup_item::BackupItem, DatabaseClient}, error::BackupError, @@ -282,8 +283,7 @@ db_client: web::Data, ) -> actix_web::Result { let username = path.into_inner(); - // Treat username as user_id in the initial version - let user_id = username; + let user_id = find_user_id(&username).await?; let Some(backup_item) = db_client .find_last_backup_item(&user_id) @@ -308,8 +308,7 @@ blob_client: Authenticated, ) -> actix_web::Result { let username = path.into_inner(); - // Treat username as user_id in the initial version - let user_id = username; + let user_id = find_user_id(&username).await?; let Some(backup_item) = db_client .find_last_backup_item(&user_id) diff --git a/services/commtest/tests/backup_integration_test.rs b/services/commtest/tests/backup_integration_test.rs --- a/services/commtest/tests/backup_integration_test.rs +++ b/services/commtest/tests/backup_integration_test.rs @@ -75,10 +75,30 @@ .await?; assert_eq!(user_data, backup_data.user_data); + // Test latest backup lookup for nonexistent user + let latest_backup_descriptor = BackupDescriptor::Latest { + username: "nonexistent_user".to_string(), + }; + + let nonexistent_user_response = backup_client + .download_backup_data(&latest_backup_descriptor, RequestedData::BackupID) + .await; + + match nonexistent_user_response { + Ok(_) => panic!("Expected error, but got success response"), + Err(BackupClientError::ReqwestError(error)) => { + assert_eq!( + error.status(), + Some(StatusCode::BAD_REQUEST), + "Expected bad request status" + ); + } + Err(_) => panic!("Unexpected error type"), + } + // Test latest backup lookup let latest_backup_descriptor = BackupDescriptor::Latest { - // Initial version of the backup service uses `user_id` in place of a username - username: device_info.user_id.to_string(), + username: device_info.username, }; let backup_id_response = backup_client diff --git a/services/commtest/tests/backup_performance_test.rs b/services/commtest/tests/backup_performance_test.rs --- a/services/commtest/tests/backup_performance_test.rs +++ b/services/commtest/tests/backup_performance_test.rs @@ -81,9 +81,15 @@ let mut handlers = vec![]; for user in &user_identities { let backup_client = backup_client.clone(); - let descriptor = BackupDescriptor::Latest { - username: user.user_id.clone(), + + let username = if user.user_id == device_info_1.user_id { + device_info_1.username.clone() + } else { + device_info_2.username.clone() }; + + let descriptor = BackupDescriptor::Latest { username }; + handlers.push(tokio::spawn(async move { let response = backup_client .download_backup_data(&descriptor, RequestedData::BackupID) @@ -107,9 +113,14 @@ let mut handlers = vec![]; for user in &user_identities { let backup_client = backup_client.clone(); - let descriptor = BackupDescriptor::Latest { - username: user.user_id.clone(), + let username = if user.user_id == device_info_1.user_id { + device_info_1.username.clone() + } else { + device_info_2.username.clone() }; + + let descriptor = BackupDescriptor::Latest { username }; + handlers.push(tokio::spawn(async move { backup_client .download_backup_data(&descriptor, RequestedData::UserKeys)