Skip to content

Commit

Permalink
Merge #572: New E2E test: download torrent in private mode
Browse files Browse the repository at this point in the history
7e67008 test: [#414] download torrent in private mode (Jose Celano)

Pull request description:

  It only checks that downloading a torrent works in private mode. This PR does not check that the downloaded torrent contains the tracker keys. The index should have a test for that.

  Sample torrent with tracker keys (in JSON):

  ```json
  {
     "announce": "http://tracker:7070//3PISvzYph3GYkjJvz39hhnUqANLeVC7r",
     "announce-list": [
        [
           "http://tracker:7070//3PISvzYph3GYkjJvz39hhnUqANLeVC7r"
        ],
        [
           "udp://tracker.torrust-demo.com:6969"
        ],
        [
           "udp://tracker.coppersurfer.tk:6969/announce"
        ],
        [
           "udp://9.rarbg.com:2710/announce"
        ],
        [
           "udp://p4p.arenabg.com:1337"
        ],
        [
           "udp://tracker.leechers-paradise.org:6969"
        ],
        [
           "udp://tracker.internetwarriors.net:1337"
        ],
        [
           "udp://tracker.opentrackr.org:1337/announce"
        ],
        [
           "http://tracker.openbittorrent.com:80/announce"
        ],
        [
           "udp://opentracker.i2p.rocks:6969/announce"
        ],
        [
           "udp://tracker.internetwarriors.net:1337/announce"
        ],
        [
           "udp://tracker.leechers-paradise.org:6969/announce"
        ],
        [
           "udp://coppersurfer.tk:6969/announce"
        ],
        [
           "udp://tracker.zer0day.to:1337/announce"
        ]
     ],
     "creation date": 1713791389,
     "info": {
        "files": [
           {
              "length": 2142878501,
              "path": [
                 "Spirited.Away.2001.1080p.BluRay.x264-[YTS.AM].mp4"
              ]
           },
           {
              "length": 58132,
              "path": [
                 "www.YTS.AM.jpg"
              ]
           }
        ],
        "name": "Spirited Away (2001) [BluRay] [1080p] [YTS.AM]",
        "piece length": 524288,
        "pieces": "<hex>1D 99 72 BF 0A E7 F0 D8 61 86 D7 AE 3B 59 A9 EF FA 5E CB 04 2D DB 14 04 A3 C0 82 0E DA 0B 7F 73 E5 5B 07 84 31 45 0C 06 4C BF 59 22 89 87 82 6B 71 D9 A8 A4 3C ... 20 4C 80 FB C7 EA</hex>"
     }
  }
  ```

ACKs for top commit:
  josecelano:
    ACK 7e67008

Tree-SHA512: a4344556323abc726abaa41e65fba413fa2d8f2eb80c17f86adb9e8060f233b9187df4f02f30ce3b0ed5a911b6f91212d3ae1fc06bd2ada023d2b9ccf06bfa58
  • Loading branch information
josecelano committed Jun 11, 2024
2 parents 1093e61 + 7e67008 commit 56a2bdc
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 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,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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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" \
Expand Down
38 changes: 33 additions & 5 deletions contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 42 additions & 0 deletions cypress/e2e/contexts/torrent/specs/private_download.cy.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,34 +52,36 @@ describe("A guest user", () => {
cy.delete_user_from_database(uploader_registration_form.username);
});

it("should be able to download a preexisting torrent", () => {
const torrent_info = generateRandomTestTorrentInfo();
if (Cypress.env("TRACKER_MODE") === "public") {
it("should be able to download a preexisting torrent", () => {
const torrent_info = generateRandomTestTorrentInfo();

cy.login(uploader_registration_form.username, uploader_registration_form.password);
cy.login(uploader_registration_form.username, uploader_registration_form.password);

cy.upload_torrent(torrent_info);
cy.upload_torrent(torrent_info);

cy.get("div[data-cy=\"user-menu\"]").click();
cy.get("div[data-cy=\"user-menu\"]").click();

cy.logout();
cy.logout();

// Ensure we are still on the torrent details page
cy.url().should("include", "/torrent/");
// Ensure we are still on the torrent details page
cy.url().should("include", "/torrent/");

cy.intercept({
method: "GET",
url: "/*/torrent/download/*"
}).as("download");
cy.intercept({
method: "GET",
url: "/*/torrent/download/*"
}).as("download");

cy.get("button[data-cy=\"torrent-action-download\"]").click();
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);
cy.wait("@download").then((interception) => {
// Ensure the filename is correct
expect(interception.response.headers["content-disposition"]).to.include(torrent_info.filename);

// 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);
// 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);
});
});
});
}
});
6 changes: 3 additions & 3 deletions docs/containerization_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
11 changes: 11 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,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
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 56a2bdc

Please sign in to comment.