From b0a458cd0ed8079fb269c94e7cb55dda17bd858e Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Tue, 24 Sep 2024 10:42:01 +0100 Subject: [PATCH 01/10] develop: bump to version 3.0.0-develop --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d6dd97a..dcafe906 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3825,7 +3825,7 @@ dependencies = [ [[package]] name = "torrust-index" -version = "3.0.0-rc.1" +version = "3.0.0-develop" dependencies = [ "anyhow", "argon2", @@ -3891,7 +3891,7 @@ dependencies = [ [[package]] name = "torrust-index-located-error" -version = "3.0.0-rc.1" +version = "3.0.0-develop" dependencies = [ "thiserror", "tracing", diff --git a/Cargo.toml b/Cargo.toml index 68daa021..7750a18c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ license = "AGPL-3.0-only" publish = true repository = "https://github.com/torrust/torrust-tracker" rust-version = "1.72" -version = "3.0.0-rc.1" +version = "3.0.0-develop" [profile.dev.package.sqlx-macros] opt-level = 3 @@ -89,7 +89,7 @@ text-to-png = "0" thiserror = "1" tokio = { version = "1", features = ["fs", "io-util", "macros", "net", "rt-multi-thread", "signal", "sync", "time"] } toml = "0" -torrust-index-located-error = { version = "3.0.0-rc.1", path = "packages/located-error" } +torrust-index-located-error = { version = "3.0.0-develop", path = "packages/located-error" } tower = { version = "0.4", features = ["timeout"] } tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] } trace = "0.1.7" From 840e1d86063d29fac5dbc20c4f49ed87a4dd262a Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Tue, 24 Sep 2024 11:09:14 +0100 Subject: [PATCH 02/10] ci: move testing with MySQL to a new workflow Integration tests with MySQL are working locally but not in the GitHub Runner. We don't know yet why. See: https://github.com/torrust/torrust-index/issues/580 That's affecting deployments and releases. We move the execution to a new temporary workflows until it's fixed. Be sure to execute it locally before opening new PR: ```console ./contrib/dev-tools/container/e2e/mysql/run-e2e-tests.sh ``` --- .github/workflows/e2e.yaml | 44 ++++++++++++++++++++++++++++++++++ .github/workflows/testing.yaml | 6 ++--- 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/e2e.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml new file mode 100644 index 00000000..20176374 --- /dev/null +++ b/.github/workflows/e2e.yaml @@ -0,0 +1,44 @@ +# Temporary execution of E2E tests using MySQL becuase it's failing +# in the `testing.yml` workflows and affects deployments and releases. +# See https://github.com/torrust/torrust-index/issues/580 +name: E2E Testing + +on: + push: + pull_request: + +env: + CARGO_TERM_COLOR: always + +jobs: + e2e: + name: E2E + runs-on: ubuntu-latest + + strategy: + matrix: + toolchain: [stable, nightly] + + steps: + - id: checkout + name: Checkout Repository + uses: actions/checkout@v4 + + - id: setup + name: Setup Toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ matrix.toolchain }} + + - id: cache + name: Enable Job Cache + uses: Swatinem/rust-cache@v2 + + # Temporary Cleaning to avoid Rust Compiler Bug + - id: clean + name: Make Build Clean + run: cargo clean + + - id: test-mysql + name: Run Integration Tests (MySQL) + run: ./contrib/dev-tools/container/e2e/mysql/run-e2e-tests.sh diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 075ae057..4c3dfebc 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -156,6 +156,6 @@ jobs: name: Run Integration Tests (SQLite) run: ./contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh - - id: test-mysql - name: Run Integration Tests (MySQL) - run: ./contrib/dev-tools/container/e2e/mysql/run-e2e-tests.sh + #- id: test-mysql + # name: Run Integration Tests (MySQL) + # run: ./contrib/dev-tools/container/e2e/mysql/run-e2e-tests.sh From 3c046b10b26d5407b98ba21bf802a41130fb2013 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 25 Sep 2024 23:44:06 +0200 Subject: [PATCH 03/10] refactor: move authorization test for guests to new mod --- .../web/api/v1/contexts/torrent/contract.rs | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/tests/e2e/web/api/v1/contexts/torrent/contract.rs b/tests/e2e/web/api/v1/contexts/torrent/contract.rs index ed3b4f33..ed48c05a 100644 --- a/tests/e2e/web/api/v1/contexts/torrent/contract.rs +++ b/tests/e2e/web/api/v1/contexts/torrent/contract.rs @@ -23,8 +23,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::fixtures::{random_torrent, TestTorrent}; - use crate::common::contexts::torrent::forms::UploadTorrentMultipartForm; + use crate::common::contexts::torrent::fixtures::TestTorrent; use crate::common::contexts::torrent::requests::InfoHash; use crate::common::contexts::torrent::responses::{ Category, File, TorrentDetails, TorrentDetailsResponse, TorrentListResponse, @@ -429,22 +428,6 @@ mod for_guests { assert_eq!(response.status, 404); } - #[tokio::test] - async fn it_should_not_allow_guests_to_upload_torrents() { - let mut env = TestEnv::new(); - env.start(api::Version::V1).await; - - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); - - let test_torrent = random_torrent(); - - let form: UploadTorrentMultipartForm = test_torrent.index_info.into(); - - let response = client.upload_torrent(form.into()).await; - - assert_eq!(response.status, 401); - } - #[tokio::test] async fn it_should_not_allow_guests_to_delete_torrents() { let mut env = TestEnv::new(); @@ -464,6 +447,31 @@ mod for_guests { assert_eq!(response.status, 401); } + + mod authorization { + use torrust_index::web::api; + + use crate::common::client::Client; + use crate::common::contexts::torrent::fixtures::random_torrent; + use crate::common::contexts::torrent::forms::UploadTorrentMultipartForm; + use crate::e2e::environment::TestEnv; + + #[tokio::test] + async fn it_should_not_allow_guests_to_upload_torrents() { + let mut env = TestEnv::new(); + env.start(api::Version::V1).await; + + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); + + let test_torrent = random_torrent(); + + let form: UploadTorrentMultipartForm = test_torrent.index_info.into(); + + let response = client.upload_torrent(form.into()).await; + + assert_eq!(response.status, 401); + } + } } mod for_authenticated_users { From 6df7a7e683ae642cfe6ecb1ad5c39b39f6597825 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 26 Sep 2024 13:12:24 +0200 Subject: [PATCH 04/10] refactor: moved test to new authorization mod --- .../web/api/v1/contexts/torrent/contract.rs | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/e2e/web/api/v1/contexts/torrent/contract.rs b/tests/e2e/web/api/v1/contexts/torrent/contract.rs index ed48c05a..b3064b20 100644 --- a/tests/e2e/web/api/v1/contexts/torrent/contract.rs +++ b/tests/e2e/web/api/v1/contexts/torrent/contract.rs @@ -428,26 +428,6 @@ mod for_guests { assert_eq!(response.status, 404); } - #[tokio::test] - async fn it_should_not_allow_guests_to_delete_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; - } - - 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 response = client.delete_torrent(&test_torrent.file_info_hash()).await; - - assert_eq!(response.status, 401); - } - mod authorization { use torrust_index::web::api; @@ -455,6 +435,8 @@ mod for_guests { use crate::common::contexts::torrent::fixtures::random_torrent; use crate::common::contexts::torrent::forms::UploadTorrentMultipartForm; use crate::e2e::environment::TestEnv; + use crate::e2e::web::api::v1::contexts::torrent::steps::upload_random_torrent_to_index; + use crate::e2e::web::api::v1::contexts::user::steps::new_logged_in_user; #[tokio::test] async fn it_should_not_allow_guests_to_upload_torrents() { @@ -471,6 +453,26 @@ mod for_guests { assert_eq!(response.status, 401); } + + #[tokio::test] + async fn it_should_not_allow_guests_to_delete_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; + } + + 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 response = client.delete_torrent(&test_torrent.file_info_hash()).await; + + assert_eq!(response.status, 401); + } } } From e3baeda82fbcc94958484646b73801c4397cfc0f Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 27 Sep 2024 12:36:37 +0200 Subject: [PATCH 05/10] test: new authorization test for guests to download a torrent file searching by info hash --- .../web/api/v1/contexts/torrent/contract.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/e2e/web/api/v1/contexts/torrent/contract.rs b/tests/e2e/web/api/v1/contexts/torrent/contract.rs index b3064b20..c8082e36 100644 --- a/tests/e2e/web/api/v1/contexts/torrent/contract.rs +++ b/tests/e2e/web/api/v1/contexts/torrent/contract.rs @@ -473,6 +473,28 @@ mod for_guests { assert_eq!(response.status, 401); } + + #[tokio::test] + async fn it_should_allow_guests_to_download_a_torrent_file_searching_by_info_hash() { + 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; + } + + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); + let uploader = new_logged_in_user(&env).await; + + // Upload + let (test_torrent, _torrent_listed_in_index) = upload_random_torrent_to_index(&uploader, &env).await; + + // Download + let response = client.download_torrent(&test_torrent.file_info_hash()).await; + + assert_eq!(response.status, 200); + } } } From 17de7297412de225b3525396ee215f50dcda9a57 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 27 Sep 2024 17:22:32 +0200 Subject: [PATCH 06/10] refactor: moved test to authorization mod --- .../web/api/v1/contexts/torrent/contract.rs | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/tests/e2e/web/api/v1/contexts/torrent/contract.rs b/tests/e2e/web/api/v1/contexts/torrent/contract.rs index c8082e36..909ec230 100644 --- a/tests/e2e/web/api/v1/contexts/torrent/contract.rs +++ b/tests/e2e/web/api/v1/contexts/torrent/contract.rs @@ -33,29 +33,6 @@ mod for_guests { use crate::e2e::web::api::v1::contexts::torrent::steps::{upload_random_torrent_to_index, upload_test_torrent}; use crate::e2e::web::api::v1::contexts::user::steps::new_logged_in_user; - #[tokio::test] - async fn it_should_allow_guests_to_get_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; - } - - let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); - - let uploader = new_logged_in_user(&env).await; - let (_test_torrent, _indexed_torrent) = upload_random_torrent_to_index(&uploader, &env).await; - - let response = client.get_torrents(Query::empty()).await; - - let torrent_list_response: TorrentListResponse = serde_json::from_str(&response.body).unwrap(); - - assert!(torrent_list_response.data.total > 0); - assert!(response.is_json_and_ok()); - } - #[tokio::test] async fn it_should_allow_to_get_torrents_with_pagination() { let mut env = TestEnv::new(); @@ -434,6 +411,8 @@ mod for_guests { use crate::common::client::Client; use crate::common::contexts::torrent::fixtures::random_torrent; use crate::common::contexts::torrent::forms::UploadTorrentMultipartForm; + use crate::common::contexts::torrent::responses::TorrentListResponse; + use crate::common::http::Query; use crate::e2e::environment::TestEnv; use crate::e2e::web::api::v1::contexts::torrent::steps::upload_random_torrent_to_index; use crate::e2e::web::api::v1::contexts::user::steps::new_logged_in_user; @@ -495,6 +474,29 @@ mod for_guests { assert_eq!(response.status, 200); } + + #[tokio::test] + async fn it_should_allow_guests_to_get_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; + } + + let client = Client::unauthenticated(&env.server_socket_addr().unwrap()); + + let uploader = new_logged_in_user(&env).await; + let (_test_torrent, _indexed_torrent) = upload_random_torrent_to_index(&uploader, &env).await; + + let response = client.get_torrents(Query::empty()).await; + + let torrent_list_response: TorrentListResponse = serde_json::from_str(&response.body).unwrap(); + + assert!(torrent_list_response.data.total > 0); + assert!(response.is_json_and_ok()); + } } } From 15adcb9aafda4a616c7a4f9483ba0d495fac7098 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Wed, 2 Oct 2024 09:17:19 +0100 Subject: [PATCH 07/10] docs: [#738] fix command --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 057a4bc7..e2934921 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,7 +112,7 @@ //! && mkdir -p ./storage/database //! ``` //! -//! Then you can run it with: `./target/release/main` +//! Then you can run it with: `./target/release/torrust-index` //! //! ## Run with docker //! From fdf62e9b3ed054fa236966e08e62dfa9cd0a2975 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Wed, 2 Oct 2024 09:20:44 +0100 Subject: [PATCH 08/10] docs: [#739] fix command to run with docker --- src/lib.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e2934921..13586a17 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,13 +119,21 @@ //! You can run the index with a pre-built docker image: //! //! ```text -//! mkdir -p ./storage/database \ +//! cd /tmp \ +//! && mkdir torrust-index \ +//! && cd torrust-index \ +//! && mkdir -p ./storage/index/lib/database \ +//! && mkdir -p ./storage/index/log \ +//! && mkdir -p ./storage/index/etc \ +//! && sqlite3 "./storage/index/lib/database/sqlite3.db" "VACUUM;" \ //! && export USER_ID=1000 \ //! && docker run -it \ -//! --user="$USER_ID" \ +//! --env USER_ID="$USER_ID" \ //! --publish 3001:3001/tcp \ -//! --volume "$(pwd)/storage":"/app/storage" \ -//! torrust/index +//! --volume "$(pwd)/storage/index/lib":"/var/lib/torrust/index" \ +//! --volume "$(pwd)/storage/index/log":"/var/log/torrust/index" \ +//! --volume "$(pwd)/storage/index/etc":"/etc/torrust/index" \ +//! torrust/index:develop //! ``` //! //! For more information about using docker visit the [tracker docker documentation](https://github.com/torrust/torrust-index/tree/develop/docker). From 7f605b136750ab9e40979156d5be4cc267db2de6 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Wed, 2 Oct 2024 09:33:32 +0100 Subject: [PATCH 09/10] fix: clippy errors --- src/services/authorization.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/services/authorization.rs b/src/services/authorization.rs index 2861ddd9..e6678ac1 100644 --- a/src/services/authorization.rs +++ b/src/services/authorization.rs @@ -74,7 +74,6 @@ impl Service { /// /// Will return an error if: /// - The user is not authorized to perform the action. - pub async fn authorize(&self, action: ACTION, maybe_user_id: Option) -> std::result::Result<(), ServiceError> { let role = self.get_role(maybe_user_id).await; From 8383e3b8c777e4e12c09c1275d5eefe6f03ae8ee Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Wed, 2 Oct 2024 13:41:21 +0100 Subject: [PATCH 10/10] release: version 3.0.0 --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dcafe906..3190f6d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3825,7 +3825,7 @@ dependencies = [ [[package]] name = "torrust-index" -version = "3.0.0-develop" +version = "3.0.0" dependencies = [ "anyhow", "argon2", @@ -3891,7 +3891,7 @@ dependencies = [ [[package]] name = "torrust-index-located-error" -version = "3.0.0-develop" +version = "3.0.0" dependencies = [ "thiserror", "tracing", diff --git a/Cargo.toml b/Cargo.toml index 7750a18c..8943d980 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ license = "AGPL-3.0-only" publish = true repository = "https://github.com/torrust/torrust-tracker" rust-version = "1.72" -version = "3.0.0-develop" +version = "3.0.0" [profile.dev.package.sqlx-macros] opt-level = 3 @@ -89,7 +89,7 @@ text-to-png = "0" thiserror = "1" tokio = { version = "1", features = ["fs", "io-util", "macros", "net", "rt-multi-thread", "signal", "sync", "time"] } toml = "0" -torrust-index-located-error = { version = "3.0.0-develop", path = "packages/located-error" } +torrust-index-located-error = { version = "3.0.0", path = "packages/located-error" } tower = { version = "0.4", features = ["timeout"] } tower-http = { version = "0", features = ["compression-full", "cors", "propagate-header", "request-id", "trace"] } trace = "0.1.7"