Skip to content

Commit

Permalink
Merge #630: Fix bug: duplicate slash in torrent announce URL
Browse files Browse the repository at this point in the history
784ac54 fix comment (Jose Celano)
a3e162c refactor: simplify config files removing default values (Jose Celano)
f0a5006 fix: [#628] rename config files for MySQL E2E test env too (Jose Celano)
564ef13 fix: [#628] bug, duplicate slash in tracker announce URL (Jose Celano)
96269cd test: [#628] add failing test for bug. Duplicate slash in announce URL (Jose Celano)

Pull request description:

  When the tracker runs in private mode the announce URL in the torrent file includes a double slash `/`. For example:

  http://tracker:7070//KEY

  ### Subtasks

  - [x] Scaffolding to run E2E tests with tracker in private mode. We have been running E2E tests only for public mode so far.
  - [x] Add a failing test.
  - [x] Fix the failing test.
  - [x] Simplify config files removing defaults options.

ACKs for top commit:
  josecelano:
    ACK 784ac54

Tree-SHA512: fdaa36a605becba8066bbbb77a0cf149b2db180ce10467104723090e5ec9dc57963a7a5f10bf3275c0d8a43600d2b21a40a6b9de65025d1fec68e815ca102c7c
  • Loading branch information
josecelano committed Jun 11, 2024
2 parents 59fb3ab + 784ac54 commit 32542e9
Show file tree
Hide file tree
Showing 24 changed files with 181 additions and 155 deletions.
4 changes: 2 additions & 2 deletions contrib/dev-tools/container/e2e/mysql/e2e-env-down.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.mysql.toml) \
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.public.e2e.container.mysql.toml) \
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.public.e2e.container.sqlite3.toml) \
docker compose down
6 changes: 3 additions & 3 deletions contrib/dev-tools/container/e2e/mysql/e2e-env-up.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash

TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.e2e.container.mysql.toml) \
TORRUST_INDEX_CONFIG=$(cat ./share/default/config/index.public.e2e.container.mysql.toml) \
docker compose build

USER_ID=${USER_ID:-1000} \
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.mysql.toml) \
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.public.e2e.container.mysql.toml) \
TORRUST_INDEX_DATABASE="torrust_index_e2e_testing" \
TORRUST_INDEX_DATABASE_DRIVER="mysql" \
TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN="MyAccessToken" \
TORRUST_INDEX_MYSQL_DATABASE="torrust_index_e2e_testing" \
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.public.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3" \
TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER="Sqlite3" \
TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN="MyAccessToken" \
Expand Down
2 changes: 1 addition & 1 deletion contrib/dev-tools/container/e2e/mysql/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ docker ps

# Run E2E tests with shared app instance
TORRUST_INDEX_E2E_SHARED=true \
TORRUST_INDEX_CONFIG_TOML_PATH="./share/default/config/index.e2e.container.mysql.toml" \
TORRUST_INDEX_CONFIG_TOML_PATH="./share/default/config/index.public.e2e.container.mysql.toml" \
TORRUST_INDEX_E2E_DB_CONNECT_URL="mysql://root:root_secret_password@localhost:3306/torrust_index_e2e_testing" \
cargo test ||
{
Expand Down
5 changes: 0 additions & 5 deletions contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.private.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.private.e2e.container.sqlite3.toml) \
docker compose down
16 changes: 16 additions & 0 deletions contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.private.e2e.container.sqlite3.toml) \
docker compose build

USER_ID=${USER_ID:-1000} \
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.private.e2e.container.sqlite3.toml) \
TORRUST_INDEX_DATABASE="e2e_testing_sqlite3" \
TORRUST_INDEX_DATABASE_DRIVER="sqlite3" \
TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN="MyAccessToken" \
TORRUST_INDEX_CONFIG_OVERRIDE_AUTH__SECRET_KEY="MaxVerstappenWC2021" \
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.private.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3" \
TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER="Sqlite3" \
TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN="MyAccessToken" \
docker compose up --detach --pull always --remove-orphans
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.public.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.public.e2e.container.sqlite3.toml) \
docker compose down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash

TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.public.e2e.container.sqlite3.toml) \
docker compose build

USER_ID=${USER_ID:-1000} \
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.public.e2e.container.sqlite3.toml) \
TORRUST_INDEX_DATABASE="e2e_testing_sqlite3" \
TORRUST_INDEX_DATABASE_DRIVER="sqlite3" \
TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN="MyAccessToken" \
TORRUST_INDEX_CONFIG_OVERRIDE_AUTH__SECRET_KEY="MaxVerstappenWC2021" \
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.public.e2e.container.sqlite3.toml) \
TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3" \
TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER="Sqlite3" \
TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN="MyAccessToken" \
Expand Down
38 changes: 34 additions & 4 deletions contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,38 @@ cp .env.local .env || exit 1
# TEST USING SQLITE
echo "Running E2E tests using SQLite ..."

# TEST USING A PUBLIC TRACKER
echo "Running E2E tests with a public tracker ..."

# Start E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-up.sh || exit 1

# Wait for conatiners to be healthy
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-mysql-1 10 3 || exit 1
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-tracker-1 10 3 || exit 1
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-1 10 3 || exit 1

# Just to make sure that everything is up and running
docker ps

# Run E2E tests with shared app instance
TORRUST_INDEX_E2E_SHARED=true \
TORRUST_INDEX_CONFIG_TOML_PATH="./share/default/config/index.public.e2e.container.sqlite3.toml" \
TORRUST_INDEX_E2E_DB_CONNECT_URL="sqlite://./storage/index/lib/database/e2e_testing_sqlite3.db?mode=rwc" \
cargo test ||
{
./contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-down.sh
exit 1
}

# Stop E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-down.sh || exit 1

# TEST USING A PRIVATE TRACKER
echo "Running E2E tests with a private tracker ..."

# Start E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh || exit 1
./contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-up.sh || exit 1

# Wait for conatiners to be healthy
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-mysql-1 10 3 || exit 1
Expand All @@ -38,13 +68,13 @@ docker ps

# Run E2E tests with shared app instance
TORRUST_INDEX_E2E_SHARED=true \
TORRUST_INDEX_CONFIG_TOML_PATH="./share/default/config/index.e2e.container.sqlite3.toml" \
TORRUST_INDEX_CONFIG_TOML_PATH="./share/default/config/index.private.e2e.container.sqlite3.toml" \
TORRUST_INDEX_E2E_DB_CONNECT_URL="sqlite://./storage/index/lib/database/e2e_testing_sqlite3.db?mode=rwc" \
cargo test ||
{
./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh
./contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-down.sh
exit 1
}

# Stop E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh || exit 1
./contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-down.sh || exit 1
4 changes: 0 additions & 4 deletions share/default/config/index.container.mysql.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Please override the following settings with environmental variable!
# tracker::token -> `TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN`
# auth::secret_key -> `TORRUST_INDEX_CONFIG_OVERRIDE_AUTH__SECRET_KEY`

log_level = "info"

[database]
Expand Down
4 changes: 0 additions & 4 deletions share/default/config/index.container.sqlite3.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Please override the following settings with environmental variable!
# tracker::token -> `TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN`
# auth::secret_key -> `TORRUST_INDEX_CONFIG_OVERRIDE_AUTH__SECRET_KEY`

log_level = "info"

[database]
Expand Down
4 changes: 0 additions & 4 deletions share/default/config/index.development.sqlite3.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Please override the following settings with environmental variable!
# tracker::token -> `TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN`
# auth::secret_key -> `TORRUST_INDEX_CONFIG_OVERRIDE_AUTH__SECRET_KEY`

log_level = "info"

# Uncomment if you want to enable TSL for development
Expand Down
13 changes: 13 additions & 0 deletions share/default/config/index.private.e2e.container.sqlite3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
log_level = "info"

[tracker]
api_url = "http://tracker:1212"
mode = "Private"
url = "http://tracker:7070"

[database]
connect_url = "sqlite:///var/lib/torrust/index/database/e2e_testing_sqlite3.db?mode=rwc"

[mail]
port = 1025
server = "mailcatcher"
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Please override the following settings with environmental variable!
# tracker::token -> `TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN`
# auth::secret_key -> `TORRUST_INDEX_CONFIG_OVERRIDE_AUTH__SECRET_KEY`

log_level = "info"

[tracker]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# Please override the following settings with environmental variable!
# tracker::token -> `TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN`
# auth::secret_key -> `TORRUST_INDEX_CONFIG_OVERRIDE_AUTH__SECRET_KEY`

log_level = "info"

[tracker]
Expand Down
37 changes: 0 additions & 37 deletions share/default/config/tracker.container.mysql.toml

This file was deleted.

37 changes: 0 additions & 37 deletions share/default/config/tracker.container.sqlite3.toml

This file was deleted.

37 changes: 0 additions & 37 deletions share/default/config/tracker.e2e.container.sqlite3.toml

This file was deleted.

10 changes: 10 additions & 0 deletions share/default/config/tracker.private.e2e.container.sqlite3.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
db_driver = "Sqlite3"
db_path = "/var/lib/torrust/tracker/database/e2e_testing_sqlite3.db"
mode = "private"

[[udp_trackers]]
enabled = false

[http_api]
bind_address = "0.0.0.0:1212"

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
db_driver = "Sqlite3"
db_path = "/var/lib/torrust/tracker/database/e2e_testing_sqlite3.db"
mode = "public"

[http_api]
bind_address = "0.0.0.0:1212"
23 changes: 21 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod v1;
pub mod validator;

use std::env;
use std::str::FromStr;
use std::sync::Arc;

use camino::Utf8PathBuf;
Expand Down Expand Up @@ -122,15 +123,17 @@ impl From<figment::Error> for Error {
Use https://crates.io/crates/torrust-tracker-primitives for TrackerMode.
Enum variants (Index -> Tracker):
Enum variants:
In Index In Tracker
- `Public` -> `Public`
- `Private` -> `Private`
- `Whitelisted` -> `Listed`
- `PrivateWhitelisted` -> `PrivateListed`
Enum serialized values (Index -> Tracker):
Enum serialized values:
In Index In Tracker
- `Public` -> `public`
- `Private` -> `private`
- `Whitelisted` -> `listed`
Expand Down Expand Up @@ -163,6 +166,22 @@ impl Default for TrackerMode {
}
}

impl FromStr for TrackerMode {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"Public" => Ok(TrackerMode::Public),
"Private" => Ok(TrackerMode::Private),
"Whitelisted" => Ok(TrackerMode::Whitelisted),
"PrivateWhitelisted" => Ok(TrackerMode::PrivateWhitelisted),
_ => Err(format!(
"{s} is not a valid tracker mode. Valid values: 'Public', 'Private', 'Whitelisted', 'PrivateWhitelisted' "
)),
}
}
}

impl TrackerMode {
#[must_use]
pub fn is_open(&self) -> bool {
Expand Down
4 changes: 3 additions & 1 deletion src/tracker/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,9 @@ impl Service {
/// It builds the announce url appending the user tracker key.
/// Eg: <https://tracker:7070/USER_TRACKER_KEY>
fn announce_url_with_key(&self, tracker_key: &TrackerKey) -> Url {
Url::parse(&format!("{}/{}", self.tracker_url, tracker_key.key)).unwrap()
self.tracker_url
.join(&tracker_key.key)
.expect("a tracker key should be added to the tracker base URL")
}

fn invalid_token_body() -> String {
Expand Down
Loading

0 comments on commit 32542e9

Please sign in to comment.