Skip to content

Conversation

josecelano
Copy link
Member

Fix missing tracker key in torrent when the tracker URL doesn't have a trailing slash. For example, this tracker URL in the configuration:

https://127.0.0.1:7070/announce

produces this tracker URL in the torrent:

https://127.0.0.1:7070/mCGfCr8nvixxA0h8B4iz0sT8V3FIQLi7

and it should produce:

https://127.0.0.1:7070/announce/mCGfCr8nvixxA0h8B4iz0sT8V3FIQLi7

@josecelano josecelano force-pushed the 811-suffix-announce-is-stripped-from-tracker-url branch from c10b379 to 2090942 Compare June 14, 2025 08:31
@josecelano josecelano requested review from da2ce7 and grmbyrn June 14, 2025 08:31
@josecelano josecelano force-pushed the 811-suffix-announce-is-stripped-from-tracker-url branch from 2090942 to 9fc18db Compare June 14, 2025 08:32
@josecelano josecelano added the Bug Incorrect Behavior label Jun 14, 2025
@josecelano josecelano self-assigned this Jun 14, 2025
@josecelano josecelano linked an issue Jun 14, 2025 that may be closed by this pull request
when the tracker URL doesn't have a trailing slash. For example, this
tracker URL in the configuration:

https://127.0.0.1:7070/announce

produces this tracker URL in the torrent:

https://127.0.0.1:7070/mCGfCr8nvixxA0h8B4iz0sT8V3FIQLi7

and it should produce:

https://127.0.0.1:7070/announce/mCGfCr8nvixxA0h8B4iz0sT8V3FIQLi7
@josecelano josecelano force-pushed the 811-suffix-announce-is-stripped-from-tracker-url branch from 9fc18db to 649565f Compare June 14, 2025 08:38
Copy link

codecov bot commented Jun 14, 2025

Codecov Report

Attention: Patch coverage is 87.50000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 47.21%. Comparing base (2a45dcc) to head (17aecf9).
Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
src/tracker/api.rs 16.66% 5 Missing ⚠️
src/tracker/service.rs 97.56% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #812      +/-   ##
===========================================
- Coverage    47.81%   47.21%   -0.60%     
===========================================
  Files          111      111              
  Lines         8540     8014     -526     
  Branches      8540     8014     -526     
===========================================
- Hits          4083     3784     -299     
+ Misses        4319     4126     -193     
+ Partials       138      104      -34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@josecelano
Copy link
Member Author

There is a test for this:

    mod downloading_a_torrent {

        use regex::Regex;
        use torrust_index::utils::parse_torrent::decode_torrent;
        use torrust_index::web::api;
        use url::Url;

        use crate::common::client::Client;
        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_include_the_tracker_key_when_the_tracker_is_running_in_private_mode() {
            let mut env = TestEnv::new();
            env.start(api::Version::V1).await;

            if !env.provides_a_private_tracker() {
                println!("test skipped. It requires a private tracker to be running.");
                return;
            }

            let uploader = new_logged_in_user(&env).await;
            let client = Client::authenticated(&env.server_socket_addr().unwrap(), &uploader.token);

            // 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;

            let torrent = decode_torrent(&response.bytes).expect("could not decode downloaded torrent");

            let announce_url = Url::parse(&torrent.announce.unwrap()).unwrap();

            let re = Regex::new(r"^http://tracker:7070/[a-zA-Z0-9]{32}$").unwrap(); // DevSkim: ignore DS137138

            assert!(re.is_match(announce_url.as_ref()), "Invalid announce URL: '{announce_url}'.");
        }
    }

But it does not include this case because the tracker URL is "http://tracker:7070"

[tracker]
api_url = "http://tracker:1212"
listed = false
private = true
token = "MyAccessToken"
url = "http://tracker:7070"

I will open a new issue for this; it seems the tracker configuration is wrong. It should be "http://tracker:7070/announce". The test is passing because we don't interact with the tracker in the test. We need to add another test to retrieve the information from the tracker using the provided URL.

cc @da2ce7

@josecelano josecelano force-pushed the 811-suffix-announce-is-stripped-from-tracker-url branch from d470f78 to 17aecf9 Compare June 14, 2025 09:56
@josecelano josecelano marked this pull request as draft June 14, 2025 10:14
@josecelano josecelano marked this pull request as ready for review June 15, 2025 11:21
@josecelano
Copy link
Member Author

ACK 17aecf9

@josecelano josecelano merged commit f9c17f3 into torrust:develop Jun 15, 2025
27 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Incorrect Behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suffix /announce is stripped from tracker url
1 participant