diff --git a/src/core/auth/key.rs b/src/core/authentication/key.rs similarity index 89% rename from src/core/auth/key.rs rename to src/core/authentication/key.rs index f0adf5946..8858361ec 100644 --- a/src/core/auth/key.rs +++ b/src/core/authentication/key.rs @@ -12,7 +12,7 @@ //! Keys are stored in this struct: //! //! ```rust,no_run -//! use torrust_tracker_lib::core::auth::Key; +//! use torrust_tracker_lib::core::authentication::Key; //! use torrust_tracker_primitives::DurationSinceUnixEpoch; //! //! pub struct PeerKey { @@ -28,14 +28,14 @@ //! You can generate a new key valid for `9999` seconds and `0` nanoseconds from the current time with the following: //! //! ```rust,no_run -//! use torrust_tracker_lib::core::auth; +//! use torrust_tracker_lib::core::authentication; //! use std::time::Duration; //! -//! let expiring_key = auth::key::generate_key(Some(Duration::new(9999, 0))); +//! let expiring_key = authentication::key::generate_key(Some(Duration::new(9999, 0))); //! //! // And you can later verify it with: //! -//! assert!(auth::key::verify_key_expiration(&expiring_key).is_ok()); +//! assert!(authentication::key::verify_key_expiration(&expiring_key).is_ok()); //! ``` use std::panic::Location; @@ -199,7 +199,7 @@ impl Key { /// Error returned when a key cannot be parsed from a string. /// /// ```text -/// use torrust_tracker_lib::core::auth::Key; +/// use torrust_tracker_lib::core::authentication::Key; /// use std::str::FromStr; /// /// let key_string = "YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ"; @@ -229,7 +229,7 @@ impl FromStr for Key { } /// Verification error. Error returned when an [`PeerKey`] cannot be -/// verified with the (`crate::core::auth::verify_key`) function. +/// verified with the (`crate::core::authentication::verify_key`) function. #[derive(Debug, Error)] #[allow(dead_code)] pub enum Error { @@ -260,7 +260,7 @@ mod tests { mod key { use std::str::FromStr; - use crate::core::auth::Key; + use crate::core::authentication::Key; #[test] fn should_be_parsed_from_an_string() { @@ -295,12 +295,12 @@ mod tests { use torrust_tracker_clock::clock; use torrust_tracker_clock::clock::stopped::Stopped as _; - use crate::core::auth; + use crate::core::authentication; #[test] fn should_be_parsed_from_an_string() { let key_string = "YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ"; - let auth_key = auth::Key::from_str(key_string); + let auth_key = authentication::Key::from_str(key_string); assert!(auth_key.is_ok()); assert_eq!(auth_key.unwrap().to_string(), key_string); @@ -311,7 +311,7 @@ mod tests { // Set the time to the current time. clock::Stopped::local_set_to_unix_epoch(); - let expiring_key = auth::key::generate_key(Some(Duration::from_secs(0))); + let expiring_key = authentication::key::generate_key(Some(Duration::from_secs(0))); assert_eq!( expiring_key.to_string(), @@ -321,9 +321,9 @@ mod tests { #[test] fn should_be_generated_with_a_expiration_time() { - let expiring_key = auth::key::generate_key(Some(Duration::new(9999, 0))); + let expiring_key = authentication::key::generate_key(Some(Duration::new(9999, 0))); - assert!(auth::key::verify_key_expiration(&expiring_key).is_ok()); + assert!(authentication::key::verify_key_expiration(&expiring_key).is_ok()); } #[test] @@ -332,17 +332,17 @@ mod tests { clock::Stopped::local_set_to_system_time_now(); // Make key that is valid for 19 seconds. - let expiring_key = auth::key::generate_key(Some(Duration::from_secs(19))); + let expiring_key = authentication::key::generate_key(Some(Duration::from_secs(19))); // Mock the time has passed 10 sec. clock::Stopped::local_add(&Duration::from_secs(10)).unwrap(); - assert!(auth::key::verify_key_expiration(&expiring_key).is_ok()); + assert!(authentication::key::verify_key_expiration(&expiring_key).is_ok()); // Mock the time has passed another 10 sec. clock::Stopped::local_add(&Duration::from_secs(10)).unwrap(); - assert!(auth::key::verify_key_expiration(&expiring_key).is_err()); + assert!(authentication::key::verify_key_expiration(&expiring_key).is_err()); } } } diff --git a/src/core/auth/mod.rs b/src/core/authentication/mod.rs similarity index 100% rename from src/core/auth/mod.rs rename to src/core/authentication/mod.rs diff --git a/src/core/databases/mod.rs b/src/core/databases/mod.rs index e29ce22e8..e0b1b4f1b 100644 --- a/src/core/databases/mod.rs +++ b/src/core/databases/mod.rs @@ -54,7 +54,7 @@ use bittorrent_primitives::info_hash::InfoHash; use torrust_tracker_primitives::PersistentTorrents; use self::error::Error; -use crate::core::auth::{self, Key}; +use crate::core::authentication::{self, Key}; struct Builder where @@ -195,11 +195,11 @@ pub trait Database: Sync + Send { /// # Errors /// /// Will return `Err` if unable to load. - fn load_keys(&self) -> Result, Error>; + fn load_keys(&self) -> Result, Error>; /// It gets an expiring authentication key from the database. /// - /// It returns `Some(PeerKey)` if a [`PeerKey`](crate::core::auth::PeerKey) + /// It returns `Some(PeerKey)` if a [`PeerKey`](crate::core::authentication::PeerKey) /// with the input [`Key`] exists, `None` otherwise. /// /// # Context: Authentication Keys @@ -207,7 +207,7 @@ pub trait Database: Sync + Send { /// # Errors /// /// Will return `Err` if unable to load. - fn get_key_from_keys(&self, key: &Key) -> Result, Error>; + fn get_key_from_keys(&self, key: &Key) -> Result, Error>; /// It adds an expiring authentication key to the database. /// @@ -216,7 +216,7 @@ pub trait Database: Sync + Send { /// # Errors /// /// Will return `Err` if unable to save. - fn add_key_to_keys(&self, auth_key: &auth::PeerKey) -> Result; + fn add_key_to_keys(&self, auth_key: &authentication::PeerKey) -> Result; /// It removes an expiring authentication key from the database. /// diff --git a/src/core/databases/mysql.rs b/src/core/databases/mysql.rs index 1b849421b..213f6300a 100644 --- a/src/core/databases/mysql.rs +++ b/src/core/databases/mysql.rs @@ -11,7 +11,7 @@ use torrust_tracker_primitives::PersistentTorrents; use super::driver::Driver; use super::{Database, Error}; -use crate::core::auth::{self, Key}; +use crate::core::authentication::{self, Key}; use crate::shared::bit_torrent::common::AUTH_KEY_LENGTH; const DRIVER: Driver = Driver::MySQL; @@ -63,7 +63,7 @@ impl Database for Mysql { PRIMARY KEY (`id`), UNIQUE (`key`) );", - i8::try_from(AUTH_KEY_LENGTH).expect("auth::Auth Key Length Should fit within a i8!") + i8::try_from(AUTH_KEY_LENGTH).expect("authentication key length should fit within a i8!") ); let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?; @@ -118,17 +118,17 @@ impl Database for Mysql { } /// Refer to [`databases::Database::load_keys`](crate::core::databases::Database::load_keys). - fn load_keys(&self) -> Result, Error> { + fn load_keys(&self) -> Result, Error> { let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?; let keys = conn.query_map( "SELECT `key`, valid_until FROM `keys`", |(key, valid_until): (String, Option)| match valid_until { - Some(valid_until) => auth::PeerKey { + Some(valid_until) => authentication::PeerKey { key: key.parse::().unwrap(), valid_until: Some(Duration::from_secs(valid_until.unsigned_abs())), }, - None => auth::PeerKey { + None => authentication::PeerKey { key: key.parse::().unwrap(), valid_until: None, }, @@ -202,7 +202,7 @@ impl Database for Mysql { } /// Refer to [`databases::Database::get_key_from_keys`](crate::core::databases::Database::get_key_from_keys). - fn get_key_from_keys(&self, key: &Key) -> Result, Error> { + fn get_key_from_keys(&self, key: &Key) -> Result, Error> { let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?; let query = conn.exec_first::<(String, Option), _, _>( @@ -213,11 +213,11 @@ impl Database for Mysql { let key = query?; Ok(key.map(|(key, opt_valid_until)| match opt_valid_until { - Some(valid_until) => auth::PeerKey { + Some(valid_until) => authentication::PeerKey { key: key.parse::().unwrap(), valid_until: Some(Duration::from_secs(valid_until.unsigned_abs())), }, - None => auth::PeerKey { + None => authentication::PeerKey { key: key.parse::().unwrap(), valid_until: None, }, @@ -225,7 +225,7 @@ impl Database for Mysql { } /// Refer to [`databases::Database::add_key_to_keys`](crate::core::databases::Database::add_key_to_keys). - fn add_key_to_keys(&self, auth_key: &auth::PeerKey) -> Result { + fn add_key_to_keys(&self, auth_key: &authentication::PeerKey) -> Result { let mut conn = self.pool.get().map_err(|e| (e, DRIVER))?; let key = auth_key.key.to_string(); diff --git a/src/core/databases/sqlite.rs b/src/core/databases/sqlite.rs index 5bb23bb3e..6fe9ac599 100644 --- a/src/core/databases/sqlite.rs +++ b/src/core/databases/sqlite.rs @@ -11,7 +11,7 @@ use torrust_tracker_primitives::{DurationSinceUnixEpoch, PersistentTorrents}; use super::driver::Driver; use super::{Database, Error}; -use crate::core::auth::{self, Key}; +use crate::core::authentication::{self, Key}; const DRIVER: Driver = Driver::Sqlite3; @@ -106,7 +106,7 @@ impl Database for Sqlite { } /// Refer to [`databases::Database::load_keys`](crate::core::databases::Database::load_keys). - fn load_keys(&self) -> Result, Error> { + fn load_keys(&self) -> Result, Error> { let conn = self.pool.get().map_err(|e| (e, DRIVER))?; let mut stmt = conn.prepare("SELECT key, valid_until FROM keys")?; @@ -116,18 +116,18 @@ impl Database for Sqlite { let opt_valid_until: Option = row.get(1)?; match opt_valid_until { - Some(valid_until) => Ok(auth::PeerKey { + Some(valid_until) => Ok(authentication::PeerKey { key: key.parse::().unwrap(), valid_until: Some(DurationSinceUnixEpoch::from_secs(valid_until.unsigned_abs())), }), - None => Ok(auth::PeerKey { + None => Ok(authentication::PeerKey { key: key.parse::().unwrap(), valid_until: None, }), } })?; - let keys: Vec = keys_iter.filter_map(std::result::Result::ok).collect(); + let keys: Vec = keys_iter.filter_map(std::result::Result::ok).collect(); Ok(keys) } @@ -216,7 +216,7 @@ impl Database for Sqlite { } /// Refer to [`databases::Database::get_key_from_keys`](crate::core::databases::Database::get_key_from_keys). - fn get_key_from_keys(&self, key: &Key) -> Result, Error> { + fn get_key_from_keys(&self, key: &Key) -> Result, Error> { let conn = self.pool.get().map_err(|e| (e, DRIVER))?; let mut stmt = conn.prepare("SELECT key, valid_until FROM keys WHERE key = ?")?; @@ -230,11 +230,11 @@ impl Database for Sqlite { let key: String = f.get(0).unwrap(); match valid_until { - Some(valid_until) => auth::PeerKey { + Some(valid_until) => authentication::PeerKey { key: key.parse::().unwrap(), valid_until: Some(DurationSinceUnixEpoch::from_secs(valid_until.unsigned_abs())), }, - None => auth::PeerKey { + None => authentication::PeerKey { key: key.parse::().unwrap(), valid_until: None, }, @@ -243,7 +243,7 @@ impl Database for Sqlite { } /// Refer to [`databases::Database::add_key_to_keys`](crate::core::databases::Database::add_key_to_keys). - fn add_key_to_keys(&self, auth_key: &auth::PeerKey) -> Result { + fn add_key_to_keys(&self, auth_key: &authentication::PeerKey) -> Result { let conn = self.pool.get().map_err(|e| (e, DRIVER))?; let insert = match auth_key.valid_until { diff --git a/src/core/error.rs b/src/core/error.rs index f0e4b849e..434e3c825 100644 --- a/src/core/error.rs +++ b/src/core/error.rs @@ -12,7 +12,7 @@ use bittorrent_http_protocol::v1::responses; use bittorrent_primitives::info_hash::InfoHash; use torrust_tracker_located_error::LocatedError; -use super::{auth::key::ParseKeyError, databases}; +use super::{authentication::key::ParseKeyError, databases}; /// Authentication or authorization error returned by the core `Tracker` #[derive(thiserror::Error, Debug, Clone)] @@ -20,7 +20,7 @@ pub enum Error { // Authentication errors #[error("The supplied key: {key:?}, is not valid: {source}")] PeerKeyNotValid { - key: super::auth::Key, + key: super::authentication::Key, source: LocatedError<'static, dyn std::error::Error + Send + Sync>, }, diff --git a/src/core/mod.rs b/src/core/mod.rs index e0e53128d..11945a79a 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -439,7 +439,7 @@ //! - Torrent metrics //! //! Refer to [`databases`] module for more information about persistence. -pub mod auth; +pub mod authentication; pub mod databases; pub mod error; pub mod services; @@ -455,7 +455,7 @@ use std::panic::Location; use std::sync::Arc; use std::time::Duration; -use auth::PeerKey; +use authentication::PeerKey; use bittorrent_primitives::info_hash::InfoHash; use error::PeerKeyError; use torrust_tracker_clock::clock::Time; @@ -468,7 +468,7 @@ use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch}; use torrust_tracker_torrent_repository::entry::EntrySync; use torrust_tracker_torrent_repository::repository::Repository; -use self::auth::Key; +use self::authentication::Key; use self::torrent::Torrents; use crate::core::databases::Database; use crate::CurrentClock; @@ -491,7 +491,7 @@ pub struct Tracker { database: Arc>, /// Tracker users' keys. Only for private trackers. - keys: tokio::sync::RwLock>, + keys: tokio::sync::RwLock>, /// The service to check is a torrent is whitelisted. pub whitelist_authorization: Arc, @@ -786,7 +786,7 @@ impl Tracker { /// Will return an error if the the authentication key cannot be verified. /// /// # Context: Authentication - pub async fn authenticate(&self, key: &Key) -> Result<(), auth::Error> { + pub async fn authenticate(&self, key: &Key) -> Result<(), authentication::Error> { if self.is_private() { self.verify_auth_key(key).await } else { @@ -805,7 +805,7 @@ impl Tracker { /// - The key duration overflows the duration type maximum value. /// - The provided pre-generated key is invalid. /// - The key could not been persisted due to database issues. - pub async fn add_peer_key(&self, add_key_req: AddKeyRequest) -> Result { + pub async fn add_peer_key(&self, add_key_req: AddKeyRequest) -> Result { // code-review: all methods related to keys should be moved to a new independent "keys" service. match add_key_req.opt_key { @@ -878,7 +878,7 @@ impl Tracker { /// # Errors /// /// Will return a `database::Error` if unable to add the `auth_key` to the database. - pub async fn generate_permanent_auth_key(&self) -> Result { + pub async fn generate_permanent_auth_key(&self) -> Result { self.generate_auth_key(None).await } @@ -896,8 +896,11 @@ impl Tracker { /// /// * `lifetime` - The duration in seconds for the new key. The key will be /// no longer valid after `lifetime` seconds. - pub async fn generate_auth_key(&self, lifetime: Option) -> Result { - let auth_key = auth::key::generate_key(lifetime); + pub async fn generate_auth_key( + &self, + lifetime: Option, + ) -> Result { + let auth_key = authentication::key::generate_key(lifetime); self.database.add_key_to_keys(&auth_key)?; self.keys.write().await.insert(auth_key.key.clone(), auth_key.clone()); @@ -918,7 +921,7 @@ impl Tracker { /// # Arguments /// /// * `key` - The pre-generated key. - pub async fn add_permanent_auth_key(&self, key: Key) -> Result { + pub async fn add_permanent_auth_key(&self, key: Key) -> Result { self.add_auth_key(key, None).await } @@ -942,7 +945,7 @@ impl Tracker { &self, key: Key, valid_until: Option, - ) -> Result { + ) -> Result { let auth_key = PeerKey { key, valid_until }; // code-review: should we return a friendly error instead of the DB @@ -973,21 +976,21 @@ impl Tracker { /// # Errors /// /// Will return a `key::Error` if unable to get any `auth_key`. - async fn verify_auth_key(&self, key: &Key) -> Result<(), auth::Error> { + async fn verify_auth_key(&self, key: &Key) -> Result<(), authentication::Error> { match self.keys.read().await.get(key) { - None => Err(auth::Error::UnableToReadKey { + None => Err(authentication::Error::UnableToReadKey { location: Location::caller(), key: Box::new(key.clone()), }), Some(key) => match self.config.private_mode { Some(private_mode) => { if private_mode.check_keys_expiration { - return auth::key::verify_key_expiration(key); + return authentication::key::verify_key_expiration(key); } Ok(()) } - None => auth::key::verify_key_expiration(key), + None => authentication::key::verify_key_expiration(key), }, } } @@ -1746,14 +1749,14 @@ mod tests { use std::str::FromStr; use std::time::Duration; - use crate::core::auth::{self}; + use crate::core::authentication::{self}; use crate::core::tests::the_tracker::private_tracker; #[tokio::test] async fn it_should_fail_authenticating_a_peer_when_it_uses_an_unregistered_key() { let tracker = private_tracker(); - let unregistered_key = auth::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(); + let unregistered_key = authentication::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(); let result = tracker.authenticate(&unregistered_key).await; @@ -1764,7 +1767,7 @@ mod tests { async fn it_should_fail_verifying_an_unregistered_authentication_key() { let tracker = private_tracker(); - let unregistered_key = auth::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(); + let unregistered_key = authentication::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(); assert!(tracker.verify_auth_key(&unregistered_key).await.is_err()); } @@ -1804,7 +1807,7 @@ mod tests { use torrust_tracker_clock::clock::Time; use torrust_tracker_configuration::v2_0_0::core::PrivateMode; - use crate::core::auth::Key; + use crate::core::authentication::Key; use crate::core::tests::the_tracker::private_tracker; use crate::CurrentClock; @@ -1856,7 +1859,7 @@ mod tests { use torrust_tracker_clock::clock::Time; use torrust_tracker_configuration::v2_0_0::core::PrivateMode; - use crate::core::auth::Key; + use crate::core::authentication::Key; use crate::core::tests::the_tracker::private_tracker; use crate::core::AddKeyRequest; use crate::CurrentClock; @@ -1944,7 +1947,7 @@ mod tests { } mod pre_generated_keys { - use crate::core::auth::Key; + use crate::core::authentication::Key; use crate::core::tests::the_tracker::private_tracker; use crate::core::AddKeyRequest; diff --git a/src/servers/apis/v1/context/auth_key/handlers.rs b/src/servers/apis/v1/context/auth_key/handlers.rs index fed3ad301..bb8a98744 100644 --- a/src/servers/apis/v1/context/auth_key/handlers.rs +++ b/src/servers/apis/v1/context/auth_key/handlers.rs @@ -12,7 +12,7 @@ use super::responses::{ auth_key_response, failed_to_delete_key_response, failed_to_generate_key_response, failed_to_reload_keys_response, invalid_auth_key_duration_response, invalid_auth_key_response, }; -use crate::core::auth::Key; +use crate::core::authentication::Key; use crate::core::{AddKeyRequest, Tracker}; use crate::servers::apis::v1::context::auth_key::resources::AuthKey; use crate::servers::apis::v1::responses::{invalid_auth_key_param_response, ok_response}; diff --git a/src/servers/apis/v1/context/auth_key/resources.rs b/src/servers/apis/v1/context/auth_key/resources.rs index c26b2c4d3..a65eb2ab2 100644 --- a/src/servers/apis/v1/context/auth_key/resources.rs +++ b/src/servers/apis/v1/context/auth_key/resources.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use torrust_tracker_clock::conv::convert_from_iso_8601_to_timestamp; -use crate::core::auth::{self, Key}; +use crate::core::authentication::{self, Key}; /// A resource that represents an authentication key. #[derive(Serialize, Deserialize, Debug, PartialEq, Eq)] @@ -17,9 +17,9 @@ pub struct AuthKey { pub expiry_time: Option, } -impl From for auth::PeerKey { +impl From for authentication::PeerKey { fn from(auth_key_resource: AuthKey) -> Self { - auth::PeerKey { + authentication::PeerKey { key: auth_key_resource.key.parse::().unwrap(), valid_until: auth_key_resource .expiry_time @@ -29,8 +29,8 @@ impl From for auth::PeerKey { } #[allow(deprecated)] -impl From for AuthKey { - fn from(auth_key: auth::PeerKey) -> Self { +impl From for AuthKey { + fn from(auth_key: authentication::PeerKey) -> Self { match (auth_key.valid_until, auth_key.expiry_time()) { (Some(valid_until), Some(expiry_time)) => AuthKey { key: auth_key.key.to_string(), @@ -54,7 +54,7 @@ mod tests { use torrust_tracker_clock::clock::{self, Time}; use super::AuthKey; - use crate::core::auth::{self, Key}; + use crate::core::authentication::{self, Key}; use crate::CurrentClock; struct TestTime { @@ -86,8 +86,8 @@ mod tests { }; assert_eq!( - auth::PeerKey::from(auth_key_resource), - auth::PeerKey { + authentication::PeerKey::from(auth_key_resource), + authentication::PeerKey { key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".parse::().unwrap(), // cspell:disable-line valid_until: Some(CurrentClock::now_add(&Duration::new(one_hour_after_unix_epoch().timestamp, 0)).unwrap()) } @@ -99,7 +99,7 @@ mod tests { fn it_should_be_convertible_from_an_auth_key() { clock::Stopped::local_set_to_unix_epoch(); - let auth_key = auth::PeerKey { + let auth_key = authentication::PeerKey { key: "IaWDneuFNZi8IB4MPA3qW1CD0M30EZSM".parse::().unwrap(), // cspell:disable-line valid_until: Some(CurrentClock::now_add(&Duration::new(one_hour_after_unix_epoch().timestamp, 0)).unwrap()), }; diff --git a/src/servers/http/v1/extractors/authentication_key.rs b/src/servers/http/v1/extractors/authentication_key.rs index 6610b197a..d3b77c31a 100644 --- a/src/servers/http/v1/extractors/authentication_key.rs +++ b/src/servers/http/v1/extractors/authentication_key.rs @@ -53,7 +53,7 @@ use bittorrent_http_protocol::v1::responses; use hyper::StatusCode; use serde::Deserialize; -use crate::core::auth::Key; +use crate::core::authentication::Key; use crate::servers::http::v1::handlers::common::auth; /// Extractor for the [`Key`] struct. diff --git a/src/servers/http/v1/handlers/announce.rs b/src/servers/http/v1/handlers/announce.rs index 61464f1d5..fe3825a41 100644 --- a/src/servers/http/v1/handlers/announce.rs +++ b/src/servers/http/v1/handlers/announce.rs @@ -21,7 +21,7 @@ use torrust_tracker_clock::clock::Time; use torrust_tracker_primitives::core::AnnounceData; use torrust_tracker_primitives::peer; -use crate::core::auth::Key; +use crate::core::authentication::Key; use crate::core::statistics::event::sender::Sender; use crate::core::{whitelist, PeersWanted, Tracker}; use crate::servers::http::v1::extractors::announce_request::ExtractRequest; @@ -290,7 +290,7 @@ mod tests { use std::sync::Arc; use super::{private_tracker, sample_announce_request, sample_client_ip_sources}; - use crate::core::auth; + use crate::core::authentication; use crate::servers::http::v1::handlers::announce::handle_announce; use crate::servers::http::v1::handlers::announce::tests::assert_error_response; @@ -327,7 +327,7 @@ mod tests { let tracker = Arc::new(tracker); let stats_event_sender = Arc::new(stats_event_sender); - let unregistered_key = auth::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(); + let unregistered_key = authentication::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(); let maybe_key = Some(unregistered_key); diff --git a/src/servers/http/v1/handlers/common/auth.rs b/src/servers/http/v1/handlers/common/auth.rs index ff1d47e91..5497427d8 100644 --- a/src/servers/http/v1/handlers/common/auth.rs +++ b/src/servers/http/v1/handlers/common/auth.rs @@ -6,7 +6,7 @@ use std::panic::Location; use bittorrent_http_protocol::v1::responses; use thiserror::Error; -use crate::core::auth; +use crate::core::authentication; /// Authentication error. /// @@ -31,8 +31,8 @@ impl From for responses::error::Error { } } -impl From for responses::error::Error { - fn from(err: auth::Error) -> Self { +impl From for responses::error::Error { + fn from(err: authentication::Error) -> Self { responses::error::Error { failure_reason: format!("Authentication error: {err}"), } diff --git a/src/servers/http/v1/handlers/scrape.rs b/src/servers/http/v1/handlers/scrape.rs index 9c57eda58..58c2d012b 100644 --- a/src/servers/http/v1/handlers/scrape.rs +++ b/src/servers/http/v1/handlers/scrape.rs @@ -15,7 +15,7 @@ use bittorrent_http_protocol::v1::services::peer_ip_resolver::{self, ClientIpSou use hyper::StatusCode; use torrust_tracker_primitives::core::ScrapeData; -use crate::core::auth::Key; +use crate::core::authentication::Key; use crate::core::statistics::event::sender::Sender; use crate::core::Tracker; use crate::servers::http::v1::extractors::authentication_key::Extract as ExtractKey; @@ -205,7 +205,7 @@ mod tests { use torrust_tracker_primitives::core::ScrapeData; use super::{private_tracker, sample_client_ip_sources, sample_scrape_request}; - use crate::core::auth; + use crate::core::authentication; use crate::servers::http::v1::handlers::scrape::handle_scrape; #[tokio::test] @@ -239,7 +239,7 @@ mod tests { let stats_event_sender = Arc::new(stats_event_sender); let scrape_request = sample_scrape_request(); - let unregistered_key = auth::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(); + let unregistered_key = authentication::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(); let maybe_key = Some(unregistered_key); let scrape_data = handle_scrape( diff --git a/src/shared/bit_torrent/common.rs b/src/shared/bit_torrent/common.rs index 46026ac47..5ba2e0492 100644 --- a/src/shared/bit_torrent/common.rs +++ b/src/shared/bit_torrent/common.rs @@ -17,6 +17,6 @@ pub const MAX_SCRAPE_TORRENTS: u8 = 74; /// HTTP tracker authentication key length. /// -/// For more information see function [`generate_key`](crate::core::auth::generate_key) to generate the -/// [`PeerKey`](crate::core::auth::PeerKey). +/// For more information see function [`generate_key`](crate::core::authentication::generate_key) to generate the +/// [`PeerKey`](crate::core::authentication::PeerKey). pub const AUTH_KEY_LENGTH: usize = 32; diff --git a/tests/servers/api/v1/contract/context/auth_key.rs b/tests/servers/api/v1/contract/context/auth_key.rs index 9b2e740c0..40c10be5f 100644 --- a/tests/servers/api/v1/contract/context/auth_key.rs +++ b/tests/servers/api/v1/contract/context/auth_key.rs @@ -2,7 +2,7 @@ use std::time::Duration; use serde::Serialize; use torrust_tracker_api_client::v1::client::{headers_with_request_id, AddKeyForm, Client}; -use torrust_tracker_lib::core::auth::Key; +use torrust_tracker_lib::core::authentication::Key; use torrust_tracker_test_helpers::configuration; use uuid::Uuid; @@ -463,7 +463,7 @@ async fn should_not_allow_reloading_keys_for_unauthenticated_users() { mod deprecated_generate_key_endpoint { use torrust_tracker_api_client::v1::client::{headers_with_request_id, Client}; - use torrust_tracker_lib::core::auth::Key; + use torrust_tracker_lib::core::authentication::Key; use torrust_tracker_test_helpers::configuration; use uuid::Uuid; diff --git a/tests/servers/http/client.rs b/tests/servers/http/client.rs index b64a616cd..9fc278536 100644 --- a/tests/servers/http/client.rs +++ b/tests/servers/http/client.rs @@ -1,7 +1,7 @@ use std::net::IpAddr; use reqwest::{Client as ReqwestClient, Response}; -use torrust_tracker_lib::core::auth::Key; +use torrust_tracker_lib::core::authentication::Key; use super::requests::announce::{self, Query}; use super::requests::scrape; diff --git a/tests/servers/http/connection_info.rs b/tests/servers/http/connection_info.rs index 123ac05f0..327bc0073 100644 --- a/tests/servers/http/connection_info.rs +++ b/tests/servers/http/connection_info.rs @@ -1,4 +1,4 @@ -use torrust_tracker_lib::core::auth::Key; +use torrust_tracker_lib::core::authentication::Key; #[derive(Clone, Debug)] pub struct ConnectionInfo { diff --git a/tests/servers/http/v1/contract.rs b/tests/servers/http/v1/contract.rs index 2cec1790f..961caf017 100644 --- a/tests/servers/http/v1/contract.rs +++ b/tests/servers/http/v1/contract.rs @@ -1381,7 +1381,7 @@ mod configured_as_private { use std::time::Duration; use bittorrent_primitives::info_hash::InfoHash; - use torrust_tracker_lib::core::auth::Key; + use torrust_tracker_lib::core::authentication::Key; use torrust_tracker_test_helpers::configuration; use crate::common::logging; @@ -1467,7 +1467,7 @@ mod configured_as_private { use aquatic_udp_protocol::PeerId; use bittorrent_primitives::info_hash::InfoHash; - use torrust_tracker_lib::core::auth::Key; + use torrust_tracker_lib::core::authentication::Key; use torrust_tracker_primitives::peer::fixture::PeerBuilder; use torrust_tracker_test_helpers::configuration;