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

Overhaul core Tracker: refactor tests #1213

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor: [#1211] rename type to WhitelistAuthorization
josecelano committed Jan 28, 2025

Verified

This commit was signed with the committer’s verified signature.
josecelano Jose Celano
commit 69d4505057affbb0995db9d08e168a92980bafd7
4 changes: 2 additions & 2 deletions src/app_test.rs
Original file line number Diff line number Diff line change
@@ -23,15 +23,15 @@ pub fn initialize_tracker_dependencies(
) -> (
Arc<Box<dyn Database>>,
Arc<InMemoryWhitelist>,
Arc<whitelist::authorization::Authorization>,
Arc<whitelist::authorization::WhitelistAuthorization>,
Arc<AuthenticationService>,
Arc<InMemoryTorrentRepository>,
Arc<DatabasePersistentTorrentRepository>,
Arc<TorrentsManager>,
) {
let database = initialize_database(config);
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(whitelist::authorization::Authorization::new(
let whitelist_authorization = Arc::new(whitelist::authorization::WhitelistAuthorization::new(
&config.core,
&in_memory_whitelist.clone(),
));
2 changes: 1 addition & 1 deletion src/bootstrap/app.rs
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP)));
let database = initialize_database(configuration);
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(whitelist::authorization::Authorization::new(
let whitelist_authorization = Arc::new(whitelist::authorization::WhitelistAuthorization::new(
&configuration.core,
&in_memory_whitelist.clone(),
));
4 changes: 2 additions & 2 deletions src/bootstrap/jobs/http_tracker.rs
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ pub async fn start_job(
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
authentication_service: Arc<AuthenticationService>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
form: ServiceRegistrationForm,
version: Version,
@@ -99,7 +99,7 @@ async fn start_v1(
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
authentication_service: Arc<AuthenticationService>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>>,
form: ServiceRegistrationForm,
) -> JoinHandle<()> {
2 changes: 1 addition & 1 deletion src/bootstrap/jobs/udp_tracker.rs
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ pub async fn start_job(
config: &UdpTracker,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
ban_service: Arc<RwLock<BanService>>,
form: ServiceRegistrationForm,
2 changes: 1 addition & 1 deletion src/container.rs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ pub struct AppContainer {
pub scrape_handler: Arc<ScrapeHandler>,
pub keys_handler: Arc<KeysHandler>,
pub authentication_service: Arc<AuthenticationService>,
pub whitelist_authorization: Arc<whitelist::authorization::Authorization>,
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
pub ban_service: Arc<RwLock<BanService>>,
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
pub stats_repository: Arc<Repository>,
2 changes: 1 addition & 1 deletion src/core/core_tests.rs
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ pub fn incomplete_peer() -> Peer {
pub fn initialize_handlers(config: &Configuration) -> (Arc<AnnounceHandler>, Arc<ScrapeHandler>) {
let database = initialize_database(config);
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(whitelist::authorization::Authorization::new(
let whitelist_authorization = Arc::new(whitelist::authorization::WhitelistAuthorization::new(
&config.core,
&in_memory_whitelist.clone(),
));
6 changes: 3 additions & 3 deletions src/core/scrape_handler.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ use super::whitelist;

pub struct ScrapeHandler {
/// The service to check is a torrent is whitelisted.
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,

/// The in-memory torrents repository.
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
@@ -18,7 +18,7 @@ pub struct ScrapeHandler {
impl ScrapeHandler {
#[must_use]
pub fn new(
whitelist_authorization: &Arc<whitelist::authorization::Authorization>,
whitelist_authorization: &Arc<whitelist::authorization::WhitelistAuthorization>,
in_memory_torrent_repository: &Arc<InMemoryTorrentRepository>,
) -> Self {
Self {
@@ -62,7 +62,7 @@ mod tests {
let config = configuration::ephemeral_public();

let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(whitelist::authorization::Authorization::new(
let whitelist_authorization = Arc::new(whitelist::authorization::WhitelistAuthorization::new(
&config.core,
&in_memory_whitelist.clone(),
));
10 changes: 5 additions & 5 deletions src/core/whitelist/authorization.rs
Original file line number Diff line number Diff line change
@@ -8,15 +8,15 @@ use tracing::instrument;
use super::repository::in_memory::InMemoryWhitelist;
use crate::core::error::Error;

pub struct Authorization {
pub struct WhitelistAuthorization {
/// Core tracker configuration.
config: Core,

/// The in-memory list of allowed torrents.
in_memory_whitelist: Arc<InMemoryWhitelist>,
}

impl Authorization {
impl WhitelistAuthorization {
/// Creates a new authorization instance.
pub fn new(config: &Core, in_memory_whitelist: &Arc<InMemoryWhitelist>) -> Self {
Self {
@@ -65,17 +65,17 @@ mod tests {

use torrust_tracker_test_helpers::configuration;

use super::Authorization;
use super::WhitelistAuthorization;
use crate::core::services::{initialize_database, initialize_whitelist_manager};
use crate::core::whitelist::manager::WhiteListManager;
use crate::core::whitelist::repository::in_memory::InMemoryWhitelist;

fn initialize_whitelist_services() -> (Arc<Authorization>, Arc<WhiteListManager>) {
fn initialize_whitelist_services() -> (Arc<WhitelistAuthorization>, Arc<WhiteListManager>) {
let config = configuration::ephemeral_listed();

let database = initialize_database(&config);
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
let whitelist_authorization = Arc::new(Authorization::new(&config.core, &in_memory_whitelist.clone()));
let whitelist_authorization = Arc::new(WhitelistAuthorization::new(&config.core, &in_memory_whitelist.clone()));
let whitelist_manager = initialize_whitelist_manager(database.clone(), in_memory_whitelist.clone());

(whitelist_authorization, whitelist_manager)
2 changes: 1 addition & 1 deletion src/core/whitelist/manager.rs
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ mod tests {
#[allow(clippy::type_complexity)]
fn whitelisted_tracker() -> (
Arc<AnnounceHandler>,
Arc<whitelist::authorization::Authorization>,
Arc<whitelist::authorization::WhitelistAuthorization>,
Arc<WhiteListManager>,
Arc<ScrapeHandler>,
) {
2 changes: 1 addition & 1 deletion src/core/whitelist/mod.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ mod tests {
#[allow(clippy::type_complexity)]
fn whitelisted_tracker() -> (
Arc<AnnounceHandler>,
Arc<whitelist::authorization::Authorization>,
Arc<whitelist::authorization::WhitelistAuthorization>,
Arc<WhiteListManager>,
Arc<ScrapeHandler>,
) {
4 changes: 2 additions & 2 deletions src/servers/http/server.rs
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ impl Launcher {
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
authentication_service: Arc<AuthenticationService>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>>,
tx_start: Sender<Started>,
rx_halt: Receiver<Halted>,
@@ -192,7 +192,7 @@ impl HttpServer<Stopped> {
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
authentication_service: Arc<AuthenticationService>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>>,
form: ServiceRegistrationForm,
) -> Result<HttpServer<Running>, Error> {
10 changes: 5 additions & 5 deletions src/servers/http/v1/handlers/announce.rs
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ pub async fn handle_without_key(
Arc<Core>,
Arc<AnnounceHandler>,
Arc<AuthenticationService>,
Arc<whitelist::authorization::Authorization>,
Arc<whitelist::authorization::WhitelistAuthorization>,
Arc<Option<Box<dyn Sender>>>,
)>,
ExtractRequest(announce_request): ExtractRequest,
@@ -73,7 +73,7 @@ pub async fn handle_with_key(
Arc<Core>,
Arc<AnnounceHandler>,
Arc<AuthenticationService>,
Arc<whitelist::authorization::Authorization>,
Arc<whitelist::authorization::WhitelistAuthorization>,
Arc<Option<Box<dyn Sender>>>,
)>,
ExtractRequest(announce_request): ExtractRequest,
@@ -104,7 +104,7 @@ async fn handle(
config: &Arc<Core>,
announce_handler: &Arc<AnnounceHandler>,
authentication_service: &Arc<AuthenticationService>,
whitelist_authorization: &Arc<whitelist::authorization::Authorization>,
whitelist_authorization: &Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: &Arc<Option<Box<dyn Sender>>>,
announce_request: &Announce,
client_ip_sources: &ClientIpSources,
@@ -139,7 +139,7 @@ async fn handle_announce(
core_config: &Arc<Core>,
announce_handler: &Arc<AnnounceHandler>,
authentication_service: &Arc<AuthenticationService>,
whitelist_authorization: &Arc<whitelist::authorization::Authorization>,
whitelist_authorization: &Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: &Arc<Option<Box<dyn Sender>>>,
announce_request: &Announce,
client_ip_sources: &ClientIpSources,
@@ -265,7 +265,7 @@ mod tests {
Arc<Core>,
Arc<AnnounceHandler>,
Arc<Option<Box<dyn Sender>>>,
Arc<whitelist::authorization::Authorization>,
Arc<whitelist::authorization::WhitelistAuthorization>,
Arc<AuthenticationService>,
);

2 changes: 1 addition & 1 deletion src/servers/http/v1/routes.rs
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ pub fn router(
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
authentication_service: Arc<AuthenticationService>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
server_socket_addr: SocketAddr,
) -> Router {
14 changes: 7 additions & 7 deletions src/servers/udp/handlers.rs
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ pub(crate) async fn handle_packet(
core_config: &Arc<Core>,
announce_handler: &Arc<AnnounceHandler>,
scrape_handler: &Arc<ScrapeHandler>,
whitelist_authorization: &Arc<whitelist::authorization::Authorization>,
whitelist_authorization: &Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: &Arc<Option<Box<dyn Sender>>>,
local_addr: SocketAddr,
cookie_time_values: CookieTimeValues,
@@ -157,7 +157,7 @@ pub async fn handle_request(
core_config: &Arc<Core>,
announce_handler: &Arc<AnnounceHandler>,
scrape_handler: &Arc<ScrapeHandler>,
whitelist_authorization: &Arc<whitelist::authorization::Authorization>,
whitelist_authorization: &Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: &Arc<Option<Box<dyn Sender>>>,
cookie_time_values: CookieTimeValues,
) -> Result<Response, (Error, TransactionId)> {
@@ -247,7 +247,7 @@ pub async fn handle_announce(
request: &AnnounceRequest,
core_config: &Arc<Core>,
announce_handler: &Arc<AnnounceHandler>,
whitelist_authorization: &Arc<whitelist::authorization::Authorization>,
whitelist_authorization: &Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: &Arc<Option<Box<dyn Sender>>>,
cookie_valid_range: Range<f64>,
) -> Result<Response, (Error, TransactionId)> {
@@ -517,7 +517,7 @@ mod tests {
Arc<Option<Box<dyn Sender>>>,
Arc<InMemoryWhitelist>,
Arc<WhiteListManager>,
Arc<whitelist::authorization::Authorization>,
Arc<whitelist::authorization::WhitelistAuthorization>,
);

fn tracker_configuration() -> Configuration {
@@ -672,7 +672,7 @@ mod tests {
Arc<Core>,
Arc<AnnounceHandler>,
Arc<ScrapeHandler>,
Arc<whitelist::authorization::Authorization>,
Arc<whitelist::authorization::WhitelistAuthorization>,
) {
let config = tracker_configuration();

@@ -1088,7 +1088,7 @@ mod tests {
async fn announce_a_new_peer_using_ipv4(
core_config: Arc<Core>,
announce_handler: Arc<AnnounceHandler>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
) -> Response {
let (stats_event_sender, _stats_repository) = crate::core::services::statistics::setup::factory(false);
let stats_event_sender = Arc::new(stats_event_sender);
@@ -1426,7 +1426,7 @@ mod tests {
async fn announce_a_new_peer_using_ipv6(
core_config: Arc<Core>,
announce_handler: Arc<AnnounceHandler>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
) -> Response {
let (stats_event_sender, _stats_repository) = crate::core::services::statistics::setup::factory(false);
let stats_event_sender = Arc::new(stats_event_sender);
4 changes: 2 additions & 2 deletions src/servers/udp/server/launcher.rs
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ impl Launcher {
core_config: Arc<Core>,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: Arc<Option<Box<dyn Sender>>>,
ban_service: Arc<RwLock<BanService>>,
bind_to: SocketAddr,
@@ -159,7 +159,7 @@ impl Launcher {
core_config: Arc<Core>,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: Arc<Option<Box<dyn Sender>>>,
ban_service: Arc<RwLock<BanService>>,
cookie_lifetime: Duration,
4 changes: 2 additions & 2 deletions src/servers/udp/server/processor.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ pub struct Processor {
core_config: Arc<Core>,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: Arc<Option<Box<dyn Sender>>>,
cookie_lifetime: f64,
}
@@ -36,7 +36,7 @@ impl Processor {
core_config: Arc<Core>,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: Arc<Option<Box<dyn Sender>>>,
cookie_lifetime: f64,
) -> Self {
2 changes: 1 addition & 1 deletion src/servers/udp/server/spawner.rs
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ impl Spawner {
core_config: Arc<Core>,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: Arc<Option<Box<dyn Sender>>>,
ban_service: Arc<RwLock<BanService>>,
cookie_lifetime: Duration,
2 changes: 1 addition & 1 deletion src/servers/udp/server/states.rs
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ impl Server<Stopped> {
core_config: Arc<Core>,
announce_handler: Arc<AnnounceHandler>,
scrape_handler: Arc<ScrapeHandler>,
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
opt_stats_event_sender: Arc<Option<Box<dyn Sender>>>,
ban_service: Arc<RwLock<BanService>>,
form: ServiceRegistrationForm,
2 changes: 1 addition & 1 deletion tests/servers/http/environment.rs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ pub struct Environment<S> {
pub authentication_service: Arc<AuthenticationService>,
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
pub stats_repository: Arc<Repository>,
pub whitelist_authorization: Arc<whitelist::authorization::Authorization>,
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
pub whitelist_manager: Arc<WhiteListManager>,
pub registar: Registar,
pub server: HttpServer<S>,
2 changes: 1 addition & 1 deletion tests/servers/udp/environment.rs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ where
pub in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
pub announce_handler: Arc<AnnounceHandler>,
pub scrape_handler: Arc<ScrapeHandler>,
pub whitelist_authorization: Arc<whitelist::authorization::Authorization>,
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
pub stats_repository: Arc<Repository>,
pub ban_service: Arc<RwLock<BanService>>,