Skip to content

Commit f41a524

Browse files
committed
refactor: [#1191] remove duplicate tests for private tracker
There were copied to the authentication module.
1 parent 9a60c0c commit f41a524

File tree

1 file changed

+0
-295
lines changed

1 file changed

+0
-295
lines changed

src/core/mod.rs

-295
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,6 @@ mod tests {
803803
use aquatic_udp_protocol::{AnnounceEvent, NumberOfBytes, PeerId};
804804
use bittorrent_primitives::info_hash::fixture::gen_seeded_infohash;
805805
use bittorrent_primitives::info_hash::InfoHash;
806-
use torrust_tracker_configuration::v2_0_0::core::PrivateMode;
807806
use torrust_tracker_configuration::TORRENT_PEERS_LIMIT;
808807
use torrust_tracker_primitives::DurationSinceUnixEpoch;
809808
use torrust_tracker_test_helpers::configuration;
@@ -823,15 +822,6 @@ mod tests {
823822
initialize_tracker(&config, &database, &whitelist_authorization, &authentication)
824823
}
825824

826-
fn private_tracker() -> Tracker {
827-
let config = configuration::ephemeral_private();
828-
829-
let (database, _in_memory_whitelist, whitelist_authorization, authentication) =
830-
initialize_tracker_dependencies(&config);
831-
832-
initialize_tracker(&config, &database, &whitelist_authorization, &authentication)
833-
}
834-
835825
fn whitelisted_tracker() -> (Tracker, Arc<whitelist::authorization::Authorization>, Arc<WhiteListManager>) {
836826
let config = configuration::ephemeral_listed();
837827

@@ -845,19 +835,6 @@ mod tests {
845835
(tracker, whitelist_authorization, whitelist_manager)
846836
}
847837

848-
fn private_tracker_without_checking_keys_expiration() -> Tracker {
849-
let mut config = configuration::ephemeral_private();
850-
851-
config.core.private_mode = Some(PrivateMode {
852-
check_keys_expiration: false,
853-
});
854-
855-
let (database, _in_memory_whitelist, whitelist_authorization, authentication) =
856-
initialize_tracker_dependencies(&config);
857-
858-
initialize_tracker(&config, &database, &whitelist_authorization, &authentication)
859-
}
860-
861838
pub fn tracker_persisting_torrents_in_database() -> Tracker {
862839
let mut config = configuration::ephemeral_listed();
863840
config.core.tracker_policy.persistent_torrent_completed_stat = true;
@@ -1516,278 +1493,6 @@ mod tests {
15161493
}
15171494
}
15181495

1519-
mod configured_as_private {
1520-
1521-
mod handling_authentication {
1522-
use std::str::FromStr;
1523-
use std::time::Duration;
1524-
1525-
use crate::core::authentication::{self};
1526-
use crate::core::tests::the_tracker::private_tracker;
1527-
1528-
#[tokio::test]
1529-
async fn it_should_fail_authenticating_a_peer_when_it_uses_an_unregistered_key() {
1530-
let tracker = private_tracker();
1531-
1532-
let unregistered_key = authentication::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap();
1533-
1534-
let result = tracker.authentication.authenticate(&unregistered_key).await;
1535-
1536-
assert!(result.is_err());
1537-
}
1538-
1539-
#[tokio::test]
1540-
async fn it_should_fail_verifying_an_unregistered_authentication_key() {
1541-
let tracker = private_tracker();
1542-
1543-
let unregistered_key = authentication::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap();
1544-
1545-
assert!(tracker.authentication.verify_auth_key(&unregistered_key).await.is_err());
1546-
}
1547-
1548-
#[tokio::test]
1549-
async fn it_should_remove_an_authentication_key() {
1550-
let tracker = private_tracker();
1551-
1552-
let expiring_key = tracker
1553-
.authentication
1554-
.generate_auth_key(Some(Duration::from_secs(100)))
1555-
.await
1556-
.unwrap();
1557-
1558-
let result = tracker.authentication.remove_auth_key(&expiring_key.key()).await;
1559-
1560-
assert!(result.is_ok());
1561-
assert!(tracker.authentication.verify_auth_key(&expiring_key.key()).await.is_err());
1562-
}
1563-
1564-
#[tokio::test]
1565-
async fn it_should_load_authentication_keys_from_the_database() {
1566-
let tracker = private_tracker();
1567-
1568-
let expiring_key = tracker
1569-
.authentication
1570-
.generate_auth_key(Some(Duration::from_secs(100)))
1571-
.await
1572-
.unwrap();
1573-
1574-
// Remove the newly generated key in memory
1575-
tracker.authentication.remove_in_memory_auth_key(&expiring_key.key()).await;
1576-
1577-
let result = tracker.authentication.load_keys_from_database().await;
1578-
1579-
assert!(result.is_ok());
1580-
assert!(tracker.authentication.verify_auth_key(&expiring_key.key()).await.is_ok());
1581-
}
1582-
1583-
mod with_expiring_and {
1584-
1585-
mod randomly_generated_keys {
1586-
use std::time::Duration;
1587-
1588-
use torrust_tracker_clock::clock::Time;
1589-
1590-
use crate::core::authentication::Key;
1591-
use crate::core::tests::the_tracker::{
1592-
private_tracker, private_tracker_without_checking_keys_expiration,
1593-
};
1594-
use crate::CurrentClock;
1595-
1596-
#[tokio::test]
1597-
async fn it_should_generate_the_key() {
1598-
let tracker = private_tracker();
1599-
1600-
let peer_key = tracker
1601-
.authentication
1602-
.generate_auth_key(Some(Duration::from_secs(100)))
1603-
.await
1604-
.unwrap();
1605-
1606-
assert_eq!(
1607-
peer_key.valid_until,
1608-
Some(CurrentClock::now_add(&Duration::from_secs(100)).unwrap())
1609-
);
1610-
}
1611-
1612-
#[tokio::test]
1613-
async fn it_should_authenticate_a_peer_with_the_key() {
1614-
let tracker = private_tracker();
1615-
1616-
let peer_key = tracker
1617-
.authentication
1618-
.generate_auth_key(Some(Duration::from_secs(100)))
1619-
.await
1620-
.unwrap();
1621-
1622-
let result = tracker.authentication.authenticate(&peer_key.key()).await;
1623-
1624-
assert!(result.is_ok());
1625-
}
1626-
1627-
#[tokio::test]
1628-
async fn it_should_accept_an_expired_key_when_checking_expiration_is_disabled_in_configuration() {
1629-
let tracker = private_tracker_without_checking_keys_expiration();
1630-
1631-
let past_timestamp = Duration::ZERO;
1632-
1633-
let peer_key = tracker
1634-
.authentication
1635-
.add_auth_key(Key::new("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(), Some(past_timestamp))
1636-
.await
1637-
.unwrap();
1638-
1639-
assert!(tracker.authentication.authenticate(&peer_key.key()).await.is_ok());
1640-
}
1641-
}
1642-
1643-
mod pre_generated_keys {
1644-
use std::time::Duration;
1645-
1646-
use torrust_tracker_clock::clock::Time;
1647-
use torrust_tracker_configuration::v2_0_0::core::PrivateMode;
1648-
1649-
use crate::core::authentication::{AddKeyRequest, Key};
1650-
use crate::core::tests::the_tracker::private_tracker;
1651-
use crate::CurrentClock;
1652-
1653-
#[tokio::test]
1654-
async fn it_should_add_a_pre_generated_key() {
1655-
let tracker = private_tracker();
1656-
1657-
let peer_key = tracker
1658-
.authentication
1659-
.add_peer_key(AddKeyRequest {
1660-
opt_key: Some(Key::new("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap().to_string()),
1661-
opt_seconds_valid: Some(100),
1662-
})
1663-
.await
1664-
.unwrap();
1665-
1666-
assert_eq!(
1667-
peer_key.valid_until,
1668-
Some(CurrentClock::now_add(&Duration::from_secs(100)).unwrap())
1669-
);
1670-
}
1671-
1672-
#[tokio::test]
1673-
async fn it_should_authenticate_a_peer_with_the_key() {
1674-
let tracker = private_tracker();
1675-
1676-
let peer_key = tracker
1677-
.authentication
1678-
.add_peer_key(AddKeyRequest {
1679-
opt_key: Some(Key::new("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap().to_string()),
1680-
opt_seconds_valid: Some(100),
1681-
})
1682-
.await
1683-
.unwrap();
1684-
1685-
let result = tracker.authentication.authenticate(&peer_key.key()).await;
1686-
1687-
assert!(result.is_ok());
1688-
}
1689-
1690-
#[tokio::test]
1691-
async fn it_should_accept_an_expired_key_when_checking_expiration_is_disabled_in_configuration() {
1692-
let mut tracker = private_tracker();
1693-
1694-
tracker.config.private_mode = Some(PrivateMode {
1695-
check_keys_expiration: false,
1696-
});
1697-
1698-
let peer_key = tracker
1699-
.authentication
1700-
.add_peer_key(AddKeyRequest {
1701-
opt_key: Some(Key::new("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap().to_string()),
1702-
opt_seconds_valid: Some(0),
1703-
})
1704-
.await
1705-
.unwrap();
1706-
1707-
assert!(tracker.authentication.authenticate(&peer_key.key()).await.is_ok());
1708-
}
1709-
}
1710-
}
1711-
1712-
mod with_permanent_and {
1713-
1714-
mod randomly_generated_keys {
1715-
use crate::core::tests::the_tracker::private_tracker;
1716-
1717-
#[tokio::test]
1718-
async fn it_should_generate_the_key() {
1719-
let tracker = private_tracker();
1720-
1721-
let peer_key = tracker.authentication.generate_permanent_auth_key().await.unwrap();
1722-
1723-
assert_eq!(peer_key.valid_until, None);
1724-
}
1725-
1726-
#[tokio::test]
1727-
async fn it_should_authenticate_a_peer_with_the_key() {
1728-
let tracker = private_tracker();
1729-
1730-
let peer_key = tracker.authentication.generate_permanent_auth_key().await.unwrap();
1731-
1732-
let result = tracker.authentication.authenticate(&peer_key.key()).await;
1733-
1734-
assert!(result.is_ok());
1735-
}
1736-
}
1737-
1738-
mod pre_generated_keys {
1739-
use crate::core::authentication::{AddKeyRequest, Key};
1740-
use crate::core::tests::the_tracker::private_tracker;
1741-
1742-
#[tokio::test]
1743-
async fn it_should_add_a_pre_generated_key() {
1744-
let tracker = private_tracker();
1745-
1746-
let peer_key = tracker
1747-
.authentication
1748-
.add_peer_key(AddKeyRequest {
1749-
opt_key: Some(Key::new("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap().to_string()),
1750-
opt_seconds_valid: None,
1751-
})
1752-
.await
1753-
.unwrap();
1754-
1755-
assert_eq!(peer_key.valid_until, None);
1756-
}
1757-
1758-
#[tokio::test]
1759-
async fn it_should_authenticate_a_peer_with_the_key() {
1760-
let tracker = private_tracker();
1761-
1762-
let peer_key = tracker
1763-
.authentication
1764-
.add_peer_key(AddKeyRequest {
1765-
opt_key: Some(Key::new("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap().to_string()),
1766-
opt_seconds_valid: None,
1767-
})
1768-
.await
1769-
.unwrap();
1770-
1771-
let result = tracker.authentication.authenticate(&peer_key.key()).await;
1772-
1773-
assert!(result.is_ok());
1774-
}
1775-
}
1776-
}
1777-
}
1778-
1779-
mod handling_an_announce_request {}
1780-
1781-
mod handling_an_scrape_request {}
1782-
}
1783-
1784-
mod configured_as_private_and_whitelisted {
1785-
1786-
mod handling_an_announce_request {}
1787-
1788-
mod handling_an_scrape_request {}
1789-
}
1790-
17911496
mod handling_torrent_persistence {
17921497

17931498
use aquatic_udp_protocol::AnnounceEvent;

0 commit comments

Comments
 (0)