Skip to content

Commit 56a2bdc

Browse files
committed
Merge #572: New E2E test: download torrent in private mode
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
2 parents 1093e61 + 7e67008 commit 56a2bdc

File tree

13 files changed

+149
-35
lines changed

13 files changed

+149
-35
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
USER_ID=${USER_ID:-1000} \
4+
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.private.e2e.container.sqlite3.toml) \
5+
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.private.e2e.container.sqlite3.toml) \
6+
docker compose down
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
USER_ID=${USER_ID:-1000} \
4+
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.private.e2e.container.sqlite3.toml) \
5+
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.private.e2e.container.sqlite3.toml) \
6+
docker compose build
7+
8+
USER_ID=${USER_ID:-1000} \
9+
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.private.e2e.container.sqlite3.toml) \
10+
TORRUST_INDEX_DATABASE="e2e_testing_sqlite3" \
11+
TORRUST_INDEX_DATABASE_DRIVER="sqlite3" \
12+
TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN="MyAccessToken" \
13+
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.private.e2e.container.sqlite3.toml) \
14+
TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3" \
15+
TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER="Sqlite3" \
16+
TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN="MyAccessToken" \
17+
docker compose up --detach --pull always --remove-orphans
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

33
USER_ID=${USER_ID:-1000} \
4-
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
5-
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
4+
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.public.e2e.container.sqlite3.toml) \
5+
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.public.e2e.container.sqlite3.toml) \
66
docker compose down

contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh renamed to contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-up.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/bin/bash
22

33
USER_ID=${USER_ID:-1000} \
4-
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
5-
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
4+
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.public.e2e.container.sqlite3.toml) \
5+
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.public.e2e.container.sqlite3.toml) \
66
docker compose build
77

88
USER_ID=${USER_ID:-1000} \
9-
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
9+
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.public.e2e.container.sqlite3.toml) \
1010
TORRUST_INDEX_DATABASE="e2e_testing_sqlite3" \
1111
TORRUST_INDEX_DATABASE_DRIVER="sqlite3" \
1212
TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN="MyAccessToken" \
13-
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
13+
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.public.e2e.container.sqlite3.toml) \
1414
TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3" \
1515
TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER="Sqlite3" \
1616
TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN="MyAccessToken" \

contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,48 @@ export TORRUST_TRACKER_DATABASE="e2e_testing_sqlite3"
1717
cp .env.local .env || exit 1
1818
./contrib/dev-tools/container/e2e/sqlite/install.sh || exit 1
1919

20+
# Run E2E tests with Tracker in public mode
21+
22+
# Start E2E testing environment
23+
./contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-up.sh || exit 1
24+
25+
# Wait for conatiners to be healthy
26+
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-mysql-1 10 3 || exit 1
27+
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-tracker-1 10 3 || exit 1
28+
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-1 10 3 || exit 1
29+
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-gui-1 10 3 || exit 1
30+
31+
# Just to make sure that everything is up and running
32+
docker ps
33+
34+
# Run E2E tests with shared app instance
35+
CYPRESS_TRACKER_MODE=public npm run cypress:run || {
36+
./contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-down.sh
37+
exit 1
38+
}
39+
40+
# Stop E2E testing environment
41+
./contrib/dev-tools/container/e2e/sqlite/mode/public/e2e-env-down.sh
42+
43+
# Run E2E tests with Tracker in private mode
44+
2045
# Start E2E testing environment
21-
./contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh || exit 1
46+
./contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-up.sh || exit 1
2247

2348
# Wait for conatiners to be healthy
2449
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-mysql-1 10 3 || exit 1
2550
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-tracker-1 10 3 || exit 1
26-
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-1 10 3 || exit 1
27-
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-gui-1 10 3 || exit 1
51+
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-1 10 3 || exit 1
52+
./contrib/dev-tools/container/functions/wait_for_container_to_be_healthy.sh torrust-index-gui-1 10 3 || exit 1
2853

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

3257
# Run E2E tests with shared app instance
33-
npm run cypress:run || { ./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh; exit 1; }
58+
CYPRESS_TRACKER_MODE=private npm run cypress:run || {
59+
./contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-down.sh
60+
exit 1
61+
}
3462

3563
# Stop E2E testing environment
36-
./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh
64+
./contrib/dev-tools/container/e2e/sqlite/mode/private/e2e-env-down.sh

cypress/e2e/contexts/torrent/specs/details/magnet_link.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("A guest user", () => {
2323
// Get the magnet link
2424
cy.get("[data-cy=\"torrent-action-magnet-link\"]").invoke("attr", "href").then((href) => {
2525
// cspell:disable-next-line
26-
expect(href).to.include(`magnet:?xt=urn:btih:${infoHash}&dn=${torrent_info.title}&tr=udp`);
26+
expect(href).to.include(`magnet:?xt=urn:btih:${infoHash}&dn=${torrent_info.title}`);
2727
});
2828

2929
cy.delete_torrent_from_database_and_fixture(torrent_info, infoHash);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { type RegistrationForm, random_user_registration_data } from "../../user/registration";
2+
import { parseInfoHash } from "../api";
3+
import { generateRandomTestTorrentInfo } from "../test_torrent_info";
4+
5+
describe("In private mode, a registered user", () => {
6+
let registration_form: RegistrationForm;
7+
8+
before(() => {
9+
registration_form = random_user_registration_data();
10+
cy.register_and_login(registration_form);
11+
});
12+
13+
after(() => {
14+
cy.delete_user_from_database(registration_form.username);
15+
});
16+
17+
if (Cypress.env("TRACKER_MODE") === "private") {
18+
it("should be able to download a preexisting torrent with the tracker key", () => {
19+
const torrent_info = generateRandomTestTorrentInfo();
20+
21+
cy.upload_torrent(torrent_info);
22+
23+
cy.intercept({
24+
method: "GET",
25+
url: "/*/torrent/download/*"
26+
}).as("download");
27+
28+
cy.get("button[data-cy=\"torrent-action-download\"]").click();
29+
30+
cy.wait("@download").then((interception) => {
31+
// Ensure the filename is correct
32+
expect(interception.response.headers["content-disposition"]).to.include(torrent_info.filename);
33+
34+
// todo: ensure that the torrent contains the tracker key
35+
36+
// Delete the test torrent generated for this test
37+
const torrentInfoHash = parseInfoHash(interception.response.headers["x-torrust-torrent-infohash"]);
38+
cy.delete_torrent_from_database_and_fixture(torrent_info, torrentInfoHash);
39+
});
40+
});
41+
}
42+
});

cypress/e2e/contexts/torrent/specs/download.cy.ts renamed to cypress/e2e/contexts/torrent/specs/public_download.cy.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,36 @@ describe("A guest user", () => {
5252
cy.delete_user_from_database(uploader_registration_form.username);
5353
});
5454

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

58-
cy.login(uploader_registration_form.username, uploader_registration_form.password);
59+
cy.login(uploader_registration_form.username, uploader_registration_form.password);
5960

60-
cy.upload_torrent(torrent_info);
61+
cy.upload_torrent(torrent_info);
6162

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

64-
cy.logout();
65+
cy.logout();
6566

66-
// Ensure we are still on the torrent details page
67-
cy.url().should("include", "/torrent/");
67+
// Ensure we are still on the torrent details page
68+
cy.url().should("include", "/torrent/");
6869

69-
cy.intercept({
70-
method: "GET",
71-
url: "/*/torrent/download/*"
72-
}).as("download");
70+
cy.intercept({
71+
method: "GET",
72+
url: "/*/torrent/download/*"
73+
}).as("download");
7374

74-
cy.get("button[data-cy=\"torrent-action-download\"]").click();
75+
cy.get("button[data-cy=\"torrent-action-download\"]").click();
7576

76-
cy.wait("@download").then((interception) => {
77-
// Ensure the filename is correct
78-
expect(interception.response.headers["content-disposition"]).to.include(torrent_info.filename);
77+
cy.wait("@download").then((interception) => {
78+
// Ensure the filename is correct
79+
expect(interception.response.headers["content-disposition"]).to.include(torrent_info.filename);
7980

80-
// Delete the test torrent generated for this test
81-
const torrentInfoHash = parseInfoHash(interception.response.headers["x-torrust-torrent-infohash"]);
82-
cy.delete_torrent_from_database_and_fixture(torrent_info, torrentInfoHash);
81+
// Delete the test torrent generated for this test
82+
const torrentInfoHash = parseInfoHash(interception.response.headers["x-torrust-torrent-infohash"]);
83+
cy.delete_torrent_from_database_and_fixture(torrent_info, torrentInfoHash);
84+
});
8385
});
84-
});
86+
}
8587
});

docs/containerization_guide.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,12 @@ Please refer to their documentation for more information.
277277
mkdir -p ./storage/index-gui/log/
278278

279279
USER_ID=${USER_ID:-1000} \
280-
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
281-
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.e2e.container.sqlite3.toml) \
280+
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.public.e2e.container.sqlite3.toml) \
281+
TORRUST_TRACKER_CONFIG_TOML=$(cat ./share/default/config/tracker.public.e2e.container.sqlite3.toml) \
282282
docker compose build
283283

284284
USER_ID=${USER_ID:-1000} \
285-
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.e2e.container.sqlite3.toml) \
285+
TORRUST_INDEX_CONFIG_TOML=$(cat ./share/default/config/index.public.e2e.container.sqlite3.toml) \
286286
TORRUST_INDEX_DATABASE="e2e_testing_sqlite3" \
287287
TORRUST_INDEX_DATABASE_DRIVER="sqlite3" \
288288
TORRUST_INDEX_CONFIG_OVERRIDE_TRACKER__TOKEN="MyAccessToken" \
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tracker]
2+
url = "http://tracker:7070"
3+
mode = "Private"
4+
api_url = "http://tracker:1212"
5+
6+
[database]
7+
connect_url = "sqlite:///var/lib/torrust/index/database/e2e_testing_sqlite3.db?mode=rwc"
8+
9+
[mail]
10+
server = "mailcatcher"
11+
port = 1025

0 commit comments

Comments
 (0)