From 7298238e3e8e8167b354170cf2773b70c26df725 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 8 May 2023 16:13:47 +0100 Subject: [PATCH] feat!: [#115] change endpoints /torrent/{id} to /torrent({infohash} BREAKING CHANGE: you cannot use the old endpoints anymore: - `GET /torrent/{id}`. - `PUT /torrent/{id}`. - `DELETE /torrent/{id}`. New endpoints: - `GET /torrent/{infohashi`. - `PUT /torrent/{infohash}`. - `DELETE /torrent/{infohash}`. --- src/databases/database.rs | 9 ++- src/databases/mysql.rs | 26 ++++++-- src/databases/sqlite.rs | 24 ++++++- src/routes/torrent.rs | 79 ++++++++++++++--------- tests/common/client.rs | 18 +++--- tests/common/contexts/torrent/fixtures.rs | 3 +- tests/common/contexts/torrent/requests.rs | 1 - tests/e2e/contexts/torrent/contract.rs | 41 ++++++------ 8 files changed, 129 insertions(+), 72 deletions(-) diff --git a/src/databases/database.rs b/src/databases/database.rs index 17ce8743..915b52ce 100644 --- a/src/databases/database.rs +++ b/src/databases/database.rs @@ -156,8 +156,8 @@ pub trait Database: Sync + Send { ) -> Result; /// Get `Torrent` from `InfoHash`. - async fn get_torrent_from_info_hash(&self, info_hash: &InfoHash) -> Result { - let torrent_info = self.get_torrent_info_from_infohash(*info_hash).await?; + async fn get_torrent_from_infohash(&self, infohash: &InfoHash) -> Result { + let torrent_info = self.get_torrent_info_from_infohash(infohash).await?; let torrent_files = self.get_torrent_files_from_id(torrent_info.torrent_id).await?; @@ -189,7 +189,7 @@ pub trait Database: Sync + Send { async fn get_torrent_info_from_id(&self, torrent_id: i64) -> Result; /// Get torrent's info as `DbTorrentInfo` from torrent `InfoHash`. - async fn get_torrent_info_from_infohash(&self, info_hash: InfoHash) -> Result; + async fn get_torrent_info_from_infohash(&self, info_hash: &InfoHash) -> Result; /// Get all torrent's files as `Vec` from `torrent_id`. async fn get_torrent_files_from_id(&self, torrent_id: i64) -> Result, DatabaseError>; @@ -200,6 +200,9 @@ pub trait Database: Sync + Send { /// Get `TorrentListing` from `torrent_id`. async fn get_torrent_listing_from_id(&self, torrent_id: i64) -> Result; + /// Get `TorrentListing` from `InfoHash`. + async fn get_torrent_listing_from_infohash(&self, infohash: &InfoHash) -> Result; + /// Get all torrents as `Vec`. async fn get_all_torrents_compact(&self) -> Result, DatabaseError>; diff --git a/src/databases/mysql.rs b/src/databases/mysql.rs index 252a10e2..668e94bc 100644 --- a/src/databases/mysql.rs +++ b/src/databases/mysql.rs @@ -406,7 +406,7 @@ impl Database for MysqlDatabase { let torrent_id = query("INSERT INTO torrust_torrents (uploader_id, category_id, info_hash, size, name, pieces, piece_length, private, root_hash, date_uploaded) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, UTC_TIMESTAMP())") .bind(uploader_id) .bind(category_id) - .bind(info_hash) + .bind(info_hash.to_uppercase()) .bind(torrent.file_size()) .bind(torrent.info.name.to_string()) .bind(pieces) @@ -539,11 +539,11 @@ impl Database for MysqlDatabase { .map_err(|_| DatabaseError::TorrentNotFound) } - async fn get_torrent_info_from_infohash(&self, info_hash: InfoHash) -> Result { + async fn get_torrent_info_from_infohash(&self, infohash: &InfoHash) -> Result { query_as::<_, DbTorrentInfo>( - "SELECT torrent_id, info_hash, name, pieces, piece_length, private, root_hash FROM torrust_torrents WHERE torrent_id = ?", + "SELECT torrent_id, info_hash, name, pieces, piece_length, private, root_hash FROM torrust_torrents WHERE info_hash = ?", ) - .bind(info_hash.to_string()) + .bind(infohash.to_hex_string().to_uppercase()) // `info_hash` is stored as uppercase hex string .fetch_one(&self.pool) .await .map_err(|_| DatabaseError::TorrentNotFound) @@ -596,6 +596,24 @@ impl Database for MysqlDatabase { .map_err(|_| DatabaseError::TorrentNotFound) } + async fn get_torrent_listing_from_infohash(&self, infohash: &InfoHash) -> Result { + query_as::<_, TorrentListing>( + "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, DATE_FORMAT(tt.date_uploaded, '%Y-%m-%d %H:%i:%s') AS date_uploaded, tt.size AS file_size, + CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders, + CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers + FROM torrust_torrents tt + INNER JOIN torrust_user_profiles tp ON tt.uploader_id = tp.user_id + INNER JOIN torrust_torrent_info ti ON tt.torrent_id = ti.torrent_id + LEFT JOIN torrust_torrent_tracker_stats ts ON tt.torrent_id = ts.torrent_id + WHERE tt.info_hash = ? + GROUP BY torrent_id" + ) + .bind(infohash.to_hex_string().to_uppercase()) // `info_hash` is stored as uppercase hex string + .fetch_one(&self.pool) + .await + .map_err(|_| DatabaseError::TorrentNotFound) + } + async fn get_all_torrents_compact(&self) -> Result, DatabaseError> { query_as::<_, TorrentCompact>("SELECT torrent_id, info_hash FROM torrust_torrents") .fetch_all(&self.pool) diff --git a/src/databases/sqlite.rs b/src/databases/sqlite.rs index ee7814c6..943d5e2d 100644 --- a/src/databases/sqlite.rs +++ b/src/databases/sqlite.rs @@ -401,7 +401,7 @@ impl Database for SqliteDatabase { let torrent_id = query("INSERT INTO torrust_torrents (uploader_id, category_id, info_hash, size, name, pieces, piece_length, private, root_hash, date_uploaded) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, strftime('%Y-%m-%d %H:%M:%S',DATETIME('now', 'utc')))") .bind(uploader_id) .bind(category_id) - .bind(info_hash) + .bind(info_hash.to_uppercase()) .bind(torrent.file_size()) .bind(torrent.info.name.to_string()) .bind(pieces) @@ -534,11 +534,11 @@ impl Database for SqliteDatabase { .map_err(|_| DatabaseError::TorrentNotFound) } - async fn get_torrent_info_from_infohash(&self, info_hash: InfoHash) -> Result { + async fn get_torrent_info_from_infohash(&self, infohash: &InfoHash) -> Result { query_as::<_, DbTorrentInfo>( "SELECT torrent_id, info_hash, name, pieces, piece_length, private, root_hash FROM torrust_torrents WHERE info_hash = ?", ) - .bind(info_hash.to_string().to_uppercase()) // info_hash is stored as uppercase + .bind(infohash.to_hex_string().to_uppercase()) // `info_hash` is stored as uppercase hex string .fetch_one(&self.pool) .await .map_err(|_| DatabaseError::TorrentNotFound) @@ -591,6 +591,24 @@ impl Database for SqliteDatabase { .map_err(|_| DatabaseError::TorrentNotFound) } + async fn get_torrent_listing_from_infohash(&self, infohash: &InfoHash) -> Result { + query_as::<_, TorrentListing>( + "SELECT tt.torrent_id, tp.username AS uploader, tt.info_hash, ti.title, ti.description, tt.category_id, tt.date_uploaded, tt.size AS file_size, + CAST(COALESCE(sum(ts.seeders),0) as signed) as seeders, + CAST(COALESCE(sum(ts.leechers),0) as signed) as leechers + FROM torrust_torrents tt + INNER JOIN torrust_user_profiles tp ON tt.uploader_id = tp.user_id + INNER JOIN torrust_torrent_info ti ON tt.torrent_id = ti.torrent_id + LEFT JOIN torrust_torrent_tracker_stats ts ON tt.torrent_id = ts.torrent_id + WHERE tt.info_hash = ? + GROUP BY ts.torrent_id" + ) + .bind(infohash.to_string().to_uppercase()) // `info_hash` is stored as uppercase + .fetch_one(&self.pool) + .await + .map_err(|_| DatabaseError::TorrentNotFound) + } + async fn get_all_torrents_compact(&self) -> Result, DatabaseError> { query_as::<_, TorrentCompact>("SELECT torrent_id, info_hash FROM torrust_torrents") .fetch_all(&self.pool) diff --git a/src/routes/torrent.rs b/src/routes/torrent.rs index 411ad6eb..55395f2e 100644 --- a/src/routes/torrent.rs +++ b/src/routes/torrent.rs @@ -23,10 +23,10 @@ pub fn init_routes(cfg: &mut web::ServiceConfig) { .service(web::resource("/upload").route(web::post().to(upload_torrent))) .service(web::resource("/download/{info_hash}").route(web::get().to(download_torrent_handler))) .service( - web::resource("/{id}") - .route(web::get().to(get_torrent)) - .route(web::put().to(update_torrent)) - .route(web::delete().to(delete_torrent)), + web::resource("/{info_hash}") + .route(web::get().to(get_torrent_handler)) + .route(web::put().to(update_torrent_handler)) + .route(web::delete().to(delete_torrent_handler)), ), ); cfg.service(web::scope("/torrents").service(web::resource("").route(web::get().to(get_torrents)))); @@ -129,12 +129,12 @@ pub async fn upload_torrent(req: HttpRequest, payload: Multipart, app_data: WebA /// /// Returns `ServiceError::BadRequest` if the torrent infohash is invalid. pub async fn download_torrent_handler(req: HttpRequest, app_data: WebAppData) -> ServiceResult { - let info_hash = get_torrent_info_hash_from_request(&req)?; + let info_hash = get_torrent_infohash_from_request(&req)?; // optional let user = app_data.auth.get_user_compact_from_request(&req).await; - let mut torrent = app_data.database.get_torrent_from_info_hash(&info_hash).await?; + let mut torrent = app_data.database.get_torrent_from_infohash(&info_hash).await?; let settings = app_data.cfg.settings.read().await; @@ -166,18 +166,26 @@ pub async fn download_torrent_handler(req: HttpRequest, app_data: WebAppData) -> Ok(HttpResponse::Ok().content_type("application/x-bittorrent").body(buffer)) } -pub async fn get_torrent(req: HttpRequest, app_data: WebAppData) -> ServiceResult { +pub async fn get_torrent_handler(req: HttpRequest, app_data: WebAppData) -> ServiceResult { // optional let user = app_data.auth.get_user_compact_from_request(&req).await; let settings = app_data.cfg.settings.read().await; - let torrent_id = get_torrent_id_from_request(&req)?; + let infohash = get_torrent_infohash_from_request(&req)?; - let torrent_listing = app_data.database.get_torrent_listing_from_id(torrent_id).await?; + println!("infohash: {}", infohash); + + let torrent_listing = app_data.database.get_torrent_listing_from_infohash(&infohash).await?; + + let torrent_id = torrent_listing.torrent_id; + + println!("torrent_listing: {:#?}", torrent_listing); let category = app_data.database.get_category_from_id(torrent_listing.category_id).await?; + println!("category: {:#?}", category); + let mut torrent_response = TorrentResponse::from_listing(torrent_listing); torrent_response.category = category; @@ -188,8 +196,12 @@ pub async fn get_torrent(req: HttpRequest, app_data: WebAppData) -> ServiceResul torrent_response.files = app_data.database.get_torrent_files_from_id(torrent_id).await?; + println!("torrent_response.files: {:#?}", torrent_response.files); + if torrent_response.files.len() == 1 { - let torrent_info = app_data.database.get_torrent_info_from_id(torrent_id).await?; + let torrent_info = app_data.database.get_torrent_info_from_infohash(&infohash).await?; + + println!("torrent_info: {:#?}", torrent_info); torrent_response .files @@ -203,6 +215,8 @@ pub async fn get_torrent(req: HttpRequest, app_data: WebAppData) -> ServiceResul .await .map(|v| v.into_iter().flatten().collect())?; + println!("trackers: {:#?}", torrent_response.trackers); + // add tracker url match user { Ok(user) => { @@ -249,16 +263,16 @@ pub async fn get_torrent(req: HttpRequest, app_data: WebAppData) -> ServiceResul Ok(HttpResponse::Ok().json(OkResponse { data: torrent_response })) } -pub async fn update_torrent( +pub async fn update_torrent_handler( req: HttpRequest, payload: web::Json, app_data: WebAppData, ) -> ServiceResult { let user = app_data.auth.get_user_compact_from_request(&req).await?; - let torrent_id = get_torrent_id_from_request(&req)?; + let infohash = get_torrent_infohash_from_request(&req)?; - let torrent_listing = app_data.database.get_torrent_listing_from_id(torrent_id).await?; + let torrent_listing = app_data.database.get_torrent_listing_from_infohash(&infohash).await?; // check if user is owner or administrator if torrent_listing.uploader != user.username && !user.administrator { @@ -267,22 +281,31 @@ pub async fn update_torrent( // update torrent title if let Some(title) = &payload.title { - app_data.database.update_torrent_title(torrent_id, title).await?; + app_data + .database + .update_torrent_title(torrent_listing.torrent_id, title) + .await?; } // update torrent description if let Some(description) = &payload.description { - app_data.database.update_torrent_description(torrent_id, description).await?; + app_data + .database + .update_torrent_description(torrent_listing.torrent_id, description) + .await?; } - let torrent_listing = app_data.database.get_torrent_listing_from_id(torrent_id).await?; + let torrent_listing = app_data + .database + .get_torrent_listing_from_id(torrent_listing.torrent_id) + .await?; let torrent_response = TorrentResponse::from_listing(torrent_listing); Ok(HttpResponse::Ok().json(OkResponse { data: torrent_response })) } -pub async fn delete_torrent(req: HttpRequest, app_data: WebAppData) -> ServiceResult { +pub async fn delete_torrent_handler(req: HttpRequest, app_data: WebAppData) -> ServiceResult { let user = app_data.auth.get_user_compact_from_request(&req).await?; // check if user is administrator @@ -290,12 +313,12 @@ pub async fn delete_torrent(req: HttpRequest, app_data: WebAppData) -> ServiceRe return Err(ServiceError::Unauthorized); } - let torrent_id = get_torrent_id_from_request(&req)?; + let infohash = get_torrent_infohash_from_request(&req)?; // needed later for removing torrent from tracker whitelist - let torrent_listing = app_data.database.get_torrent_listing_from_id(torrent_id).await?; + let torrent_listing = app_data.database.get_torrent_listing_from_infohash(&infohash).await?; - app_data.database.delete_torrent(torrent_id).await?; + app_data.database.delete_torrent(torrent_listing.torrent_id).await?; // remove info_hash from tracker whitelist let _ = app_data @@ -304,7 +327,9 @@ pub async fn delete_torrent(req: HttpRequest, app_data: WebAppData) -> ServiceRe .await; Ok(HttpResponse::Ok().json(OkResponse { - data: NewTorrentResponse { torrent_id }, + data: NewTorrentResponse { + torrent_id: torrent_listing.torrent_id, + }, })) } @@ -332,17 +357,7 @@ pub async fn get_torrents(params: Query, app_data: WebAppData) -> Ok(HttpResponse::Ok().json(OkResponse { data: torrents_response })) } -fn get_torrent_id_from_request(req: &HttpRequest) -> Result { - match req.match_info().get("id") { - None => Err(ServiceError::BadRequest), - Some(torrent_id) => match torrent_id.parse() { - Err(_) => Err(ServiceError::BadRequest), - Ok(v) => Ok(v), - }, - } -} - -fn get_torrent_info_hash_from_request(req: &HttpRequest) -> Result { +fn get_torrent_infohash_from_request(req: &HttpRequest) -> Result { match req.match_info().get("info_hash") { None => Err(ServiceError::BadRequest), Some(info_hash) => match InfoHash::from_str(info_hash) { diff --git a/tests/common/client.rs b/tests/common/client.rs index c3501519..6ff016bc 100644 --- a/tests/common/client.rs +++ b/tests/common/client.rs @@ -5,7 +5,7 @@ use super::connection_info::ConnectionInfo; use super::contexts::category::forms::{AddCategoryForm, DeleteCategoryForm}; use super::contexts::settings::form::UpdateSettings; use super::contexts::torrent::forms::UpdateTorrentFrom; -use super::contexts::torrent::requests::{InfoHash, TorrentId}; +use super::contexts::torrent::requests::InfoHash; use super::contexts::user::forms::{LoginForm, RegistrationForm, TokenRenewalForm, TokenVerificationForm, Username}; use super::http::{Query, ReqwestQuery}; use super::responses::{self, BinaryResponse, TextResponse}; @@ -93,23 +93,25 @@ impl Client { self.http_client.get("torrents", Query::empty()).await } - pub async fn get_torrent(&self, id: TorrentId) -> TextResponse { - self.http_client.get(&format!("torrent/{id}"), Query::empty()).await + pub async fn get_torrent(&self, infohash: &InfoHash) -> TextResponse { + self.http_client.get(&format!("torrent/{infohash}"), Query::empty()).await } - pub async fn delete_torrent(&self, id: TorrentId) -> TextResponse { - self.http_client.delete(&format!("torrent/{id}")).await + pub async fn delete_torrent(&self, infohash: &InfoHash) -> TextResponse { + self.http_client.delete(&format!("torrent/{infohash}")).await } - pub async fn update_torrent(&self, id: TorrentId, update_torrent_form: UpdateTorrentFrom) -> TextResponse { - self.http_client.put(&format!("torrent/{id}"), &update_torrent_form).await + pub async fn update_torrent(&self, infohash: &InfoHash, update_torrent_form: UpdateTorrentFrom) -> TextResponse { + self.http_client + .put(&format!("torrent/{infohash}"), &update_torrent_form) + .await } pub async fn upload_torrent(&self, form: multipart::Form) -> TextResponse { self.http_client.post_multipart("torrent/upload", form).await } - pub async fn download_torrent(&self, info_hash: InfoHash) -> responses::BinaryResponse { + pub async fn download_torrent(&self, info_hash: &InfoHash) -> responses::BinaryResponse { self.http_client .get_binary(&format!("torrent/download/{info_hash}"), Query::empty()) .await diff --git a/tests/common/contexts/torrent/fixtures.rs b/tests/common/contexts/torrent/fixtures.rs index 00e26ecf..34146adf 100644 --- a/tests/common/contexts/torrent/fixtures.rs +++ b/tests/common/contexts/torrent/fixtures.rs @@ -7,6 +7,7 @@ use uuid::Uuid; use super::file::{create_torrent, parse_torrent, TorrentFileInfo}; use super::forms::{BinaryFile, UploadTorrentMultipartForm}; +use super::requests::InfoHash; use super::responses::Id; use crate::common::contexts::category::fixtures::software_predefined_category_name; @@ -91,7 +92,7 @@ impl TestTorrent { } } - pub fn info_hash(&self) -> String { + pub fn infohash(&self) -> InfoHash { self.file_info.info_hash.clone() } } diff --git a/tests/common/contexts/torrent/requests.rs b/tests/common/contexts/torrent/requests.rs index 946c475a..1d4ac583 100644 --- a/tests/common/contexts/torrent/requests.rs +++ b/tests/common/contexts/torrent/requests.rs @@ -1,2 +1 @@ -pub type TorrentId = i64; pub type InfoHash = String; diff --git a/tests/e2e/contexts/torrent/contract.rs b/tests/e2e/contexts/torrent/contract.rs index cca181ac..1a049890 100644 --- a/tests/e2e/contexts/torrent/contract.rs +++ b/tests/e2e/contexts/torrent/contract.rs @@ -20,6 +20,7 @@ mod for_guests { use crate::common::client::Client; use crate::common::contexts::category::fixtures::software_predefined_category_id; use crate::common::contexts::torrent::asserts::assert_expected_torrent_details; + use crate::common::contexts::torrent::requests::InfoHash; use crate::common::contexts::torrent::responses::{ Category, File, TorrentDetails, TorrentDetailsResponse, TorrentListResponse, }; @@ -53,7 +54,7 @@ mod for_guests { } #[tokio::test] - async fn it_should_allow_guests_to_get_torrent_details_searching_by_id() { + async fn it_should_allow_guests_to_get_torrent_details_searching_by_infohash() { let mut env = TestEnv::new(); env.start().await; @@ -67,7 +68,7 @@ mod for_guests { let uploader = new_logged_in_user(&env).await; let (test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; - let response = client.get_torrent(uploaded_torrent.torrent_id).await; + let response = client.get_torrent(&test_torrent.infohash()).await; let torrent_details_response: TorrentDetailsResponse = serde_json::from_str(&response.body).unwrap(); @@ -116,7 +117,7 @@ mod for_guests { } #[tokio::test] - async fn it_should_allow_guests_to_download_a_torrent_file_searching_by_id() { + async fn it_should_allow_guests_to_download_a_torrent_file_searching_by_infohash() { let mut env = TestEnv::new(); env.start().await; @@ -130,7 +131,7 @@ mod for_guests { let uploader = new_logged_in_user(&env).await; let (test_torrent, _torrent_listed_in_index) = upload_random_torrent_to_index(&uploader, &env).await; - let response = client.download_torrent(test_torrent.info_hash()).await; + let response = client.download_torrent(&test_torrent.infohash()).await; let torrent = decode_torrent(&response.bytes).expect("could not decode downloaded torrent"); let uploaded_torrent = @@ -152,9 +153,9 @@ mod for_guests { let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); - let non_existing_info_hash = "443c7602b4fde83d1154d6d9da48808418b181b6".to_string(); + let non_existing_info_hash: InfoHash = "443c7602b4fde83d1154d6d9da48808418b181b6".to_string(); - let response = client.download_torrent(non_existing_info_hash).await; + let response = client.download_torrent(&non_existing_info_hash).await; // code-review: should this be 404? assert_eq!(response.status, 400); @@ -173,9 +174,9 @@ mod for_guests { let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); let uploader = new_logged_in_user(&env).await; - let (_test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; + let (test_torrent, _uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; - let response = client.delete_torrent(uploaded_torrent.torrent_id).await; + let response = client.delete_torrent(&test_torrent.infohash()).await; assert_eq!(response.status, 401); } @@ -321,7 +322,7 @@ mod for_authenticated_users { let client = Client::authenticated(&env.server_socket_addr().unwrap(), &downloader.token); // When the user downloads the torrent - let response = client.download_torrent(test_torrent.info_hash()).await; + let response = client.download_torrent(&test_torrent.infohash()).await; let torrent = decode_torrent(&response.bytes).expect("could not decode downloaded torrent"); @@ -355,11 +356,11 @@ mod for_authenticated_users { } let uploader = new_logged_in_user(&env).await; - let (_test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; + let (test_torrent, _uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &uploader.token); - let response = client.delete_torrent(uploaded_torrent.torrent_id).await; + let response = client.delete_torrent(&test_torrent.infohash()).await; assert_eq!(response.status, 403); } @@ -376,7 +377,7 @@ mod for_authenticated_users { // Given a users uploads a torrent let uploader = new_logged_in_user(&env).await; - let (test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; + let (test_torrent, _uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; // Then another non admin user should not be able to update the torrent let not_the_uploader = new_logged_in_user(&env).await; @@ -387,7 +388,7 @@ mod for_authenticated_users { let response = client .update_torrent( - uploaded_torrent.torrent_id, + &test_torrent.infohash(), UpdateTorrentFrom { title: Some(new_title.clone()), description: Some(new_description.clone()), @@ -418,7 +419,7 @@ mod for_authenticated_users { } let uploader = new_logged_in_user(&env).await; - let (test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; + let (test_torrent, _uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &uploader.token); @@ -427,7 +428,7 @@ mod for_authenticated_users { let response = client .update_torrent( - uploaded_torrent.torrent_id, + &test_torrent.infohash(), UpdateTorrentFrom { title: Some(new_title.clone()), description: Some(new_description.clone()), @@ -454,7 +455,7 @@ mod for_authenticated_users { use crate::e2e::environment::TestEnv; #[tokio::test] - async fn it_should_allow_admins_to_delete_torrents_searching_by_id() { + async fn it_should_allow_admins_to_delete_torrents_searching_by_infohash() { let mut env = TestEnv::new(); env.start().await; @@ -464,12 +465,12 @@ mod for_authenticated_users { } let uploader = new_logged_in_user(&env).await; - let (_test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; + let (test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; let admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &admin.token); - let response = client.delete_torrent(uploaded_torrent.torrent_id).await; + let response = client.delete_torrent(&test_torrent.infohash()).await; let deleted_torrent_response: DeletedTorrentResponse = serde_json::from_str(&response.body).unwrap(); @@ -488,7 +489,7 @@ mod for_authenticated_users { } let uploader = new_logged_in_user(&env).await; - let (test_torrent, uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; + let (test_torrent, _uploaded_torrent) = upload_random_torrent_to_index(&uploader, &env).await; let logged_in_admin = new_logged_in_admin(&env).await; let client = Client::authenticated(&env.server_socket_addr().unwrap(), &logged_in_admin.token); @@ -498,7 +499,7 @@ mod for_authenticated_users { let response = client .update_torrent( - uploaded_torrent.torrent_id, + &test_torrent.infohash(), UpdateTorrentFrom { title: Some(new_title.clone()), description: Some(new_description.clone()),