|
5 | 5 | /// cargo test `warp_http_tracker_server` -- --nocapture |
6 | 6 | /// ``` |
7 | 7 | /// |
8 | | -/// Axum version ()WIP): |
| 8 | +/// Axum version (WIP): |
9 | 9 | /// ```text |
10 | 10 | /// cargo test `warp_http_tracker_server` -- --nocapture |
11 | 11 | /// ``` |
@@ -1271,143 +1271,6 @@ mod axum_http_tracker_server { |
1271 | 1271 |
|
1272 | 1272 | // WIP: migration HTTP from Warp to Axum |
1273 | 1273 |
|
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 | | - |
1411 | 1274 | mod for_all_config_modes { |
1412 | 1275 |
|
1413 | 1276 | mod and_running_on_reverse_proxy { |
|
0 commit comments