Skip to content

Commit 4a9c083

Browse files
committed
Merge torrust#1232: Overhaul core Tracker: add tests for authentication mod
3d89c7f fix: [torrust#1231] lint errors (Jose Celano) 3e02b48 test: [torrust#1231] add more tests for authentication::service mod (Jose Celano) 7d8b394 test: [torrust#1231] add tests for AuthenticationService (Jose Celano) 63e773a refactor: [torrust#1231] remove dead code (Jose Celano) c3117cf test: [torrust#1231] add more tests for KeysHandler (Jose Celano) bd4cef6 refactor: [torrust#1231] tests to use database mock in KeysHandler (Jose Celano) e3ba1e1 test: [torrust#1231] add tests for KeysHandler (Jose Celano) 5db73be refactor: rename methods (Jose Celano) 0d7e30e refactor: [torrust#1231] bittorrent_tracker_core::authentication::key::tests (Jose Celano) d0c7313 refactor: [torrust#1231] peer_key mod tests (Jose Celano) 5d91a32 test: [torrust#1231] add more tests to peer_key mod (Jose Celano) 0336ca7 refactor: [torrust#1231] exctract mod (Jose Celano) 8709540 refactor: [torrust#1231] improve DatabaseKeyRepository tests (Jose Celano) e519e7f refactor: [torrust#1231] simplify tests for DatabaseKeyRepository (Jose Celano) f485a52 refactor: inject only core config in tracker core DB setup (Jose Celano) 7c8d294 test: add tests for DatabaseKeyRepository (Jose Celano) 04ee425 chore: add todo (Jose Celano) 8efda62 test: [torrust#1231] add tests for InMemoryKeyRepository (Jose Celano) Pull request description: Overhaul core Tracker: add tests for `authentication` mod. Coverage before: ```output Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- packages/tracker-core/src/authentication/handler.rs 85 17 80.00% 28 1 96.43% 203 35 82.76% 0 0 - packages/tracker-core/src/authentication/key/mod.rs 55 7 87.27% 18 3 83.33% 124 12 90.32% 0 0 - packages/tracker-core/src/authentication/key/repository/in_memory.rs 23 5 78.26% 10 2 80.00% 25 5 80.00% 0 0 - packages/tracker-core/src/authentication/key/repository/persisted.rs 15 3 80.00% 4 0 100.00% 17 0 100.00% 0 0 - packages/tracker-core/src/authentication/mod.rs 67 0 100.00% 19 0 100.00% 201 0 100.00% 0 0 - packages/tracker-core/src/authentication/service.rs 22 2 90.91% ``` Coverage after: ```output Filename Regions Missed Regions Cover Functions Missed Functions Executed Lines Missed Lines Cover Branches Missed Branches Cover --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- packages/tracker-core/src/authentication/handler.rs 158 9 94.30% 52 0 100.00% 583 0 100.00% 0 0 - packages/tracker-core/src/authentication/key/mod.rs 35 3 91.43% 11 0 100.00% 96 0 100.00% 0 0 - packages/tracker-core/src/authentication/key/peer_key.rs 39 0 100.00% 17 0 100.00% 102 0 100.00% 0 0 - packages/tracker-core/src/authentication/key/repository/in_memory.rs 51 0 100.00% 20 0 100.00% 169 0 100.00% 0 0 - packages/tracker-core/src/authentication/key/repository/persisted.rs 24 2 91.67% 8 0 100.00% 77 0 100.00% 0 0 - packages/tracker-core/src/authentication/mod.rs 67 0 100.00% 19 0 100.00% 219 0 100.00% 0 0 - packages/tracker-core/src/authentication/service.rs 52 0 100.00% 20 0 100.00% 268 0 100.00% 0 0 - ``` ACKs for top commit: josecelano: ACK 3d89c7f Tree-SHA512: 6107da6ab65266f4efa50b93d6c3ed38d5c5289d4d4a449b15a8aa3021d0219bfb1dc78e833675a81a2803091fa7f65db354bd6a67f5bcfcbefb55995e6d94a7
2 parents 0c6d87c + 3d89c7f commit 4a9c083

File tree

24 files changed

+1098
-308
lines changed

24 files changed

+1098
-308
lines changed

packages/test-helpers/src/configuration.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Tracker configuration factories for testing.
22
use std::env;
33
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
4+
use std::path::PathBuf;
45
use std::time::Duration;
56

67
use torrust_tracker_configuration::{Configuration, HttpApi, HttpTracker, Threshold, UdpTracker};
@@ -63,15 +64,19 @@ pub fn ephemeral() -> Configuration {
6364
tsl_config: None,
6465
}]);
6566

66-
// Ephemeral sqlite database
67-
let temp_directory = env::temp_dir();
68-
let random_db_id = random::string(16);
69-
let temp_file = temp_directory.join(format!("data_{random_db_id}.db"));
67+
let temp_file = ephemeral_sqlite_database();
7068
temp_file.to_str().unwrap().clone_into(&mut config.core.database.path);
7169

7270
config
7371
}
7472

73+
#[must_use]
74+
pub fn ephemeral_sqlite_database() -> PathBuf {
75+
let temp_directory = env::temp_dir();
76+
let random_db_id = random::string(16);
77+
temp_directory.join(format!("data_{random_db_id}.db"))
78+
}
79+
7580
/// Ephemeral configuration with reverse proxy enabled.
7681
#[must_use]
7782
pub fn ephemeral_with_reverse_proxy() -> Configuration {

packages/tracker-core/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.coverage

packages/tracker-core/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ bittorrent-http-protocol = { version = "3.0.0-develop", path = "../http-protocol
2020
bittorrent-primitives = "0.1.0"
2121
chrono = { version = "0", default-features = false, features = ["clock"] }
2222
derive_more = { version = "1", features = ["as_ref", "constructor", "from"] }
23+
mockall = "0"
2324
r2d2 = "0"
2425
r2d2_mysql = "25"
2526
r2d2_sqlite = { version = "0", features = ["bundled"] }

packages/tracker-core/src/announce_handler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ mod tests {
425425

426426
config.core.tracker_policy.persistent_torrent_completed_stat = true;
427427

428-
let database = initialize_database(&config);
428+
let database = initialize_database(&config.core);
429429
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
430430
let db_torrent_repository = Arc::new(DatabasePersistentTorrentRepository::new(&database));
431431
let torrents_manager = Arc::new(TorrentsManager::new(

0 commit comments

Comments
 (0)