From db6ba5cd31d2ccade9ab6f1d673bdf0ca4f956f8 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Tue, 11 Jun 2024 10:08:02 +0100 Subject: [PATCH] test: [#414] download torrent in private mode The torrent should include the tracker keys. --- .../e2e/sqlite/mode/private/e2e-env-down.sh | 6 +++ .../e2e/sqlite/mode/private/e2e-env-up.sh | 17 ++++++++ .../sqlite/{ => mode/public}/e2e-env-down.sh | 4 +- .../sqlite/{ => mode/public}/e2e-env-up.sh | 8 ++-- .../container/e2e/sqlite/run-e2e-tests.sh | 38 ++++++++++++++--- .../torrent/specs/details/magnet_link.cy.ts | 2 +- .../torrent/specs/private_download.cy.ts | 42 +++++++++++++++++++ .../{download.cy.ts => public_download.cy.ts} | 0 docs/containerization_guide.md | 6 +-- .../index.private.e2e.container.sqlite3.toml | 11 +++++ ...> index.public.e2e.container.sqlite3.toml} | 0 ...tracker.private.e2e.container.sqlite3.toml | 8 ++++ ...tracker.public.e2e.container.sqlite3.toml} | 0 13 files changed, 127 insertions(+), 15 deletions(-) create mode 100755 contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-down.sh create mode 100755 contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-up.sh rename contrib/dev-tools/container/e2e/sqlite/{ => mode/public}/e2e-env-down.sh (70%) rename contrib/dev-tools/container/e2e/sqlite/{ => mode/public}/e2e-env-up.sh (82%) create mode 100644 cypress/e2e/contexts/torrent/specs/private_download.cy.ts rename cypress/e2e/contexts/torrent/specs/{download.cy.ts => public_download.cy.ts} (100%) create mode 100644 share/default/config/index.private.e2e.container.sqlite3.toml rename share/default/config/{index.e2e.container.sqlite3.toml => index.public.e2e.container.sqlite3.toml} (100%) create mode 100644 share/default/config/tracker.private.e2e.container.sqlite3.toml rename share/default/config/{tracker.e2e.container.sqlite3.toml => tracker.public.e2e.container.sqlite3.toml} (100%) diff --git a/contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-down.sh b/contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-down.sh new file mode 100755 index 00000000..0c46a7cd --- /dev/null +++ b/contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-down.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +USER_ID=${USER_ID:-1000} \ + 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 diff --git a/contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-up.sh b/contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-up.sh new file mode 100755 index 00000000..f719647f --- /dev/null +++ b/contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-up.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +USER_ID=${USER_ID:-1000} \ + 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 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_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 diff --git a/contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh b/contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-down.sh similarity index 70% rename from contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh rename to contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-down.sh index 7cf22d0c..07282840 100755 --- a/contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh +++ b/contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-down.sh @@ -1,6 +1,6 @@ #!/bin/bash USER_ID=${USER_ID:-1000} \ - TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.sqlite3.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.sqlite3.toml) \ + TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.public.e2e.container.sqlite3.toml) \ docker compose down diff --git a/contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh b/contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-up.sh similarity index 82% rename from contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh rename to contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-up.sh index 2070bad2..9253eedd 100755 --- a/contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh +++ b/contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-up.sh @@ -1,16 +1,16 @@ #!/bin/bash USER_ID=${USER_ID:-1000} \ - TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.sqlite3.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.sqlite3.toml) \ + TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.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_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" \ diff --git a/contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh b/contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh index 79c7656d..d5798095 100755 --- a/contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh +++ b/contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh @@ -17,20 +17,48 @@ export TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3" cp .env.local .env || exit 1 ./contrib/dev-tools/container/e2e/sqlite/install.sh || exit 1 +# Run E2E tests with Tracker in public mode + +# 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 +./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-gui-1 10 3 || exit 1 + +# Just to make sure that everything is up and running +docker ps + +# Run E2E tests with shared app instance +CYPRESS_TRACKER_MODE=public npm run cypress:run || { + ./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 + +# Run E2E tests with Tracker in private mode + # 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 ./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 -./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-gui-1 10 3 || exit 1 +./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-1 10 3 || exit 1 +./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-gui-1 10 3 || exit 1 # Just to make sure that everything is up and running docker ps # Run E2E tests with shared app instance -npm run cypress:run || { ./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh; exit 1; } +CYPRESS_TRACKER_MODE=private npm run cypress:run || { + ./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 +./contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-down.sh diff --git a/cypress/e2e/contexts/torrent/specs/details/magnet_link.cy.ts b/cypress/e2e/contexts/torrent/specs/details/magnet_link.cy.ts index 7ac27f50..f2b9352c 100644 --- a/cypress/e2e/contexts/torrent/specs/details/magnet_link.cy.ts +++ b/cypress/e2e/contexts/torrent/specs/details/magnet_link.cy.ts @@ -23,7 +23,7 @@ describe("A guest user", () => { // Get the magnet link cy.get("[data-cy=\"torrent-action-magnet-link\"]").invoke("attr", "href").then((href) => { // cspell:disable-next-line - expect(href).to.include(`magnet:?xt=urn:btih:${infoHash}&dn=${torrent_info.title}&tr=udp`); + expect(href).to.include(`magnet:?xt=urn:btih:${infoHash}&dn=${torrent_info.title}`); }); cy.delete_torrent_from_database_and_fixture(torrent_info, infoHash); diff --git a/cypress/e2e/contexts/torrent/specs/private_download.cy.ts b/cypress/e2e/contexts/torrent/specs/private_download.cy.ts new file mode 100644 index 00000000..e7283fa8 --- /dev/null +++ b/cypress/e2e/contexts/torrent/specs/private_download.cy.ts @@ -0,0 +1,42 @@ +import { type RegistrationForm, random_user_registration_data } from "../../user/registration"; +import { parseInfoHash } from "../api"; +import { generateRandomTestTorrentInfo } from "../test_torrent_info"; + +describe("In private mode, a registered user", () => { + let registration_form: RegistrationForm; + + before(() => { + registration_form = random_user_registration_data(); + cy.register_and_login(registration_form); + }); + + after(() => { + cy.delete_user_from_database(registration_form.username); + }); + + if (Cypress.env("TRACKER_MODE") === "private") { + it("should be able to download a preexisting torrent with the tracker key", () => { + const torrent_info = generateRandomTestTorrentInfo(); + + cy.upload_torrent(torrent_info); + + cy.intercept({ + method: "GET", + url: "/*/torrent/download/*" + }).as("download"); + + cy.get("button[data-cy=\"torrent-action-download\"]").click(); + + cy.wait("@download").then((interception) => { + // Ensure the filename is correct + expect(interception.response.headers["content-disposition"]).to.include(torrent_info.filename); + + // todo: ensure that the torrent contains the tracker key + + // Delete the test torrent generated for this test + const torrentInfoHash = parseInfoHash(interception.response.headers["x-torrust-torrent-infohash"]); + cy.delete_torrent_from_database_and_fixture(torrent_info, torrentInfoHash); + }); + }); + } +}); diff --git a/cypress/e2e/contexts/torrent/specs/download.cy.ts b/cypress/e2e/contexts/torrent/specs/public_download.cy.ts similarity index 100% rename from cypress/e2e/contexts/torrent/specs/download.cy.ts rename to cypress/e2e/contexts/torrent/specs/public_download.cy.ts diff --git a/docs/containerization_guide.md b/docs/containerization_guide.md index 19b6acbe..351e4097 100644 --- a/docs/containerization_guide.md +++ b/docs/containerization_guide.md @@ -277,12 +277,12 @@ Please refer to their documentation for more information. mkdir -p ./storage/index-gui/log/ USER_ID=${USER_ID:-1000} \ - TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.sqlite3.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.sqlite3.toml) \ + TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.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" \ diff --git a/share/default/config/index.private.e2e.container.sqlite3.toml b/share/default/config/index.private.e2e.container.sqlite3.toml new file mode 100644 index 00000000..81d368fb --- /dev/null +++ b/share/default/config/index.private.e2e.container.sqlite3.toml @@ -0,0 +1,11 @@ +[tracker] +url = "http://tracker:7070" +mode = "Private" +api_url = "http://tracker:1212" + +[database] +connect_url = "sqlite:///var/lib/torrust/index/database/e2e_testing_sqlite3.db?mode=rwc" + +[mail] +server = "mailcatcher" +port = 1025 diff --git a/share/default/config/index.e2e.container.sqlite3.toml b/share/default/config/index.public.e2e.container.sqlite3.toml similarity index 100% rename from share/default/config/index.e2e.container.sqlite3.toml rename to share/default/config/index.public.e2e.container.sqlite3.toml diff --git a/share/default/config/tracker.private.e2e.container.sqlite3.toml b/share/default/config/tracker.private.e2e.container.sqlite3.toml new file mode 100644 index 00000000..54f4152f --- /dev/null +++ b/share/default/config/tracker.private.e2e.container.sqlite3.toml @@ -0,0 +1,8 @@ +mode = "private" +db_path = "/var/lib/torrust/tracker/database/e2e_testing_sqlite3.db" + +[[udp_trackers]] +enabled = false + +[http_api] +bind_address = "0.0.0.0:1212" diff --git a/share/default/config/tracker.e2e.container.sqlite3.toml b/share/default/config/tracker.public.e2e.container.sqlite3.toml similarity index 100% rename from share/default/config/tracker.e2e.container.sqlite3.toml rename to share/default/config/tracker.public.e2e.container.sqlite3.toml