Skip to content

Commit de3d90f

Browse files
committed
test(http): enable axum http tracker testt
Those test should have been enabled when the implementation was done.
1 parent de55fb4 commit de3d90f

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/http/axum_implementation/extractors/peer_ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::http::axum_implementation::responses;
99

1010
#[derive(Error, Debug)]
1111
pub enum ResolutionError {
12-
#[error("missing the right most X-Forwarded-For IP (mandatory on reverse proxy tracker configuration) in {location}")]
12+
#[error("missing or invalid the right most X-Forwarded-For IP (mandatory on reverse proxy tracker configuration) in {location}")]
1313
MissingRightMostXForwardedForIp { location: &'static Location<'static> },
1414
#[error("cannot get the client IP from the connection info in {location}")]
1515
MissingClientIp { location: &'static Location<'static> },

tests/http/asserts.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ pub async fn assert_could_not_find_remote_address_on_xff_header_error_response(r
138138
);
139139
}
140140

141+
pub async fn assert_could_not_find_remote_address_on_x_forwarded_for_header_error_response(response: Response) {
142+
assert_eq!(response.status(), 200);
143+
144+
assert_bencoded_error(
145+
&response.text().await.unwrap(),
146+
"missing or invalid the right most X-Forwarded-For IP (mandatory on reverse proxy tracker configuration)",
147+
Location::caller(),
148+
);
149+
}
150+
141151
pub async fn assert_invalid_remote_address_on_xff_header_error_response(response: Response) {
142152
assert_eq!(response.status(), 200);
143153

tests/http_tracker.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,19 +1405,15 @@ mod axum_http_tracker_server {
14051405
mod and_running_on_reverse_proxy {
14061406
use torrust_tracker::http::Version;
14071407

1408-
use crate::http::asserts::{
1409-
assert_could_not_find_remote_address_on_xff_header_error_response,
1410-
assert_invalid_remote_address_on_xff_header_error_response,
1411-
};
1408+
use crate::http::asserts::assert_could_not_find_remote_address_on_x_forwarded_for_header_error_response;
14121409
use crate::http::client::Client;
14131410
use crate::http::requests::announce::QueryBuilder;
14141411
use crate::http::server::start_http_tracker_on_reverse_proxy;
14151412

1416-
//#[tokio::test]
1417-
#[allow(dead_code)]
1413+
#[tokio::test]
14181414
async fn should_fail_when_the_http_request_does_not_include_the_xff_http_request_header() {
14191415
// If the tracker is running behind a reverse proxy, the peer IP is the
1420-
// last IP in the `X-Forwarded-For` HTTP header, which is the IP of the proxy client.
1416+
// right most IP in the `X-Forwarded-For` HTTP header, which is the IP of the proxy's client.
14211417

14221418
let http_tracker_server = start_http_tracker_on_reverse_proxy(Version::Axum).await;
14231419

@@ -1427,11 +1423,10 @@ mod axum_http_tracker_server {
14271423
.get(&format!("announce?{params}"))
14281424
.await;
14291425

1430-
assert_could_not_find_remote_address_on_xff_header_error_response(response).await;
1426+
assert_could_not_find_remote_address_on_x_forwarded_for_header_error_response(response).await;
14311427
}
14321428

1433-
//#[tokio::test]
1434-
#[allow(dead_code)]
1429+
#[tokio::test]
14351430
async fn should_fail_when_the_xff_http_request_header_contains_an_invalid_ip() {
14361431
let http_tracker_server = start_http_tracker_on_reverse_proxy(Version::Axum).await;
14371432

@@ -1441,7 +1436,7 @@ mod axum_http_tracker_server {
14411436
.get_with_header(&format!("announce?{params}"), "X-Forwarded-For", "INVALID IP")
14421437
.await;
14431438

1444-
assert_invalid_remote_address_on_xff_header_error_response(response).await;
1439+
assert_could_not_find_remote_address_on_x_forwarded_for_header_error_response(response).await;
14451440
}
14461441
}
14471442

0 commit comments

Comments
 (0)