From 06913eabccb62a7bdf4bad1da26f47a50f749a23 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 11 Oct 2024 15:06:09 +0200 Subject: [PATCH] test: new test for admin users to update someone elses torrent --- .../web/api/v1/contexts/torrent/contract.rs | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/e2e/web/api/v1/contexts/torrent/contract.rs b/tests/e2e/web/api/v1/contexts/torrent/contract.rs index 67e7b588..855bf5f9 100644 --- a/tests/e2e/web/api/v1/contexts/torrent/contract.rs +++ b/tests/e2e/web/api/v1/contexts/torrent/contract.rs @@ -1367,7 +1367,9 @@ mod and_admins { common::{ client::Client, contexts::torrent::{ - fixtures::random_torrent, forms::UploadTorrentMultipartForm, responses::TorrentListResponse, + fixtures::random_torrent, + forms::{UpdateTorrentFrom, UploadTorrentMultipartForm}, + responses::TorrentListResponse, }, http::Query, }, @@ -1552,5 +1554,42 @@ mod and_admins { assert_eq!(response.status, 200); } + + #[tokio::test] + async fn it_should_allow_admin_users_to_update_someone_elses_torrents() { + let mut env = TestEnv::new(); + env.start(api::Version::V1).await; + + if !env.provides_a_tracker() { + println!("test skipped. It requires a tracker to be running."); + return; + } + + // 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; + + // Then admin user should be able to update the torrent + let admin = new_logged_in_admin(&env).await; + + let client = Client::authenticated(&env.server_socket_addr().unwrap(), &admin.token); + + let new_title = format!("{}-new-title", test_torrent.index_info.title); + let new_description = format!("{}-new-description", test_torrent.index_info.description); + + let response = client + .update_torrent( + &test_torrent.file_info_hash(), + UpdateTorrentFrom { + title: Some(new_title.clone()), + description: Some(new_description.clone()), + category: None, + tags: None, + }, + ) + .await; + + assert_eq!(response.status, 200); + } } }