Skip to content

Commit 94fbdeb

Browse files
committed
Merge #206: Axum HTTP tracker: remove temporary status endpoint
2ffbf3d refactor(http): [#204] remove temporary status endpoint (Jose Celano) Pull request description: It was only added to test the initial HTTP scaffolding for the Axum implementation. Top commit has no ACKs. Tree-SHA512: 6e965ef53f2247da35e96429a2f4a5592eab9f7d382533fa38b94099fcf6eb593932eb6eacb53499f3642a75c8cfb244478d6f50e575fb848edbbff28351e6c5
2 parents 953ad24 + 2ffbf3d commit 94fbdeb

File tree

9 files changed

+2
-176
lines changed

9 files changed

+2
-176
lines changed

src/http/axum_implementation/handlers/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::tracker::error::Error;
44
pub mod announce;
55
pub mod auth;
66
pub mod scrape;
7-
pub mod status;
87

98
impl From<Error> for responses::error::Error {
109
fn from(err: Error) -> Self {

src/http/axum_implementation/handlers/status.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/http/axum_implementation/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ pub mod extractors;
22
pub mod handlers;
33
pub mod query;
44
pub mod requests;
5-
pub mod resources;
65
pub mod responses;
76
pub mod routes;
87
pub mod server;

src/http/axum_implementation/resources/mod.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/http/axum_implementation/resources/ok.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
pub mod announce;
22
pub mod error;
3-
pub mod ok;
43
pub mod scrape;

src/http/axum_implementation/responses/ok.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/http/axum_implementation/routes.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ use axum::routing::get;
44
use axum::Router;
55
use axum_client_ip::SecureClientIpSource;
66

7-
use super::handlers::{announce, scrape, status};
7+
use super::handlers::{announce, scrape};
88
use crate::tracker::Tracker;
99

1010
pub fn router(tracker: &Arc<Tracker>) -> Router {
1111
Router::new()
12-
// Status
13-
.route("/status", get(status::handle))
1412
// Announce request
1513
.route("/announce", get(announce::handle_without_key).with_state(tracker.clone()))
1614
.route("/announce/:key", get(announce::handle_with_key).with_state(tracker.clone()))

tests/http_tracker.rs

Lines changed: 1 addition & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/// cargo test `warp_http_tracker_server` -- --nocapture
66
/// ```
77
///
8-
/// Axum version ()WIP):
8+
/// Axum version (WIP):
99
/// ```text
1010
/// cargo test `warp_http_tracker_server` -- --nocapture
1111
/// ```
@@ -1271,143 +1271,6 @@ mod axum_http_tracker_server {
12711271

12721272
// WIP: migration HTTP from Warp to Axum
12731273

1274-
use local_ip_address::local_ip;
1275-
use torrust_tracker::http::axum_implementation::extractors::remote_client_ip::RemoteClientIp;
1276-
use torrust_tracker::http::axum_implementation::resources::ok::Ok;
1277-
use torrust_tracker::http::Version;
1278-
1279-
use crate::http::client::Client;
1280-
use crate::http::server::start_default_http_tracker;
1281-
1282-
#[tokio::test]
1283-
async fn should_return_the_status() {
1284-
// This is a temporary test to test the new Axum HTTP tracker server scaffolding
1285-
1286-
let http_tracker_server = start_default_http_tracker(Version::Axum).await;
1287-
1288-
let client_ip = local_ip().unwrap();
1289-
1290-
let response = Client::bind(http_tracker_server.get_connection_info(), client_ip)
1291-
.get("status")
1292-
.await;
1293-
1294-
let ok: Ok = serde_json::from_str(&response.text().await.unwrap()).unwrap();
1295-
1296-
assert_eq!(
1297-
ok,
1298-
Ok {
1299-
remote_client_ip: RemoteClientIp {
1300-
right_most_x_forwarded_for: None,
1301-
connection_info_ip: Some(client_ip)
1302-
}
1303-
}
1304-
);
1305-
}
1306-
1307-
mod should_get_the_remote_client_ip_from_the_http_request {
1308-
1309-
// Temporary tests to test that the new Axum HTTP tracker gets the right remote client IP.
1310-
// Once the implementation is finished, test for announce request will cover these cases.
1311-
1312-
use std::net::IpAddr;
1313-
use std::str::FromStr;
1314-
1315-
use local_ip_address::local_ip;
1316-
use torrust_tracker::http::axum_implementation::extractors::remote_client_ip::RemoteClientIp;
1317-
use torrust_tracker::http::axum_implementation::resources::ok::Ok;
1318-
use torrust_tracker::http::Version;
1319-
1320-
use crate::http::client::Client;
1321-
use crate::http::server::{start_http_tracker_on_reverse_proxy, start_public_http_tracker};
1322-
1323-
#[tokio::test]
1324-
async fn when_the_client_ip_is_a_local_ip_it_should_assign_that_ip() {
1325-
let http_tracker_server = start_public_http_tracker(Version::Axum).await;
1326-
1327-
let client_ip = local_ip().unwrap();
1328-
1329-
let client = Client::bind(http_tracker_server.get_connection_info(), client_ip);
1330-
1331-
let response = client.get("status").await;
1332-
1333-
let ok: Ok = serde_json::from_str(&response.text().await.unwrap()).unwrap();
1334-
1335-
assert_eq!(
1336-
ok,
1337-
Ok {
1338-
remote_client_ip: RemoteClientIp {
1339-
right_most_x_forwarded_for: None,
1340-
connection_info_ip: Some(client_ip)
1341-
}
1342-
}
1343-
);
1344-
}
1345-
1346-
#[tokio::test]
1347-
async fn when_the_client_ip_is_a_loopback_ipv4_it_should_assign_that_ip() {
1348-
let http_tracker_server = start_public_http_tracker(Version::Axum).await;
1349-
1350-
let loopback_ip = IpAddr::from_str("127.0.0.1").unwrap();
1351-
let client_ip = loopback_ip;
1352-
1353-
let client = Client::bind(http_tracker_server.get_connection_info(), client_ip);
1354-
1355-
let response = client.get("status").await;
1356-
1357-
let ok: Ok = serde_json::from_str(&response.text().await.unwrap()).unwrap();
1358-
1359-
assert_eq!(
1360-
ok,
1361-
Ok {
1362-
remote_client_ip: RemoteClientIp {
1363-
right_most_x_forwarded_for: None,
1364-
connection_info_ip: Some(client_ip)
1365-
}
1366-
}
1367-
);
1368-
}
1369-
1370-
#[tokio::test]
1371-
async fn when_the_tracker_is_behind_a_reverse_proxy_it_should_assign_as_secure_ip_the_right_most_ip_in_the_x_forwarded_for_http_header(
1372-
) {
1373-
/*
1374-
client <-> http proxy <-> tracker <-> Internet
1375-
ip: header: config: remote client ip:
1376-
145.254.214.256 X-Forwarded-For = 145.254.214.256 on_reverse_proxy = true 145.254.214.256
1377-
*/
1378-
1379-
let http_tracker_server = start_http_tracker_on_reverse_proxy(Version::Axum).await;
1380-
1381-
let loopback_ip = IpAddr::from_str("127.0.0.1").unwrap();
1382-
let client_ip = loopback_ip;
1383-
1384-
let client = Client::bind(http_tracker_server.get_connection_info(), client_ip);
1385-
1386-
let left_most_ip = IpAddr::from_str("203.0.113.195").unwrap();
1387-
let right_most_ip = IpAddr::from_str("150.172.238.178").unwrap();
1388-
1389-
let response = client
1390-
.get_with_header(
1391-
"status",
1392-
"X-Forwarded-For",
1393-
&format!("{left_most_ip},2001:db8:85a3:8d3:1319:8a2e:370:7348,{right_most_ip}"),
1394-
)
1395-
.await;
1396-
1397-
let ok: Ok = serde_json::from_str(&response.text().await.unwrap()).unwrap();
1398-
1399-
assert_eq!(
1400-
ok,
1401-
Ok {
1402-
remote_client_ip: RemoteClientIp {
1403-
right_most_x_forwarded_for: Some(right_most_ip),
1404-
connection_info_ip: Some(client_ip)
1405-
}
1406-
}
1407-
);
1408-
}
1409-
}
1410-
14111274
mod for_all_config_modes {
14121275

14131276
mod and_running_on_reverse_proxy {

0 commit comments

Comments
 (0)