Skip to content

Commit 74b04c8

Browse files
committed
Merge #1213: Overhaul core Tracker: refactor tests
7ce52f9 refactor: [#1211] rename type to WhitelistManager (Jose Celano) 115159d refactor: [#1211] clean core::whitelist module tests (Jose Celano) 69d4505 refactor: [#1211] rename type to WhitelistAuthorization (Jose Celano) 7fa2b15 refactor: [#1211] clean tests in core::whitelist::authorization (Jose Celano) b51018f refactor: [#1211] extract duplicate code (Jose Celano) 6529021 refactor: [#1211] remove duplicate function (Jose Celano) 55dc8b0 refactor: [#1211] clean AnnounceHandler tests (Jose Celano) e8a2c8b refactor: [#1211] clean tests in core mod (Jose Celano) 22320f5 refactor: [#1211] move test to torrust_tracker_primitives::core (Jose Celano) e2d573b refactor: [#1211] move tests to whitelist module (Jose Celano) c785fd1 refactor: [#1211] move tests to AnnounceHandler (Jose Celano) c3f0bc7 refactor: [#1211] move tracker tests to InMemoryTorrentRepository (Jose Celano) Pull request description: Overhaul core Tracker: refactor tests ACKs for top commit: josecelano: ACK 7ce52f9 Tree-SHA512: 2c9366e644c22c20be06e0d47cf94a3c18e962ba64a868f0a0a59fd5de4e057b540549cebbf5587e4d339f17b3f44f2b7e936306f94341b8a620208150eb3e23
2 parents 17bea24 + 7ce52f9 commit 74b04c8

36 files changed

+849
-744
lines changed

packages/primitives/src/core.rs

+30
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,33 @@ impl ScrapeData {
5656
self.files.insert(*info_hash, SwarmMetadata::zeroed());
5757
}
5858
}
59+
60+
#[cfg(test)]
61+
mod tests {
62+
63+
use bittorrent_primitives::info_hash::InfoHash;
64+
65+
use crate::core::ScrapeData;
66+
67+
/// # Panics
68+
///
69+
/// Will panic if the string representation of the info hash is not a valid info hash.
70+
#[must_use]
71+
pub fn sample_info_hash() -> InfoHash {
72+
"3b245504cf5f11bbdbe1201cea6a6bf45aee1bc0" // DevSkim: ignore DS173237
73+
.parse::<InfoHash>()
74+
.expect("String should be a valid info hash")
75+
}
76+
77+
#[test]
78+
fn it_should_be_able_to_build_a_zeroed_scrape_data_for_a_list_of_info_hashes() {
79+
// Zeroed scrape data is used when the authentication for the scrape request fails.
80+
81+
let sample_info_hash = sample_info_hash();
82+
83+
let mut expected_scrape_data = ScrapeData::empty();
84+
expected_scrape_data.add_file_with_zeroed_metadata(&sample_info_hash);
85+
86+
assert_eq!(ScrapeData::zeroed(&vec![sample_info_hash]), expected_scrape_data);
87+
}
88+
}

src/app_test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ pub fn initialize_tracker_dependencies(
2323
) -> (
2424
Arc<Box<dyn Database>>,
2525
Arc<InMemoryWhitelist>,
26-
Arc<whitelist::authorization::Authorization>,
26+
Arc<whitelist::authorization::WhitelistAuthorization>,
2727
Arc<AuthenticationService>,
2828
Arc<InMemoryTorrentRepository>,
2929
Arc<DatabasePersistentTorrentRepository>,
3030
Arc<TorrentsManager>,
3131
) {
3232
let database = initialize_database(config);
3333
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
34-
let whitelist_authorization = Arc::new(whitelist::authorization::Authorization::new(
34+
let whitelist_authorization = Arc::new(whitelist::authorization::WhitelistAuthorization::new(
3535
&config.core,
3636
&in_memory_whitelist.clone(),
3737
));

src/bootstrap/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
9393
let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP)));
9494
let database = initialize_database(configuration);
9595
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
96-
let whitelist_authorization = Arc::new(whitelist::authorization::Authorization::new(
96+
let whitelist_authorization = Arc::new(whitelist::authorization::WhitelistAuthorization::new(
9797
&configuration.core,
9898
&in_memory_whitelist.clone(),
9999
));

src/bootstrap/jobs/http_tracker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub async fn start_job(
5252
announce_handler: Arc<AnnounceHandler>,
5353
scrape_handler: Arc<ScrapeHandler>,
5454
authentication_service: Arc<AuthenticationService>,
55-
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
55+
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
5656
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
5757
form: ServiceRegistrationForm,
5858
version: Version,
@@ -99,7 +99,7 @@ async fn start_v1(
9999
announce_handler: Arc<AnnounceHandler>,
100100
scrape_handler: Arc<ScrapeHandler>,
101101
authentication_service: Arc<AuthenticationService>,
102-
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
102+
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
103103
stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>>,
104104
form: ServiceRegistrationForm,
105105
) -> JoinHandle<()> {

src/bootstrap/jobs/tracker_apis.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::core::authentication::handler::KeysHandler;
3434
use crate::core::statistics::event::sender::Sender;
3535
use crate::core::statistics::repository::Repository;
3636
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
37-
use crate::core::whitelist::manager::WhiteListManager;
37+
use crate::core::whitelist::manager::WhitelistManager;
3838
use crate::servers::apis::server::{ApiServer, Launcher};
3939
use crate::servers::apis::Version;
4040
use crate::servers::registar::ServiceRegistrationForm;
@@ -74,7 +74,7 @@ pub async fn start_job(
7474
config: &HttpApi,
7575
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
7676
keys_handler: Arc<KeysHandler>,
77-
whitelist_manager: Arc<WhiteListManager>,
77+
whitelist_manager: Arc<WhitelistManager>,
7878
ban_service: Arc<RwLock<BanService>>,
7979
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
8080
stats_repository: Arc<Repository>,
@@ -126,7 +126,7 @@ async fn start_v1(
126126
tls: Option<RustlsConfig>,
127127
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
128128
keys_handler: Arc<KeysHandler>,
129-
whitelist_manager: Arc<WhiteListManager>,
129+
whitelist_manager: Arc<WhitelistManager>,
130130
ban_service: Arc<RwLock<BanService>>,
131131
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
132132
stats_repository: Arc<Repository>,

src/bootstrap/jobs/udp_tracker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub async fn start_job(
4949
config: &UdpTracker,
5050
announce_handler: Arc<AnnounceHandler>,
5151
scrape_handler: Arc<ScrapeHandler>,
52-
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
52+
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
5353
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
5454
ban_service: Arc<RwLock<BanService>>,
5555
form: ServiceRegistrationForm,

src/container.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::core::torrent::manager::TorrentsManager;
1313
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
1414
use crate::core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
1515
use crate::core::whitelist;
16-
use crate::core::whitelist::manager::WhiteListManager;
16+
use crate::core::whitelist::manager::WhitelistManager;
1717
use crate::servers::udp::server::banning::BanService;
1818

1919
pub struct AppContainer {
@@ -22,11 +22,11 @@ pub struct AppContainer {
2222
pub scrape_handler: Arc<ScrapeHandler>,
2323
pub keys_handler: Arc<KeysHandler>,
2424
pub authentication_service: Arc<AuthenticationService>,
25-
pub whitelist_authorization: Arc<whitelist::authorization::Authorization>,
25+
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
2626
pub ban_service: Arc<RwLock<BanService>>,
2727
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
2828
pub stats_repository: Arc<Repository>,
29-
pub whitelist_manager: Arc<WhiteListManager>,
29+
pub whitelist_manager: Arc<WhitelistManager>,
3030
pub in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
3131
pub db_torrent_repository: Arc<DatabasePersistentTorrentRepository>,
3232
pub torrents_manager: Arc<TorrentsManager>,

0 commit comments

Comments
 (0)