Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New E2E test: download torrent in private mode #572

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"