Skip to content

Commit

Permalink
Merge #1232: Overhaul core Tracker: add tests for authentication mod
Browse files Browse the repository at this point in the history
3d89c7f fix: [#1231] lint errors (Jose Celano)
3e02b48 test: [#1231] add more tests for authentication::service mod (Jose Celano)
7d8b394 test: [#1231] add tests for AuthenticationService (Jose Celano)
63e773a refactor: [#1231] remove dead code (Jose Celano)
c3117cf test: [#1231] add more tests for KeysHandler (Jose Celano)
bd4cef6 refactor: [#1231] tests to use database mock in KeysHandler (Jose Celano)
e3ba1e1 test: [#1231] add tests for KeysHandler (Jose Celano)
5db73be refactor: rename methods (Jose Celano)
0d7e30e refactor: [#1231] bittorrent_tracker_core::authentication::key::tests (Jose Celano)
d0c7313 refactor: [#1231] peer_key mod tests (Jose Celano)
5d91a32 test: [#1231] add more tests to peer_key mod (Jose Celano)
0336ca7 refactor: [#1231] exctract mod (Jose Celano)
8709540 refactor: [#1231] improve DatabaseKeyRepository tests (Jose Celano)
e519e7f refactor: [#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: [#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
  • Loading branch information
josecelano committed Feb 4, 2025
2 parents 0c6d87c + 3d89c7f commit 4a9c083
Show file tree
Hide file tree
Showing 24 changed files with 1,098 additions and 308 deletions.
13 changes: 9 additions & 4 deletions packages/test-helpers/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Tracker configuration factories for testing.
use std::env;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
use std::path::PathBuf;
use std::time::Duration;

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

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

config
}

#[must_use]
pub fn ephemeral_sqlite_database() -> PathBuf {
let temp_directory = env::temp_dir();
let random_db_id = random::string(16);
temp_directory.join(format!("data_{random_db_id}.db"))
}

/// Ephemeral configuration with reverse proxy enabled.
#[must_use]
pub fn ephemeral_with_reverse_proxy() -> Configuration {
Expand Down
1 change: 1 addition & 0 deletions packages/tracker-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.coverage
1 change: 1 addition & 0 deletions packages/tracker-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ bittorrent-http-protocol = { version = "3.0.0-develop", path = "../http-protocol
bittorrent-primitives = "0.1.0"
chrono = { version = "0", default-features = false, features = ["clock"] }
derive_more = { version = "1", features = ["as_ref", "constructor", "from"] }
mockall = "0"
r2d2 = "0"
r2d2_mysql = "25"
r2d2_sqlite = { version = "0", features = ["bundled"] }
Expand Down
2 changes: 1 addition & 1 deletion packages/tracker-core/src/announce_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ mod tests {

config.core.tracker_policy.persistent_torrent_completed_stat = true;

let database = initialize_database(&config);
let database = initialize_database(&config.core);
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
let db_torrent_repository = Arc::new(DatabasePersistentTorrentRepository::new(&database));
let torrents_manager = Arc::new(TorrentsManager::new(
Expand Down
Loading

0 comments on commit 4a9c083

Please sign in to comment.